Converting result of spatial querying to geoJson or retrieving administrative info (State, Country etc.)

536 Views Asked by At

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!

1

There are 1 best solutions below

4
On

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);
};