I have a leaflet map that uses esri-leaflet to display a feature layer created for arcgis that is a number of paths. These paths are created correctly and I can see them on the map, but they aren't the visual I need. Instead I'm interested in getting the LatLng of the centroid of the path.

Since I know leaflet polylines have a getCenter method, I just need to know how to access these objects after they are drawn to the map. Is this possible?

Code for this follows:

let mymap = L.map("mapid").setView([lat, lng], 18);
var subtleUA = L.esri
let roomFeatures = L.esri.featureLayer({url:"https://mymapserver/../interiors/16"}).addTo(mymap)

1 Answer 1


After feature layer is loaded you can use layer's .eachFeature method to loop through features and get center of each feature:

let roomFeatures = L.esri.featureLayer({url:"https://mymapserver/../interiors/16"});

roomFeatures.on('load', function() {
  roomFeatures.eachFeature(function(layer) {
    let center = layer.getCenter();
  • excellent! I wasn't sure if the features were actual polylines after using esri leaflet but this is great!
    – Li Brary
    Commented Jun 19, 2020 at 23:36

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.