[GIS] Use Mapbox featureLayer to create Marker Clusters

javascriptleafletmapbox

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?

Best Answer

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);