Converting geojson to feature layer

5745
2
06-10-2015 05:14 AM
ChristerVinje_Gimse
New Contributor

Hi!

I am building a simple app with the ESRI javascript API. It contains two feature layers from an ESRI REST API, and I also need to get GPX-data from another API. I have managed to get and convert the GPX into geojson, and now I want to create a feature layer in my code to display the geojson data on the same map.

The question is how?

Here are code snippets:

Simple featureLayer:

var featureLayerEnkeltminner = new FeatureLayer("http://askeladden_wms.ra.no/arcgis/rest/services/WMS/RA_Askeladden/MapServer/1", {

    infoTemplate: new InfoTemplate("${Navn}", "${*}"),

    outFields: ["Navn", "KulturminneID", "KategoriID", "VernetypeID", "KOMM"]

  });

Get and convert GPX-data:

var api = new KR.API();

var tur = {

     api: 'utno2,

     id: '2.11234',

     type: 'gpx'

};

api.getData(tur, function (res) {

     console.log(res);

The code above uses other javascript libraries than ESRI, but that should not be a problem. The console logs the object like it should:

Objectfeatures:

     Array[1]0:

          Objectgeometry:

               Objectcoordinates:

                    Array[2057]

                    type: "LineString"

                    __proto__:

               Objectproperties:

                    Objectname: "Flyktningeruta"

                    [...]

So the thing is that I need to use something like featureCollection to create a featureLayer, but how do I get the methods to use object I have created?

All help is greatly appreciated!

Chris

0 Kudos
2 Replies
FilipKrál
Occasional Contributor III

Hello Christer,

I've seen some examples that converted between GeoJSON and EsriJSON (i.e. ArcGIS REST API JSON) using a JavaScrip library called Terraformer​.

You could also try to bounce your GeoJSON off one of my services:

https://omnimion.com/om/services/geojson-esrijson/

You should be able to post your geojson for example using jquery:

$.ajax( {
  url: "https://omnimion.com/om/services/geojson-esrijson"
  data: {"q": JSON.stringify(geojson)},
  method: 'POST',
  dataType: 'json'
}).done( function(data){    
  console.log(data); // data should contain esrijson
}).fail( function(err){ 
  console.log(err);
});

You could certainly add the converted feature to a GraphicsLayer, but I don't know how to create a full fledged FeatureLayer from it (which is a subtype of GraphicsLayer).

I would really like to know if it works for you or how you eventually solve this.

Filip.

0 Kudos
AdamJoseph1
New Contributor

alternative to serve out ESRI JSON is to use cartoview. Cartoview will install PostGIS and Python. You can easily load GeoJSON in PostGIS.

Or you can try ESRI koop it is available on Github

0 Kudos