Skip to content

Commit

Permalink
Fixed adding extra child just detach (#14)
Browse files Browse the repository at this point in the history
<!--

Thank you for submitting a pull request!

Here's a checklist you might find useful.
[ ] There is an associated issue that is labelled
  'Bug' or 'help wanted' or is in the Community milestone
[ ] Code is up-to-date with the `main` branch
[ ] You've successfully run `npm test` locally
[ ] There are new or updated tests validating the change

-->

Fixes #
  • Loading branch information
matthew44-mappable authored Jun 13, 2024
1 parent 51cc80d commit 577adfd
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 18 deletions.
2 changes: 2 additions & 0 deletions src/controls/MMapGeolocationControl/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ class MMapGeolocationControl extends mappable.MMapGroupEntity<MMapGeolocationCon
}

protected override _onDetach() {
this._control.removeChild(this._button);
this.removeChild(this._control);
this._unwatchThemeContext?.();
}

Expand Down
12 changes: 6 additions & 6 deletions src/controls/MMapRotateControl/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,11 @@ type DefaultProps = typeof defaultProps;
export class MMapRotateControl extends mappable.MMapComplexEntity<MMapRotateControlProps, DefaultProps> {
static defaultProps = defaultProps;
static [mappable.optionsKeyVuefy] = MMapRotateControlVuefyOptions;
private _control!: MMapControl;
private _rotateControl!: InternalRotateControl;
private _control: MMapControl;
private _rotateControl: InternalRotateControl;

constructor(props: MMapRotateControlProps) {
super(props);
}

protected _onAttach(): void {
this._control = new mappable.MMapControl({transparent: true});
this._rotateControl = new InternalRotateControl(this._props);

Expand All @@ -64,12 +61,15 @@ export class InternalRotateControl extends mappable.MMapComplexEntity<MMapRotate
private _startMovePosition?: Position;
private _startAzimuth?: number;

protected _onAttach(): void {
constructor(props: MMapRotateControlProps) {
super(props);
this._listener = new mappable.MMapListener({
onUpdate: (event) => this._onMapUpdate(event.camera)
});
this.addChild(this._listener);
}

protected _onAttach(): void {
this._element = document.createElement('mappable');
this._element.textContent = 'N';
this._element.classList.add(ROTATE_CONTROL_CLASS);
Expand Down
5 changes: 2 additions & 3 deletions src/controls/MMapRotateTiltControl/MMapRotateControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@ export class MMapRotateControl extends mappable.MMapGroupEntity<MMapRotateTiltCo

constructor(props: MMapRotateTiltControlProps) {
super(props);
}

protected _onAttach(): void {
this._listener = new mappable.MMapListener({
onUpdate: (event) => this._onMapUpdate(event.camera)
});
this.addChild(this._listener);
}

protected _onAttach(): void {
this._element = document.createElement('mappable');
this._element.classList.add(ROTATE_CONTROL_CLASS);

Expand Down
5 changes: 2 additions & 3 deletions src/controls/MMapRotateTiltControl/MMapTiltControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@ export class MMapTiltControl extends mappable.MMapComplexEntity<MMapRotateTiltCo

constructor(props: MMapRotateTiltControlProps) {
super(props);
}

protected _onAttach(): void {
this._listener = new mappable.MMapListener({
onUpdate: (event) => this._onMapUpdate(event.camera)
});
this.addChild(this._listener);
}

protected _onAttach(): void {
this._element = document.createElement('mappable');
this._element.classList.add(TILT_CONTROL_CLASS);
const {tilt, tiltRange} = this.root;
Expand Down
4 changes: 1 addition & 3 deletions src/controls/MMapRotateTiltControl/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ export class MMapRotateTiltControl extends mappable.MMapComplexEntity<MMapRotate

constructor(props: MMapRotateTiltControlProps) {
super(props);
}

protected _onAttach(): void {
this._control = new mappable.MMapControl({transparent: true});
this._rotateControl = new MMapRotateControl(this._props);
this._tiltControl = new MMapTiltControl(this._props);
Expand All @@ -48,6 +45,7 @@ export class MMapRotateTiltControl extends mappable.MMapComplexEntity<MMapRotate
this._control.addChild(this._rotateControl);
this.addChild(this._control);
}

protected _onUpdate(): void {
this._rotateControl.update(this._props);
this._tiltControl.update(this._props);
Expand Down
1 change: 1 addition & 0 deletions src/controls/MMapSearchControl/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ class MMapSearchControl extends mappable.MMapComplexEntity<MMapSearchControlProp
}

protected override _onDetach(): void {
this._control.removeChild(this._search);
this.removeChild(this._control);
}
}
Expand Down
3 changes: 0 additions & 3 deletions src/controls/MMapTiltControl/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ export class MMapTiltControl extends mappable.MMapComplexEntity<MMapTiltControlP

constructor(props: MMapTiltControlProps) {
super(props);
}

protected _onAttach(): void {
this._control = new mappable.MMapControl({transparent: true});
this._tiltControl = new InternalTiltControl(this._props);

Expand Down
7 changes: 7 additions & 0 deletions src/markers/MMapDefaultMarker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,13 @@ export class MMapDefaultMarker extends mappable.MMapComplexEntity<MMapDefaultMar
this._marker.update({...this._props, onClick: this._onMarkerClick});
}

protected override _onDetach(): void {
if (this._popup) {
this.removeChild(this._popup);
}
this.removeChild(this._marker);
}

private _createPopupMarker() {
return new MMapPopupMarker({
...this._props,
Expand Down
4 changes: 4 additions & 0 deletions src/markers/MMapPopupMarker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ export class MMapPopupMarker extends mappable.MMapComplexEntity<MMapPopupMarkerP
this._marker.update(this._props);
}

protected _onDetach(): void {
this.removeChild(this._marker);
}

private _updateTheme() {
const themeCtx = this._consumeContext(mappable.ThemeContext);
const {theme} = themeCtx;
Expand Down

0 comments on commit 577adfd

Please sign in to comment.