Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

For this project I am working on, I would like to display an ArcGIS Online FeatureService (JSON) in a webmap that I have built using OpenLayers.

I am able to read the JSON from the service, but I can't seem to 'convert' into a vector layer.

My code is the following:

var data = ($.ajax({
    url: '...',
    success: function (data) {
    console.log(data);
    }

    }));

   var geojson_format = new OpenLayers.Format.GeoJSON();
   var vector_layer = new OpenLayers.Layer.Vector();
   map.addLayer(vector_layer);
   vector_layer.addFeatures(geojson_format.read(data));

This unfortunately produces the following errors:

TypeError: g is null (FF)

TypeError: 'null' is not an object (evaluating 'g.layer=this') (Safari)

Uncaught TypeError: Cannot set property 'layer' of null (Chrome) 

Does anyone know how to fix this?

Thnx in advance!

share|improve this question
    
additionally, you can use QGIS. Load a shapefile and save as a geojson layer. The geojson format works with both OpenLayers and Leaflet. Make sure you re-project as a shapefile before converting. –  geomajor56 Apr 22 '13 at 14:17
    
Rather than include your solution within your Question, would you be able to transfer it to an Answer, please? It is then quite permissible for you to Accept your own answer. –  PolyGeo Apr 26 '13 at 21:01

2 Answers 2

I would have used the code given at this ticket: http://trac.osgeo.org/openlayers/ticket/3661.

That way you can get the data on the fly, and show it in your OpenLayers map.

share|improve this answer
up vote 0 down vote accepted

I already solved my own question:

It appeared that geoJSON from ArcGIS online is not correctly formatted for use in OpenLayers. If you ever run into this issue yourself, you can convert esri GeoJSON to 'regular' GeoJSON by using this service:

http://esritogeo.herokuapp.com/

(be sure to check the result properly though, as in this case, there were too many brackets around the coordinates).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.