AnsweredAssumed Answered

toggle feature?

Question asked by ahmadsopian on Jul 13, 2016
Latest reply on Jul 15, 2016 by rscheitlin
<script type="text/javascript">
    dojo.require("dijit.dijit"); // optimize: load dijit layer 
    dojo.require("dijit.layout.BorderContainer");
    dojo.require("dijit.layout.ContentPane");
    dojo.require("esri.map");
    dojo.require("esri.toolbars.draw");
    dojo.require("esri.layers.FeatureLayer");
    dojo.require("esri.tasks.query");
    dojo.require("dojox.grid.DataGrid");
    dojo.require("dojo.data.ItemFileReadStore");
    dojo.require("dijit.layout.TabContainer");
    var map, toolbar;
    var featureLayer;
    function init() {
        var initExtent = new esri.geometry.Extent({ "xmin": 9773773.173194762, "ymin": -1718113.5089816158, "xmax": 16446419.994375736, "ymax": 1187716.5583068724, "spatialReference": { "wkid": 102100} });
        map = new esri.Map("map", {
            extent: initExtent
        });
        dojo.connect(map, 'onLoad', function (map) {
            identifyTask = new esri.tasks.IdentifyTask("http://gisserver/ArcGIS/rest/services/multi/MapServer");
            identifyParams = new esri.tasks.IdentifyParameters();
            identifyParams.tolerance = 3;
            identifyParams.returnGeometry = true;
            identifyParams.layerIds = [0, 1, 2];
            identifyParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_ALL;
            identifyParams.width = map.width;
            identifyParams.height = map.height;
            //initialize the toolbar 
            toolBar = new esri.toolbars.Draw(map);
            dojo.connect(toolBar, "onDrawEnd", onDrawEnd);
            //resize the map when the browser resizes 
            dojo.connect(dijit.byId('map'), 'resize', map, map.resize);
        });
        var basemapUrl = "http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer";
        var basemap = new esri.layers.ArcGISTiledMapServiceLayer(basemapUrl);
        var landBaseLayer = new esri.layers.ArcGISDynamicMapServiceLayer("gisserver/ArcGIS/rest/services/multi/MapServer", { opacity: 100 });
        map.addLayer(basemap);
        map.addLayer(landBaseLayer);
    }
    function onDrawEnd(extent) {
        toolBar.deactivate();
        executeIdentifyTask(extent);
    }
    function executeIdentifyTask(geom) {
        //clear the graphics layer  
        map.graphics.clear();
        var polygonSymbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID,
                                new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DOT,
                                new dojo.Color([151, 249, 0, .80]), 3),
                                new dojo.Color([151, 249, 0, 0.45]));
        identifyParams.geometry = geom;
        identifyParams.mapExtent = map.extent;
        identifyTask.execute(identifyParams, function (response) {
            var waItems = [];
            var weItems = [];
            var basItems = [];
            dojo.forEach(response, function (result) {
                var feature = result.feature;
                //add selected feature to graphics layer 
                feature.setSymbol(polygonSymbol);
                map.graphics.add(feature);
                if (result.layerName === 'We') {
                    weItems.push(feature.attributes);
                } else if (result.layerName === 'wa') {
                    waItems.push(feature.attributes);
                } else if (result.layerName === 'Bas') {
                    basItems.push(feature.attributes);
                }
            });
            //update the data grid  
            var waStore = new dojo.data.ItemFileReadStore({ data: { identifier: 'FID', items: waItems} });
            gridwa.setStore(waStore);


            var weStore = new dojo.data.ItemFileReadStore({ data: { identifier: 'FID', items: weItems} });
            gridwe.setStore(weStore);
            var basStore = new dojo.data.ItemFileReadStore({ data: { identifier: 'FID', items: basItems} });
            gridbas.setStore(basStore);


        });
    }
    //show map on load  
    dojo.addOnLoad(init); 
    </script> 

Kelly Hutchins

help create toggle layer for select multiple features

 

 

Outcomes