0

I've been experimenting with a web map using Esri Leaflet examples and I've run into a bit of a problem getting my popups to load. I'm able to successfully load the data from the REST service and it displays properly, however no popup is created when I click each feature.

Sites = L.esri.dynamicMapLayer("http://gis.montgomerycountymd.gov/ArcGIS/rest/services/General/Fiber_PLOI/MapServer",{});
Sites.bindPopup(function (error, featureCollection) {
if(error || featureCollection.features.length === 0) {
  return false;
} else {
  return 'Name: ' + featureCollection.features.properties.NAME;}
}); 
1
  • Can you provide a JSFiddle? That would help in debugging your use case. Commented Feb 5, 2015 at 10:14

1 Answer 1

0

This is because the features property of featureCollection is an array. Because of this you'd either need to loop through all of them or just specify a static index position if you'd like to get a reference to the first individual feature.

return 'Name: ' + featureCollection.features[0].properties.NAME;}

setting a breakpoint within the callback which is triggered by bindPopup is the best way to get a better idea of what exactly is returned and how you can work with it.

3
  • I tried to add a static index but the popups are still not binding. Commented Feb 6, 2015 at 2:03
  • works fine for me w/ your service... jsfiddle.net/jagravois/aLaokhjg Commented Feb 7, 2015 at 4:08
  • Wow man thanks so much! This has been driving me nuts. Turns out the problem was I was using layer controls, and called the .bindPopup method prior to calling L.control.layers().addTo(map). Commented Feb 8, 2015 at 16:24

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.