Wednesday, October 29, 2008

Alphabetize a featureset

If you are using ESRI's ArcGIS JavaScript Extensionfor teh Google Maps API, you may have noticed that when performing a query or search, your results are returned to you in a completely random order. Here is how you can alphabetize your results:

//fset is of type esri.arcgis.gmaps.FeatureSet() returned by the QueryTask execute method
//The following alphabetizes the array
fset.features.sort(function(a,b){
var aString = a.attributes.School;
var bString = b.attributes.School;

if (aString < bString) return -1;
else if (aString > bString) return 1;
else return 0;
});

No comments: