Skip to content

Instantly share code, notes, and snippets.

@raykendo
Created May 25, 2015 05:48
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 raykendo/31fb197a3f1a1ba52a6f to your computer and use it in GitHub Desktop.
Save raykendo/31fb197a3f1a1ba52a6f to your computer and use it in GitHub Desktop.
ArcGIS JSAPI: Query Distinct, the old fashion way.
require([..., "esri/tasks/query", "esri/tasks/QueryTask", "dojo/_base/array",...],
function (..., Query, QueryTask, arrayUtils,...) {
...
// urls faked to protect the innocent kitties
var qTask = new QueryTask("http://www.cat-hurders.com:6080/arcgis/rest/services/CatSightings/MapServer/"),
query = new Query();
// set up the parameters to query for the breeds
query.where = "1=1";
query.outFields = ["breed"];
query.returnGeometry = false;
// execute the query
qTask.execute(query).then(function (featureSet) {
var features, i;
// collect the list of breeds
features = arrayUtils.map(featureSet.features, function (feature) {
return feature.attributes.breed;
});
// sort the list
features.sort();
// pick through each item in the list, and if it matches the item before, remove it.
for (i = features.length - 1; i > 0; i--) {
if (features[i] === features[i-1]) {
features.splice(i, 1);
}
}
// do something with the list.
...
});
...
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment