Created
November 28, 2013 00:04
-
-
Save jgravois/7685198 to your computer and use it in GitHub Desktop.
loop through response fields and find 'esriFieldTypeOID' instead of pulling information from response.objectIdFieldName (which is only present in a response from FeatureServer layer.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if(response.features.length && !response.error){ | |
//loop through fields returned by service | |
for (var j = response.fields.length - 1; j >= 0, j--) { | |
//find field with type 'esriFieldTypeOID' and use its name as an attribute when converting to GeoJSON | |
if(response.fields[j].type == "esriFieldTypeOID") | |
var idKey = response.fields[j].name | |
} | |
for (var i = response.features.length - 1; i >= 0; i--) { | |
var feature = response.features[i]; | |
var id = feature.attributes[idKey]; | |
if(!this._layers[id]){ | |
var geojson = Terraformer.ArcGIS.parse(feature); | |
geojson.id = id; | |
this.index.insert(geojson, geojson.id); | |
this.addData(geojson); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment