0

I'm trying to use this tutorial (https://www.mapbox.com/mapbox.js/example/v1.0.0/markercluster-with-mapbox-data/) to create marker clusters to style a Mapbox featureLayer containing my data. This code works to display my data:

var featureLayer = L.mapbox.featureLayer(rodents1,{
        pointToLayer: function (feature,latlng){
            return L.circleMarker(latlng,markerStyle);
        },
    }).addTo(map);

But when I try to rework my code according to the instructions, my data goes missing from my map. Here is the code according to the instructions:

// Since featureLayer is an asynchronous method, we use the `.on('ready'`
// call to only use its marker data once we know it is actually loaded.
L.mapbox.featureLayer('rodents1').on('ready', function(e) {
    // The clusterGroup gets each marker in the group added to it
    // once loaded, and then is added to the map
    var clusterGroup = new L.MarkerClusterGroup();
    e.target.eachLayer(function(layer) {
        clusterGroup.addLayer(layer);
    });
    map.addLayer(clusterGroup);

I've included links to the Leaflet/markercluster files in the head of my html file.

Am I missing something?

1
  • Can you post a jsfiddle so we can see a bit more code?
    – rowanwins
    Commented Apr 19, 2015 at 11:09

1 Answer 1

1

I found a solution here: https://stackoverflow.com/questions/17005784/clustering-markers-on-mapbox-leaflet

I used this code to display my markers:

var markers = new L.MarkerClusterGroup();
var geoJsonFeature = rodents1;
var geoJsonLayer = L.geoJson(rodents1);

var map = L.mapbox.map('map','mapbox.streets')
    .setView([42.35,-71.08],13);

markers.addLayer(geoJsonLayer);
map.addLayer(markers);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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