I'm using Esri-Leaflet and whenever I try to use getFeature() the console.log returns "undefined".

There are no other errors to accompany the undefined message.

var service = L.esri.featureLayer({url: 'https://services1.arcgis.com/example/arcgis/rest/services/LayerName/FeatureServer/0'});
var objID = parseInt("4");
var featurePoly = service.getFeature(objID);

A feature of ObjectID of 4 does exist. The feature service is reachable.

Any thoughts on where I might be going wrong?


The answer to this seems to be that:

The featureService must have been added to the map. .addTo('map'); The map must be set to viewing coordinates that causes the features to be returned to the map.

It's not possible to work with features that have not been added to the map, apparently.

| improve this answer | |

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.