Last active
August 29, 2015 14:15
-
-
Save brightrain/9f7efde8f77a63ca5125 to your computer and use it in GitHub Desktop.
define campground engine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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