I have set up a search function that allows a user to type in a value then perform a search for a point feature. Results will post in a data grid. When I click on the record in the data grid I can zoom to a point. However, when I click another record to zoom to that record, the map zooms in further. Is there a way to prevent this from happening? I need to keep the same zoom extent for all features, rather than zooming in further as each record is clicked. Here is the code that I have so far:
Does not include variable declaration or function init (
Code:
function doFind() {
//Set the search text to the value in the box
findParams.searchText = dojo.byId("searchText").value;
if (findParams.searchText == 0)
{
alert("There are no tree species found. Please type in a valid species code");
}
else
{
findTask.execute(findParams,showResults2);
}
}
function showResults2(results) {
//This function works with an array of FindResult that the task returns
map.graphics.clear();
var markerSymbol = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE, 12, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([0, 0, 0]), 1), new dojo.Color([0, 255, 255, .5]));
var lineSymbol = new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DASH, new dojo.Color([0, 255, 255]), 1);
var polygonSymbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([0, 0, 0, 1]), 2), new dojo.Color([255, 255, 0, 0.5]));
if(results.length == 0)
{
alert("There are no tree species found.");
}
else
{
//create array of attributes
var items = dojo.map(results,function(result){
var graphic = result.feature;
switch (graphic.geometry.type) {
case "point":
graphic.setSymbol(markerSymbol);
break;
case "polyline":
graphic.setSymbol(lineSymbol);
break;
case "polygon":
graphic.setSymbol(polygonSymbol);
break;
}
map.graphics.add(graphic);
return result.feature.attributes;
});
}
//Create data object to be used in store
var data = {
identifier: "AssetID", //This field needs to have unique values
//label: "Asset ID", //Name field for display. Not pertinent to a grid but may be used elsewhere.
items: items
};
//Create data store and bind to grid.
store = new dojo.data.ItemFileReadStore({ data:data });
var grid = dijit.byId('grid');
grid.setStore(store);
//Zoom back to the initial map extent
map.centerAndZoom(center, zoom);
}
//Zoom to tree when user clicks a row
function onRowClickHandler(evt){
var TreePoint = grid.getItem(evt.rowIndex).AssetID;
var SelectedTreePoint;
dojo.forEach(map.graphics.graphics,function(graphic){
if((graphic.attributes) && graphic.attributes.AssetID === TreePoint){
SelectedTreePoint = graphic;
return;
}
});
var TreePointExtent = SelectedTreePoint.geometry;
map.centerAndZoom(TreePointExtent, .001);
}