Datguy
Datguy

Reputation: 151

Can you use self-hosted (or otherwise non-arcGIS) data with the esri leaflet feature layer api?

I am using a third-party application which allows the user to add custom map layers to a Leaflet map. All I am able to input is a url to the map layer. I've taken a look at the source code and they are using this method:

https://developers.arcgis.com/esri-leaflet/api-reference/layers/feature-layer/

My GIS files are not hosted through an arcGIS system. Is there a way I can serve my own files so that this method will load them onto the map properly?

I tried a couple urls, but I see inconsistent behaviour:

  1. geoJson url

Enter this: https://foo.blob.core.windows.net/gis/roads.geojson

Site fetches this: https://foo.blob.core.windows.net/gis/roads.geojson/query?returnGeometry=true&where=*&outFields=*&in*&geometry=*&geometryType=*&spatialRel=*&geometryPrecision=*&f=geojson

This is also what it does with the typical arcgis urls, which works well for them, but not for plain static files.

  1. Miscellaneous url

Enter this: https://foo.blob.core.windows.net/gis

Site fetches this: https://foo.blob.core.windows.net/gis/?f=json

The miscellaneous url is the one that really gets me, because https://foo.blob.core.windows.net/gis/query is geoJson, so I thought maybe this would be a successful workaround.

That said, I'm not sure if this method will even load geoJSON or if it has to be one of the esri formats.

Upvotes: 0

Views: 60

Answers (1)

Datguy
Datguy

Reputation: 151

The ArcGIS Feature Service protocol works like this:

Suppose 'https://foo.blob.core.windows.net/gis' is your "base URL".

First, it requests <base_url>?f=json, which will return metadata about the spatial data you are requesting. It uses this to decide what format to request the spatial data in.

If you look at one of these pages from a real ArcGIS Feature Service, then you can see that the base URL provides a variety of human-readable information, such as the physical extents of the data and the formats (e.g. geoJSON, esri JSON [just called JSON by the service]) that the data is available in. Appending '?f=json' to the base URL will cause the service to return this data in JSON format instead, so that it can be programatically read.

Second, it will make requests to <base_url>/query?<...query params...>. It will make multiple of these requests, especially as you zoom and pan around the map, because it only requests each chunk of data as it needs it.

If you want to serve GIS data to a client which only accepts this protocol, do the following:

  1. Make sure your GIS data is geoJSON in the WGS 84 (EPSG:4326) CRS, and is all of a single geometry type, e.g. LineString, Point, etc.
  2. Add an 'id' property to all of the features in the geoJSON. This means that each feature will have type, properties, geometry, and now id. Without this non-standard id, esri-leaflet will not display the data. You can do this now or have your server add it. The ids can be simple integers indices from 0 or 1 onwards.
  3. Create a base URL which returns this minimal metadata: { 'supportedQueryFormats': 'geoJSON' }
  4. Create <base_url>/query which returns your GIS data.

If you want to read the querystring params that the client sends you and adjust your response based on that, have fun 😃.

Final note: if you get 'invalid geoJSON' messages in the console, it may be that esri-leaflet is trying to convert the incoming data to geoJSON. If your URL matches the pattern .*\.arcgis\.com.*FeatureServer then esri-leaflet will assume the incoming data is geoJSON and will not try to convert it.

Upvotes: 0

Related Questions