[OpenLayers-Trac] [OpenLayers] #3661: OpenLayers.Format.EsriGeoJSON: a format to convert ArcGIS Server REST GeoJSON output to GeoJSON being used by OpenLayers

OpenLayers trac-20090302 at openlayers.org
Mon May 21 16:14:57 EDT 2012


#3661: OpenLayers.Format.EsriGeoJSON: a format to convert ArcGIS Server REST
GeoJSON output to GeoJSON being used by OpenLayers
-------------------------------------------------+--------------------------
 Reporter:  liuxd8510                            |       Owner:  tschaub
     Type:  feature                              |      Status:  new    
 Priority:  minor                                |   Milestone:         
Component:  Format                               |     Version:  2.11   
 Keywords:  ArcGIS Server; ESRI; REST; GeoJSON;  |       State:         
-------------------------------------------------+--------------------------
 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.

-- 
Ticket URL: <http://trac.openlayers.org/ticket/3661>
OpenLayers <http://openlayers.org/>
A free AJAX map viewer


More information about the Trac mailing list