0

现在,地图在数据网格中添加了每个找到的结果的图形。但我只想在数据网格中添加选定的图形,然后将范围(缩放)设置为选定的特征。有谁知道如何做到这一点?现在我这样做:

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);
    }
}
4

1 回答 1

-1

检查 ESRI 的资源中心 - JS API 示例部分。

这个http://help.arcgis.com/en/webapi/javascript/arcgis/samples/find_map_datagrid/index.html是工作示例。

而这个http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples_start.htm#jssamples/find_map_datagrid.html是该示例的源代码。

于 2012-12-06T15:17:08.557 回答