Solved! Go to Solution.
You do not need the TOC to tell you which layer is visible.
For service level layer, you should be using Layer.visible. For layers underneath a dynamic map service, use ArcGISDynamicMapServiceLayer.visibleLayers.
My web map includes one dymanamic mapservice with 13 layers, all listed in the TOC and most used in the identify. I want to do the same thing...only identify on layers that are visible, or checked in the TOC. I think this reply would work for me, but I don't quite follow it (still learning). If someone could explain a little more I think I can get there. I don't understand what nliu meant with "using layer.visible" or "using ArcGISDynamicMapServiceLayer.visibleLayers". Would this be a parameter with the identify function? Any clarification would be greatly appreciated! Thanks.
identifyParams.layerIds = YOURLAYERNAME.visibleLayers;
var infoTemplate = new esri.InfoTemplate('${layerName}', "${*}");
//// Identify Widget //// var popup = new esri.dijit.Popup({ fillSymbol: new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255, 0, 0]), 2), new dojo.Color([255, 255, 0, 0.25]))}, dojo.create("div")); dojo.connect(map,'onLoad',function(){ //setup generic identify parameters identifyParams = new esri.tasks.IdentifyParameters(); identifyParams.tolerance = 5; identifyParams.returnGeometry = true; identifyParams.layerIds = KSAVDynamicLayersALL.visibleLayers; dojo.connect(map,'onClick',doIdentify); }); dojo.connect(map,'onLayersAddResult', setupIdentify); function setupIdentify(results){ //loop through operational layers and add identify task for each. tasks = dojo.map(results,function(result){ return new esri.tasks.IdentifyTask(result.layer.url); }); } function doIdentify(evt){ map.infoWindow.hide(); clickPoint = evt.mapPoint; identifyParams.geometry = evt.mapPoint; identifyParams.mapExtent = map.extent; identifyParams.width = map.width; identifyParams.height = map.height; var deferreds = dojo.map(tasks,function(task){ return task.execute(identifyParams); }); var dlist = new dojo.DeferredList(deferreds); dlist.then(handleQueryResults); } function handleQueryResults(results){ var features = []; dojo.forEach(results,function(result){ // for a simplified test let's just display all the attributes in the popup if(result[1].length > 0){ dojo.forEach(result[1],function(r){ var feature = r.feature; console.log(feature); feature.attributes.layerName =r.layerName; var infoTemplate = new esri.InfoTemplate('${r.layerName}', "${*}"); feature.setInfoTemplate(infoTemplate); features.push(feature); ///// NOTE the above infoTemplate isn'try working in that "layerName' should be the layer's name. I want a layer //name like "Water Mains" to be in the title of the popup InfoWindow. Not working. i need to maybe make a variable that is //LayersALL.layerName as an array or something }); } }); map.infoWindow.setFeatures(features); map.infoWindow.show(clickPoint); } //// ^^^ Identify Widget ////
K M,
Did you find the way to pass the dynamic layer automatically dependent on the map service the toc use or the the mouse clicked on. I used this toc widget with 4 map services, but I can not figure out how to let the program know which map service the identify is going to use. I could use YOURLAYERNAME to pass the map service, but only can hard code it one map service. Is there a way to know which map service is using dynamically?
identifyParams.layerIds = YOURLAYERNAME.visibleLayers;
Thanks
Zhujing
var feature = result.feature; feature.attributes.layerName = result.layerName; if (result.layerName === 'Zoning Classifications') { console.log(feature.attributes.NAME); var template = new esri.dijit.PopupTemplate({ title: "Zoning", description: "<b>Zoning:</b> {Zoning Classification} <br/> <b>Description:</b> {Zoning Description}" }); feature.setInfoTemplate(template); return feature; }); if (results.length === 0) { map.infoWindow.clearFeatures(); } else { map.infoWindow.setFeatures(results); } map.infoWindow.show(idParams.geometry); return results; }
var popup = new esri.dijit.Popup({ fillSymbol: new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255, 0, 0]), 2), new dojo.Color([255, 255, 0, 0.25])) }, dojo.create("div")); map = new esri.Map("map", { infoWindow: popup, extent: startExtent, logo: false });
dojo.require("esri.dijit.Popup");
//// Identify Widget //// var identifyParams; var tasks; var clickPoint; //var popup = new esri.dijit.Popup({ fillSymbol: new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255, 0, 0]), 2), new dojo.Color([255, 255, 0, 0.25]))}, dojo.create("div")); dojo.connect(map, 'onLoad', function () { //setup generic identify parameters identifyParams = new esri.tasks.IdentifyParameters(); identifyParams.tolerance = 5; identifyParams.returnGeometry = true; identifyParams.layerIds = MYDYNAMICLAYER.visibleLayers; identifyParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_VISIBLE; dojo.connect(map, 'onClick', doIdentify); }); dojo.connect(map, 'onLayersAddResult', setupIdentify); function setupIdentify(results) { //loop through operational layers and add identify task for each. tasks = dojo.map(results, function (result) { return new esri.tasks.IdentifyTask(result.layer.url); }); } function doIdentify(evt) { map.infoWindow.hide(); clickPoint = evt.mapPoint; identifyParams.geometry = evt.mapPoint; identifyParams.mapExtent = map.extent; identifyParams.width = map.width; identifyParams.height = map.height; identifyParams.layerIds = MYDYNAMICLAYER.visibleLayers; identifyParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_VISIBLE; var deferreds = dojo.map(tasks, function (task) { return task.execute(identifyParams); }); var dlist = new dojo.DeferredList(deferreds); dlist.then(handleQueryResults); } function handleQueryResults(results) { var features = []; dojo.forEach(results, function (result) { // for a simplified test let's just display all the attributes in the popup if (result[1].length > 0) { dojo.forEach(result[1], function (r) { var feature = r.feature; console.log(feature); feature.attributes.layerName = r.layerName; var infoTemplate = new esri.InfoTemplate("${name}", "${*}"); feature.setInfoTemplate(infoTemplate); features.push(feature); }); } }); map.infoWindow.setFeatures(features); map.infoWindow.show(clickPoint); } //// ^^^ Identify Widget ////
Hi,
It seems this TOC only can have 2 Dynamic map services show in the TOC window, Is there a way to show more dynamic map services?
Thanks
Zhujing
You can have as many services as you'd like. You have to add them into the layerInfos object as described in the documentation.
Ken,
In my application, no any map service show in the legend window after I add in the third map service to the layerInfos, but i could add in any 2 of the map services in different ways.
What do you think the problem is?
Thanks
Zhujing
>>> Ken Buja <geonet@esri.com> 9/25/2014 3:53 PM >>>
Ken Buja replied to the discussion
"NLiu's Table of Contents(TOC)/Legend widget and Visibility States"
To view the discussion, visit: https://community.esri.com/message/425141?et=watches.email.thread#425141