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

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

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

Am I missing something?

  • Can you post a jsfiddle so we can see a bit more code? – rowanwins Apr 19 '15 at 11:09

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


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.