Hi David,I believe the problem is the extent is wrong when you try to zoom to the feature. Try the following instead:var map;
var findTask, findParams;
function init(){
map = new esri.Map("map")
var basemap = new esri.layers.ArcGISDynamicMapServiceLayer("http://myserver/ArcGIS/rest/services/Basemap/MapServer");
map.addLayer(basemap);
//Create Find Task using Post code layer
findTask = new esri.tasks.FindTask("http://myserver/ArcGIS/rest/services/Basemap/MapServer/");
//Create the find parameters
findParams = new esri.tasks.FindParameters();
findParams.returnGeometry = true;
findParams.layerIds = [0];
findParams.searchFields = ["NAME"];
findParams.outSpatialReference = map.spatialReference;
}
function doFind(){
//Set the search text to the value in the box
findParams.searchText = dojo.byId("name").value;
findTask.execute(findParams, showResults);
}
function showResults(results){
map.graphics.clear();
var symbol = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_DIAMOND, 10,
new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID,
new dojo.Color([0, 0, 0]), 1),
new dojo.Color([255, 255, 0, 1]));
//Create items array
var items = [];
for (var i = 0, il = results.length; i < il; i++) {
items.push(results.feature.attributes); //append each attribute list as item in store
var graphic = results.feature;
graphic.setSymbol(symbol);
map.graphics.add(graphic);
}
for (var i = 0, il = map.graphics.graphics.length; i < il; i++) {
var currentGraphic = map.graphics.graphics;
}
extent = pointToExtent(map, currentGraphic.geometry.x, currentGraphic.geometry.y, 6)
map.setExtent(extent);
}
function pointToExtent(map, pointX, pointY, toleranceInPixel) {
var pixelWidth = map.extent.getWidth() / map.width;
var toleraceInMapCoords = toleranceInPixel * pixelWidth;
return new esri.geometry.Extent( pointX - toleraceInMapCoords,
pointY - toleraceInMapCoords,
pointX + toleraceInMapCoords,
pointY + toleraceInMapCoords,
map.spatialReference );
}
dojo.addOnLoad(init);
The function 'pointToExtent' will calculate the extent based off of the selected graphics X and Y coordinates.