现在,地图在数据网格中添加了每个找到的结果的图形。但我只想在数据网格中添加选定的图形,然后将范围(缩放)设置为选定的特征。有谁知道如何做到这一点?现在我这样做:
function showResults(results) {
var markerSymbol = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_CIRCLE,
10,
new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID,
new dojo.Color([0,255,255]), 2),
new dojo.Color([0,255,0,0])
);
var lineSymbol = new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID,
new dojo.Color([0,255,255]),
4
);
var polygonSymbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID,
new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID,
new dojo.Color([0,255,255]), 4),
new dojo.Color([0,255,255,0])
);
map.graphics.clear();
var dataForGrid = [];
dojo.forEach(results, function(result) {
var graphic = result.feature;
dataForGrid.push([ result.foundFieldName, result.value]);
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);
});
var data = {
items: dataForGrid
};
var store = new dojo.data.ItemFileReadStore({
data: data
});
grid.setStore(store);
}
function onRowClickHandler(evt){
var clickedTaxLotId = grid.getItem(evt.rowIndex).POINT_NAME;
var selectedTaxLot;
dojo.forEach(map.graphics.graphics,function(graphic){
if((graphic.attributes) && graphic.attributes.POINT_NAME === clickedTaxLotId){
selectedTaxLot = graphic;
return;
}
});
if (selectedTaxLot.geometry.declaredClass == 'esri.geometry.Point' ) {
var PointExtent = new esri.geometry.Extent(); PointExtent.xmin = selectedTaxLot.geometry.x - 100; //I'm using State Plane Feet, so
that's 100 out from my point PointExtent.ymin =
selectedTaxLot.geometry.y - 100; PointExtent.xmax =
selectedTaxLot.geometry.x + 100; PointExtent.ymax =
selectedTaxLot.geometry.y + 100; map.setExtent(PointExtent);
} else if (selectedTaxLot.geometry.declaredClass == 'esri.geometry.Polyline' ) {
var taxLotExtent = selectedTaxLot.geometry.getExtent();
map.setExtent(taxLotExtent);
} else if (selectedTaxLot.geometry.declaredClass == 'esri.geometry.Polygon' ) {
var taxLotExtent = selectedTaxLot.geometry.getExtent();
map.setExtent(taxLotExtent);
}
}