0

I am trying to convert the selected regions in the following URL (marked in red) into geojson and retrieve administrative info (State, Country etc.)

https://esri.github.io/esri-leaflet/examples/spatial-queries.html

This is an example code that I found online.

     var feature = L.esri.Util.arcgisToGeoJSON(neighborhoods[i], ids[i]);
     var latlng = L.Projection.Mercator.unproject(L.point(feature.geometry.coordinates));
                    feature.geometry.coordinates = [latlng.lng, latlng.lat];

Please Help!

Steve
  • 25,806
  • 2
  • 33
  • 43
codejunkie
  • 908
  • 2
  • 21
  • 34

1 Answers1

1

the short answer is that you don't need to convert clientside esri leaflet features to GeoJSON because they already are GeoJSON.

the only complication in the sample that you referenced is that the query to select an individual feature chains the ids() method, so only an identifier is requested for features that match search criteria (rather than raw GeoJSON features) because they've already been requested an drawn once.

for (var i = ids.length - 1; i >= 0; i--) {
  neighborhoods.setFeatureStyle(ids[i], { color: 'red', weight: 2 });
  /* retrieve an individual GeoJSON feature via its ID 
  using L.esri.featureLayer.getFeature() */
  var selectedNeighborhood = neighborhoods.getFeature(ids[i]);
  console.log(selectedNeighborhood.feature);
};
john gravois
  • 392
  • 2
  • 8
  • Can I query without creating a feature layer? I would like to find which administrative divisions fall inside my selection polygon. My aim is to enable users to select regions randomly on the map and then "find" administrative divisions (state, region, county, village etc.) from the selection. Can feature layers be created from administrative units automatically? – codejunkie Sep 20 '16 at 05:46
  • 1
    if you have an esri service to point at, you can definitely skip instantiating an L.esri.featureLayer and just use L.esri.query() instead to retrieve GeoJSON. http://esri.github.io/esri-leaflet/api-reference/tasks/query.html – john gravois Sep 21 '16 at 16:07
  • Could you please share an example of this? I'm a newbie. – codejunkie Sep 24 '16 at 05:12
  • I already included a code snippet in my answer and a link to more code in my last reply. I'm happy to review some code of yours if you can share a codepen, jsfiddle or jsbin. – john gravois Sep 25 '16 at 10:22