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?

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Apr 18, 2015 at 18:27
1
  • Can you post a jsfiddle so we can see a bit more code? 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);
answered Apr 19, 2015 at 18:25

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.