Skip to content

Commit

Permalink
remove usage of NgZone.onStable and NgZone.onMicrotaskEmpty, setup is…
Browse files Browse the repository at this point in the history
  • Loading branch information
marcjulian authored Aug 21, 2024
1 parent 08949de commit 152d704
Showing 1 changed file with 13 additions and 19 deletions.
32 changes: 13 additions & 19 deletions projects/ngx-maplibre-gl/src/lib/map/map.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import {
type ControlPosition,
} from 'maplibre-gl';
import { AsyncSubject, Subscription } from 'rxjs';
import { first } from 'rxjs/operators';
import type {
LayerEvents,
MapEvent,
Expand Down Expand Up @@ -107,21 +106,18 @@ export class MapService {
readonly mapLoaded$ = this.mapLoaded.asObservable();

setup(options: SetupMap) {
// Need onStable to wait for a potential @angular/route transition to end
this.zone.onStable.pipe(first()).subscribe(() => {
// Workaround rollup issue
this.createMap(options.mapOptions as MapOptions);
this.hookEvents(options.mapEvents);
this.mapEvents = options.mapEvents;
this.mapCreated.next(undefined);
this.mapCreated.complete();

if (options.mapOptions.terrain) {
this.mapInstance.on('load', () => {
this.updateTerrain(options.mapOptions.terrain!);
});
}
});
// Workaround rollup issue
this.createMap(options.mapOptions as MapOptions);
this.hookEvents(options.mapEvents);
this.mapEvents = options.mapEvents;
this.mapCreated.next(undefined);
this.mapCreated.complete();

if (options.mapOptions.terrain) {
this.mapInstance.on('load', () => {
this.updateTerrain(options.mapOptions.terrain!);
});
}
}

destroyMap() {
Expand Down Expand Up @@ -646,9 +642,7 @@ export class MapService {
this.mapInstance.setStyle(options.style!);
}

this.subscription.add(
this.zone.onMicrotaskEmpty.subscribe(() => this.applyChanges())
);
this.subscription.add(this.applyChanges());
}

private removeMarkers() {
Expand Down

0 comments on commit 152d704

Please sign in to comment.