Skip to content

Instantly share code, notes, and snippets.

@brightrain
Last active August 29, 2015 14:15
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/9f7efde8f77a63ca5125 to your computer and use it in GitHub Desktop.
Save brightrain/9f7efde8f77a63ca5125 to your computer and use it in GitHub Desktop.
define campground engine
// https://github.com/twitter/typeahead.js/blob/master/doc/bloodhound.md#options
var campBH = new Bloodhound({
name: "camp",
datumTokenizer: function (d) {
return Bloodhound.tokenizers.whitespace(d.name);
},
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
// feature services currently only support query
// if you are using a map server, use find
//http://resources.arcgis.com/en/help/arcgis-rest-api/index.html#/Query_Feature_Service_Layer/02r3000000r1000000/
url: config.featureServerUrl + config.featureLayerIndexes.camp + "/query?" +
"where=REC_NAME Like '%%QUERY%'" +
"&outFields=REC_NAME,OBJECTID" +
"&returnGeometry=false&f=json",
// build the 'datums' that populate the search drop down
// this happens on the callback to the query above
filter: function (data) {
// we only need the name,
// objectid (to retrieve the feature if selected)
// and the source (to later determine which type was selected by the user)
return $.map(data.features, function (feature) {
return {
name: feature.attributes.REC_NAME,
objectId: feature.attributes.OBJECTID,
source: "camp"
};
});
},
// set and remove spinners
ajax: {
beforeSend: function (jqXhr, settings) {
$("#search-loading-icon").addClass("search-loading");
},
complete: function (jqXHR, status) {
$("#search-loading-icon").removeClass("search-loading");
}
}
},
limit: 5
});
campBH.initialize();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment