1

When using the following portion of code, the clusters and some markers are shown but if I zoom or click anywhere the browser crashes.

var cam = L.ExtraMarkers.icon({
             icon: 'fa-video-camera',
             markerColor: 'red',
             shape: 'square',
             prefix: 'fa'
          });

var cameras = omnivore.kml('json/cameras.kml')
            .on('ready', function(layer) {
               this.eachLayer(function(marker) {
                 marker.setIcon(cam);
                 var markers = L.markerClusterGroup();
                 var popupCam = marker.toGeoJSON().properties.name;
                 marker.bindPopup(popupCam);
                 markers.addLayer(cameras);
                 map.addLayer(markers);
               })
             });

Without using the clustering, all markers (~300) are shown pretty well so I guess it should not be performance related.

  • 1
    Which browser? Which version of Leaflet? Can you publish a demo which can crash my browser? – IvanSanchez Nov 10 '16 at 14:57
2

So for each of your 300 markers, you create a Cluster Group, to which you add the entire cameras GeoJSON group (300 markers), and add the former Cluster Group to the map?

300 cluster groups with 300 markers each?

There is a high chance this is what slows down your browser, possibly making it crash.

I guess you wanted to put your code with Cluster Group outside your eachLayer loop.

var cameras = omnivore.kml('json/cameras.kml')
  .on('ready', function(layer) {
    this.eachLayer(function(marker) {
      marker.setIcon(cam);
      var popupCam = marker.toGeoJSON().properties.name;
      // Could probably have used popupCam = marker.feature.properties.name?
      marker.bindPopup(popupCam);
    })
    var markers = L.markerClusterGroup();
    markers.addLayer(cameras);
    map.addLayer(markers);
  });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.