Skip to content

Instantly share code, notes, and snippets.

@odoe
Created December 15, 2014 16:59
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 odoe/8aa12f4e68ca328b549c to your computer and use it in GitHub Desktop.
Save odoe/8aa12f4e68ca328b549c to your computer and use it in GitHub Desktop.
xstyle model
define([
'esri/tasks/FindTask',
'esri/tasks/FindParameters',
'esri/graphicsUtils'
], function(
FindTask, FindParameters, gUtils
) {
var model = {
map: undefined,
setParams: function(params) {
model.map = params.map;
model.url = params.url;
model.searchFields = params.searchFields;
model.layerIds = params.layerIds;
},
init: function() {
model.task = new FindTask(model.url);
},
value: '',
message: 'Find',
find: function(e) {
if (!model.task) {
model.init();
}
var params = new FindParameters();
params.outSpatialReference = model.map.spatialReference;
params.returnGeometry = true;
params.searchText = model.value;
params.searchFields = model.searchFields;
params.layerIds = model.layerIds;
model.task.execute(params).then(function(result) {
console.debug(result);
if (result.length) {
var feature = result[0].feature;
model.map.setExtent(gUtils.graphicsExtent([feature]));
} else {
alert('No results found');
}
}, function(err) {
console.log('Error in search: ', err);
});
},
updateValue: function(e) {
model.value = e.target.value;
}
};
return model;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment