Skip to content

Commit

Permalink
fix(markerCluster): run clustering inside NgZone
Browse files Browse the repository at this point in the history
fix #36
  • Loading branch information
Wykks committed May 21, 2018
1 parent 7aa7fc4 commit e708040
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/app/lib/marker-cluster/marker-cluster.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
OnDestroy,
OnInit,
SimpleChanges,
TemplateRef
TemplateRef,
NgZone
} from '@angular/core';
import { fromEvent } from 'rxjs/observable/fromEvent';
import { merge } from 'rxjs/observable/merge';
Expand Down Expand Up @@ -78,7 +79,8 @@ export class MarkerClusterComponent implements OnChanges, OnDestroy, AfterConten

constructor(
private MapService: MapService,
private ChangeDetectorRef: ChangeDetectorRef
private ChangeDetectorRef: ChangeDetectorRef,
private zone: NgZone
) { }

ngOnInit() {
Expand Down Expand Up @@ -118,7 +120,11 @@ export class MarkerClusterComponent implements OnChanges, OnDestroy, AfterConten
);
const sub = mapMove$.pipe(
startWith<any>(undefined)
).subscribe(() => this.updateCluster());
).subscribe(() => {
this.zone.run(() => {
this.updateCluster();
});
});
this.sub.add(sub);
});
}
Expand All @@ -143,7 +149,8 @@ export class MarkerClusterComponent implements OnChanges, OnDestroy, AfterConten
const bbox = this.MapService.getCurrentViewportBbox();
const currentZoom = Math.round(this.MapService.mapInstance.getZoom());
this.clusterPoints = this.supercluster.getClusters(bbox, currentZoom);
this.ChangeDetectorRef.detectChanges();
this.MapService.applyChanges();
this.ChangeDetectorRef.markForCheck();
// this.ChangeDetectorRef.detectChanges();
// this.MapService.applyChanges();
}
}

0 comments on commit e708040

Please sign in to comment.