Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed adding extra child just detach #14

Merged
merged 2 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
1 change: 1 addition & 0 deletions src/controls/MMapZoomControl/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ class MMapZoomControl extends mappable.MMapComplexEntity<MMapZoomControlProps, D
}

protected override _onDetach(): void {
this._control.removeChild(this._zoom);
matthew44-mappable marked this conversation as resolved.
Show resolved Hide resolved
this.removeChild(this._control);
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/markers/MMapDefaultMarker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ export class MMapDefaultMarker extends mappable.MMapComplexEntity<MMapDefaultMar
this._marker.update({...this._props, onClick: this._onMarkerClick});
}

protected override _onDetach(): void {
this.removeChild(this._marker);
matthew44-mappable marked this conversation as resolved.
Show resolved Hide resolved
}

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);
matthew44-mappable marked this conversation as resolved.
Show resolved Hide resolved
}

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