Skip to content

Instantly share code, notes, and snippets.

@brightrain
Created February 11, 2015 00:50
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 brightrain/2036ceb58860266d5658 to your computer and use it in GitHub Desktop.
Save brightrain/2036ceb58860266d5658 to your computer and use it in GitHub Desktop.
esri-geocoder engine
// build the esri geocoder bloodhound engine
var esriBH = new Bloodhound({
name: "esri-geocoder",
datumTokenizer: function (d) {
return Bloodhound.tokenizers.whitespace(d.name);
},
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
//https://developers.arcgis.com/rest/geocode/api-reference/geocoding-suggest.htm
// use the searchExtent parameter to limit the results to roughly washington state
url: config.arcgisGeocodingBaseUrl +
"suggest?text=%QUERY&searchExtent=-125,49,-116.9,45.5&f=json",
filter: function (data) {
return $.map(data.suggestions, function (result) {
//typically this is a category or type of business (e.g. coffee shops)
if(result.isCollection === false) {
return {
name: result.text,
magicKey: result.magicKey,
source: "esri-geocoder"
};
}
});
},
ajax: {
beforeSend: function (jqXhr, settings) {
$("#search-loading-icon").addClass("search-loading");
},
complete: function (jqXHR, status) {
$("#search-loading-icon").removeClass("search-loading");
}
}
},
limit: 5
});
esriBH.initialize();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment