bluehalo / ngx-leaflet-markercluster

MIT License
61 stars 22 forks source link

TypeError: L.markerClusterGroup is not a function #88

Closed javanese84 closed 5 months ago

javanese84 commented 5 months ago

Hi,

I just tried implementing the markerCluster functionality into my application based on Angular17 (with standalone Components). I copied the example from this repo 1:1 (as own module as in the example) and getting the following error: TypeError: L.markerClusterGroup is not a function image

The Error is thrown within the directive in the ngOnInit (line 18). See the following screenshot.

image

Extract from package.json: "leaflet": "^1.9.4", "leaflet.markercluster": "^1.5.3", "@asymmetrik/ngx-leaflet": "^17.0.0", "@asymmetrik/ngx-leaflet-markercluster": "^17.0.0",

javanese84 commented 5 months ago

Now, it works without any issue. That's my code:

const markerArray = L.markerClusterGroup();
for (const loc of this.locations) {
  passArray.addLayer(marker([ loc.lat, loc.lon ], {
    icon: this.icon
  }));
}
this.markerGroup = markerArray;

in my template:

<div style="height: 500px;"
       leaflet
       (leafletMapReady)="onMapReady($event)"
       [leafletOptions]="options">
    @if (markerGroup) {
      <div [leafletLayer]="markerGroup"></div>
    }
</div>