Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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