Skip to content

Commit

Permalink
fix: attempting to delete a custom control to the map if it was not a…
Browse files Browse the repository at this point in the history
…ctually added there (happens if there was an exception during markers initialization) #199
  • Loading branch information
dmytro-gokun committed Jul 24, 2020
1 parent 28c764a commit 503730b
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion projects/ngx-mapbox-gl/src/lib/control/control.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export class CustomControl implements IControl {
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ControlComponent implements OnDestroy, AfterContentInit {
private controlAdded = false;

/* Init inputs */
@Input() position?: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';

Expand All @@ -46,12 +48,13 @@ export class ControlComponent implements OnDestroy, AfterContentInit {
this.control = new CustomControl(this.content.nativeElement);
this.MapService.mapCreated$.subscribe(() => {
this.MapService.addControl(this.control!, this.position);
this.controlAdded = true;
});
}
}

ngOnDestroy() {
if (this.control) {
if (this.controlAdded) {
this.MapService.removeControl(this.control);
}
}
Expand Down

0 comments on commit 503730b

Please sign in to comment.