I am using ngx-leaflet, when adding markers to the map, the application slows down due to the large amount of Function Call (zone.js). I tried to use changeDetection and ngZone but to no avail. Please help :)
constructor(zone: NgZone) {}
onMapReady(map: L.Map) {
this.map = map;
this.zone.run(() => {
this.getPoints();
});
L.control.scale({position: 'bottomleft'}).addTo(this.map);
L.control.zoom({position: 'bottomleft'}).addTo(this.map);
this.createLegend();
}
private updateLayers(pointList: Point[]) {
this.layers = [];
let group = L.featureGroup();
for (let point of pointList) {
if (point.gps) {
this.zone.run( ()=> {
let marker: Marker = L.marker([point.gps.latitude, point.gps.longitude], {icon: this.setIcon(point.status)});
group.addLayer(marker);
this.setPopupContent(marker, point);
this.layers.push(marker);
this.layers = this.layers.slice();
this.changeDetector.detectChanges();
});
}
}
if (pointList.length != 0) {
this.zone.run(()=> {
this.leafletDirective.getMap().fitBounds(group.getBounds(), {
padding: [10, 10],
animate: false,
duration: 0.01,
noMoveStart: true});
});
}
}