Ticket #3661 (new feature)
Opened 13 months ago
OpenLayers.Format.EsriGeoJSON: a format to convert ArcGIS Server REST GeoJSON output to GeoJSON being used by OpenLayers
| Reported by: | liuxd8510 | Owned by: | tschaub |
|---|---|---|---|
| Priority: | minor | Milestone: | |
| Component: | Format | Version: | 2.11 |
| Keywords: | ArcGIS Server; ESRI; REST; GeoJSON; | Cc: | liuxd8510@… |
| State: |
Description
Our OpenLayers application has a demand of directly and dynamically loading data from the vector output (GeoJSON) of a bunch of ArcGIS Server REST services. OpenLayers doesn't have a native support in doing so. Referring to an example http://mapbutcher.com/blog/2008/10/07/arcgis-server-rest-api-openlayers-and-some-potatoes/ (it uses Polygon as example) as the starting point, we extended the support to all other geometry types (Point/Multipoint/LineString/MultiLineString/Polygon/MultiPolygon) and packed them into a new Format (inherits from GeoJSON format).
how to use:
var new_geojson_layer = new OpenLayers.Layer.Vector("Esri_URL_GeoJSON", {
strategies: [new OpenLayers.Strategy.Fixed()],
protocol: new OpenLayers.Protocol.Script({ //to get around cross-domain if this issue exists
url: arcgis_rest_query_url, //ArcGIS Server REST GeoJSON output url
format: new OpenLayers.Format.EsriGeoJSON(),
parseFeatures: function(data) {
return this.format.read(data);
}
})
});
or:
var new_geojson_layer = new OpenLayers.Layer.Vector("Esri_URL_GeoJSON", {
strategies: [new OpenLayers.Strategy.Fixed()]
});
var new_protocol = new OpenLayers.Protocol.Script({ //using this protocal to request output from a given output_url
url: arcgis_rest_query_url,
callback: function(response) { //data is returned
var esri_geojson_format = new OpenLayers.Format.EsriGeoJSON();
var new_features = esri_geojson_format.read(response); //parse ESRI_GeoJSON to OpenLayers Features
if(new_features) {
new_geojson_layer.addFeatures(new_geojson_layer);
}
}
});
Note: We are not sure whether it's necessary to output OpenLayers feature to ESRI GeoJSON, so for now, the wirte() is same as the one in OpenLayers.Format.GeoJSON.
Hope this is something helpful to other OL users.

