Skip to content

Instantly share code, notes, and snippets.

@jgravois
Created November 28, 2013 00:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgravois/7685198 to your computer and use it in GitHub Desktop.
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.
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