[Vuejs]-Leaflet error Uncaught (in promise) TypeError: layer.addEventParent is not a function

0👍

The addLayer() method of MarkerClusterGroup expects a single layer object or an array of layer objects as an argument. In your code, you are passing an array of markers to the addLayer() method, which is causing the error.
Let’s pass it to addLayer(), you can directly add each marker to the markerClusters group using the addLayer() method within your loop. Here’s the updated code:

onMounted(() => {
  markerClusters.clearLayers();
  toRaw(props.coordinatesTwo).forEach((item) => {
    let marker = L.marker(new L.LatLng(item.coordinates.lat, item.coordinates.lng), {
      icon: customIcon
    });
    markerClusters.addLayer(marker);
  });

  props.map.leafletObject.addLayer(markerClusters);
});

Leave a comment