findTask = new FindTask("link to the featureServer/"); // Create a new constructor by mixing in the components
// Allow row selection for the grid
var myGrid = declare([Grid, Selection]);
//columns for the grid
var columns = [
{'field': 'objectid', 'label': "Objet ID"},
{'field': 'nom', 'label': 'Nom'},
{'field': 'ex_nom', 'label': 'Ex nom'},
{'field': 'nature_cha', 'label': 'Nature chaussée'},
{'field': 'sens_circu', 'label': 'Sens circulation', width:"30%"}
];
// Create an instance of Grid
grid = new myGrid({
columns: columns,
selectionMode: 'single',
}, 'grid');
grid.on("dgrid-select", onRowClickHandler);
map.on("load", function () {
//Create the find parameters
findParams = new FindParameters();
findParams.returnGeometry = true;
findParams.layerIds = [17]; //VOIRIE
findParams.searchFields = ["nom", "ex_nom"];
findParams.outSpatialReference = map.spatialReference;
console.log("find sr: ", findParams.outSpatialReference);
});
function doFind() {
//Set the search text to the value in the box
var ownerNameBox = dom.byId("findinput"); //ce que l'utilisateur à entrer
findParams.searchText = dom.byId("findinput").value;
findTask.execute(findParams, showResults);
}
function showResults(results) {
//This function works with an array of FindResult that the task returns
map.graphics.clear();
var symbol = new SimpleFillSymbol(
SimpleFillSymbol.STYLE_SOLID,
new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([98, 194, 204]), 2),
new Color([98, 194, 204, 0.5])
);
//create array of attributes
var items = arrayUtils.map(results, function (result) {
var graphic = result.feature;
graphic.setSymbol(symbol);
map.graphics.add(graphic);
return result.feature.attributes;
});
//display the results in the grid
grid.refresh();
grid.renderArray(items);
//Zoom back to the initial map extent
map.centerAndZoom(center, zoom);
}
//Zoom to the parcel when the user clicks a row
function onRowClickHandler(evt) {
var clickedTaxLotId = event.rows[0].data.objectid;
var selectedTaxLot = arrayUtils.filter(map.graphics.graphics, function (graphic) {
return ((graphic.attributes) && graphic.attributes.objectid === clickedTaxLotId);
});
if ( selectedTaxLot.length ) {
map.setExtent(selectedTaxLot[0].geometry.getExtent(), true);
}
}
var search = new Search({
enableButtonMode: true, //this enables the search widget to display as a single button
enableLabel: false,
enableInfoWindow: true,
showInfoWindowOnSelect: false,
map: map
}, "search");
var sources = search.get("sources");
var featureLayer1 = new FeatureLayer("..../1", {
mode: FeatureLayer.MODE_ONDEMAND,
outFields: ["*"]
});