I'm trying to convert a geoJSON to ESRI JSON (ultimately to create a FeatureLayer for use in a web map). I'm using the javascript API 3.24.
My original geoJSON looks like this:
<SPAN class="punctuation token">{</SPAN>
<SPAN class="string token">"type"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"FeatureCollection"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"features"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">[</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="string token">"type"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"Feature"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"geometry"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">{</SPAN>
<SPAN class="string token">"type"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"Polygon"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"coordinates"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">[</SPAN>
<SPAN class="punctuation token">[</SPAN>
<SPAN class="punctuation token">[</SPAN>
<SPAN class="number token">7.3868103070001</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="number token">6.0366749930001</SPAN>
<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="punctuation token">[</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN> ..... etc etc<BR />
</CODE></P><P>I've checked to see if this is properly formed using JSONlint and by bringing it into a GIS. All good there.</P><P>I've then used <A href="http://terraformer.io/arcgis-parser/" rel="nofollow noopener noreferrer" target="_blank">Terraformer</A> to convert the above into the ESRI JSON format using</P><P></P><PRE class="lia-code-sample line-numbers language-none"><CODE>Terraformer<SPAN class="punctuation token">.</SPAN>ArcGIS<SPAN class="punctuation token">.</SPAN><SPAN class="token function">convert</SPAN><SPAN class="punctuation token">(</SPAN>geojsonData<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN></SPAN>
This appears to work but looking at the returned object it looks like this:
<SPAN class="punctuation token">[</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="string token">"geometry"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">{</SPAN>
<SPAN class="string token">"rings"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">[</SPAN>
<SPAN class="punctuation token">[</SPAN>
<SPAN class="punctuation token">[</SPAN>
<SPAN class="number token">7.3868103070001</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="number token">6.0366749930001</SPAN>
<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="punctuation token">[</SPAN>
<SPAN class="number token">7.3872861030001</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="number token">6.036048758</SPAN>
<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="punctuation token">[</SPAN>
<SPAN class="number token">7.3888583080001</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="number token">6.0361989570001</SPAN>
<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
etc... etc... until
<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"spatialReference"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">{</SPAN>
<SPAN class="string token">"wkid"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="number token">4326</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"attributes"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">{</SPAN>
<SPAN class="string token">"OBJECTID"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"admin"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"Abia"</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>etc...etc...
Again I've checked the above with JSONlint and it appears to be valid. However, it is missing some of the ESRI JSON structure I was expecting (geometry type, fields etc)
When I try to set this ESRI JSON to a FeatureLayer I've included a layer definition but I'm still getting a spurious error. The code I'm using to create the FeatureLayer is as follows:
<SPAN class="keyword token">var</SPAN> request <SPAN class="operator token">=</SPAN> <SPAN class="token function">esriRequest</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">{</SPAN>
url<SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"php/getStates.php"</SPAN><SPAN class="punctuation token">,</SPAN>
handleAs<SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"json"</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">function</SPAN> <SPAN class="token function">requestSucceeded</SPAN><SPAN class="punctuation token">(</SPAN>data<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN>
<SPAN class="comment token">// use terraformer to convert geojson to ESRIjson</SPAN>
<SPAN class="keyword token">var</SPAN> arcdata <SPAN class="operator token">=</SPAN> Terraformer<SPAN class="punctuation token">.</SPAN>ArcGIS<SPAN class="punctuation token">.</SPAN><SPAN class="token function">convert</SPAN><SPAN class="punctuation token">(</SPAN>data<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">var</SPAN> featureCollection <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">{</SPAN>
layerDefinition<SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">{</SPAN>
<SPAN class="string token">"geometryType"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"esriGeometryPolygon"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"fields"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">{</SPAN>
<SPAN class="string token">"name"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"OBJECTID"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"type"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"esriFieldTypeOID"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"alias"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"OBJECTID"</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="string token">"name"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"admin"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"type"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"esriFieldTypeString"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"alias"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"admin"</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">,</SPAN>
featureSet <SPAN class="punctuation token">:</SPAN> arcdata
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">var</SPAN> fl <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">FeatureLayer</SPAN><SPAN class="punctuation token">(</SPAN>featureCollection<SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">{</SPAN>
mode<SPAN class="punctuation token">:</SPAN> FeatureLayer<SPAN class="punctuation token">.</SPAN>MODE_SNAPSHOT<SPAN class="punctuation token">,</SPAN>
outFields<SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">'OBJECTID'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'admin'</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>I'd like to know what might be going wrong here. The spurious error mentioned above is:
<SPAN class=""><SPAN class="" data-link-actor-id="server1.conn0.child1/obj18176"></SPAN></SPAN>
<SPAN class=""><SPAN class="" data-link-actor-id="server1.conn0.child1/obj18176"><SPAN>TypeError: b is undefined _addFeatures@</SPAN><A _jive_internal="true" href="https://community.esri.com/js.arcgis.com/3.24/:2256:226" target="_blank">https://js.arcgis.com/3.24/:2256:226</A><SPAN> </SPAN></SPAN></SPAN>
This is the first time I've looked properly into the js API so forgive me if this is an obvious blunder.