No se pueden eliminar capas con clústeres en leaflet.js

Estoy usando el leaflet cluster plugin to map out a bunch of crashes. When you load up the page, I map out all crashes (stored in a GeoJSON file). I also have buttons that load up a different geoJSON file for each year.

The problem I am running into is that removeLayer() isn't actually removing the layers. So when I remap a new GeoJSON file, it's just stacking all the crashes on top of each other.

These are my two functions that fire when you click a button. marcadores var is defined in the global namespace, seen below (maybe this is part of the problem)?

var markers = L.markerClusterGroup({spiderfyDistanceMultiplier: 1.3});

//Lay new data on map
function buildMarkers(yearData){
        var crashLayer = new L.geoJson(yearData, {
                onEachFeature: function (feature, layer) {


//Remove ALL data on map        
function removeClusters(){

//AN example of a button

preguntado el 09 de septiembre de 13 a las 21:09

2 Respuestas

Lo acabo de descubrir.

To clear all the data from the markers variable, I used clearLayers(). So in my buildMarkers() function I just add this to the first line in the function


and that clears away all the data.

Respondido el 09 de Septiembre de 13 a las 21:09

we can remove clusters layers by using disableClusteringAtZoom need to specified that at which label we can remove the Clustering

var markers = L.markerClusterGroup({disableClusteringAtZoom: 17, spiderfyOnMaxZoom: false, showCoverageOnHover: true, zoomToBoundsOnClick: true }); 

respondido 13 mar '18, 07:03

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.