identifyParams.layerIds = visible
function executeIdentifyTask(evt) { identifyParams.geometry = evt.mapPoint; identifyParams.mapExtent = map.extent;
function executeIdentifyTask(evt) { identifyParams.geometry = evt.mapPoint; identifyParams.mapExtent = map.extent; identifyParams.layerIds = visible
Simple way to get visiblelayerids and assign to identify parameters.
var FilteredLayerIds = app.ElectricGrid_Service.visibleLayers.slice(0);
identifyParams.layerIds = FilteredLayerIds;
Michael it does not seem likely ESRI will change it. Ultimately it would be good to see ESRI provide an Identify widget in the API that tracked visible layers and had capability to identify all visible layers. But for now you must build your own widget. I built an Identify that does this (with much help from Tracy, Adrian and everyone else here..thank you all). It works with the AGS JS TOC Widget mentioned here: MapViewer - Savannah Area GIS
Feel free to use all the code. Just let me know if you find any bugs.
Does ESRI or any Javascript developer know if this NIM has been fixed at any version of AGS v10.2.x or possibly at v10.3.0? It would be nice for the code to work as advertised in the documentation instead of resorting to workarounds.
educationLayer = new ArcGISDynamicMapServiceLayer(pathName+"/ArcGIS/rest/services/BaseMap/Education/MapServer", {id:'educationLayer', visible:false})
var layers = arrayUtils.map(app.map.layerIds, function(layerId) { return app.map.getLayer(layerId); });
var visLayers = layer.visibleLayers; if (visLayers !== -1) { //TOC lets the user change visibility, layerIDs must be explicitly defined idParams.layerIds = layer.visibleLayers; }else { idParams.layerIds = []; }
app.map.on("click", runIdentifies);
// FUNCTION FOR IDENTIFYING MULTIPLE LAYERS AT ONCE //manually define which layers to do the identify on based on visible Layers function createIdentifyParams(layers,evt){ identifyParamsList.length = 0; arrayUtils.forEach(layers, function (layer) { var idParams = new IdentifyParameters(); idParams.width = app.map.width; idParams.height = app.map.height; idParams.geometry = evt.mapPoint; idParams.mapExtent = app.map.extent; idParams.layerOption = IdentifyParameters.LAYER_OPTION_VISIBLE; var visLayers = layer.visibleLayers; if (visLayers !== -1) { //TOC lets the user change visibility, layerIDs must be explicitly defined idParams.layerIds = layer.visibleLayers; }else { idParams.layerIds = []; } idParams.tolerance = 3; idParams.returnGeometry = true; idParams.spatialReference = spatialReference; identifyParamsList.push(idParams); }); return identifyParamsList; } function runIdentifies(evt) { idPoint = evt.mapPoint; app.map.infoWindow.clearFeatures(); var layers = arrayUtils.map(app.map.layerIds, function(layerId) { return app.map.getLayer(layerId); }); layers = arrayUtils.filter(layers, function(layer) { if (layer.visibleLayers[0] !== -1){ return layer.getImageUrl && layer.visible } }); var params = createIdentifyParams(layers,evt); var tasks = arrayUtils.map(layers, function(layer) { return new IdentifyTask(layer.url); }); var IdentifyTaskList = arrayUtils.map(layers, function(layer, index) { task = new IdentifyTask(layer.url); return task.execute(params[index]) //assume you have a list of identifyParameters }); all(IdentifyTaskList).then(showIdentifyResults); } function showIdentifyResults(idResults){ var results = []; idResults = arrayUtils.filter(idResults, function (result) {//filter out any failed tasks return idResults[0]; }); for (i=0;i<idResults.length;i++) { //combines identifyResults var lyrResultLen = idResults.length; var lyrResult = idResults; for (j = 0; j < lyrResultLen; j++) { var featRes = lyrResult; results.push(featRes); } } formatResults = arrayUtils.map(results, function(result){ var feature = result.feature; var layerName = result.layerName; feature.attributes.layerName = result.layerName; feature.setInfoTemplate(generateInfoTemplate); generateInfoTemplate.setTitle("Layer Information"); return feature; }); if (formatResults.length > 0) { app.map.infoWindow.setFeatures(formatResults); app.map.infoWindow.show(idPoint); } }
var legisDistAtt = ['OBJECTID','District']; var prevDistAtt = ['OBJECTID','ID']; var countyAtt = ['OBJECTID', 'COUNTYNAME'];
generateInfoTemplate = new InfoTemplate(); generateInfoTemplate.setTitle("Layer Information"); generateInfoTemplate.setContent(generateWindowContent); function generateWindowContent(graphic) { var layerName = graphic.attributes.layerName;//case sensitive field names var fieldNamesArr = []; for (fieldName in graphic.attributes) { if (graphic.attributes.hasOwnProperty(fieldName) && fieldName !=='Shape' && fieldName !== 'Shape.area' && fieldName !== 'Shape.len') { fieldNamesArr.push(fieldName); } } var attString = ""; switch (layerName) { case "House District": attString = createAttRows(graphic, legisDistAtt); break; case "Senate District": attString = createAttRows(graphic, legisDistAtt); break; case "Congressional District": attString = createAttRows(graphic, legisDistAtt); break; case "County": attString = createAttRows(graphic, countyAtt); break; default: attString = createAttRows(graphic, fieldNamesArr); } return "<h4>"+ layerName +"</h4>" +"<table id='infoWindowTable' data-dojo-type='dojox/grid/DataGrid' data-dojo-props='class:'infoTable'' ><tr><th></th><th></th></tr>" +attString+ "</table>"; } function createAttRows(graphic, attArray) { var returnString = ""; arrayUtils.forEach(attArray, function (attName){ if (attName !== 'OBJECTID' && attName !== 'layerName') { returnString = returnString + "<tr><td><b>"+attName+"</b></td><td>" + graphic.attributes[attName]+ "</td></tr>"; } }); return returnString; }
NIM is still open.
Many thanks - so reported over 3 years ago!! So, I don't think I'll hold my breath for a fix anytime soon.
BTW, can anyone else (none esri staff) get the link to the bug report from Shuping Li to work?ACM
It looks like you should be able just to addidentifyParams.layerIds = visibleto function executeIdentifyTask(evt) { identifyParams.geometry = evt.mapPoint; identifyParams.mapExtent = map.extent; to give you function executeIdentifyTask(evt) { identifyParams.geometry = evt.mapPoint; identifyParams.mapExtent = map.extent; identifyParams.layerIds = visible Should work
I think you are experiencing [NIM042441 The layerOption LAYER_OPTION_VISIBLE not working as expected while using Identify Task.]. The LAYER_OPTION_VISIBLE seems only response to the default visible layers in the map service.To workaround this, as amarsden did, please assign the list of visible layer to the IdentifyParameters.layerIds property, which can force the identify task to only perform the find operation on the specified layers.
function updateLayerVisibility() { var inputs = dojo.query(".list_item"), input; visible = []; dojo.forEach(inputs,function(input){ if (input.checked) { visible.push(input.id); } }); //if there aren't any layers visible set the array to be -1 if(visible.length === 0){ visible.push(-1); } dynamicMapServiceLayer.setVisibleLayers(visible); }
Thanks I've added your code but it's still not working. It still identifies sublayers which are turned off in the layerlist. I thought it is something with the lids and the build layer list. But I can't really pinpoint it.
var legendLayers = [] var parcels = new esri.layers.FeatureLayer("restURL",{ mode:esri.layers.FeatureLayer.MODE_SNAPSHOT, id: 'parcels', outFields:["*"] }); legendLayers.push({layer:parcels,title:"Property Boundaries"});
I was having the same issue. identifyParams.LAYER_OPTION_VISIBLE would still identify layers that are hidden (not checked in the dijit.legend).I *think* the LAYER_OPTION_VISIBLE pertains to the scale visibility, set in either the rest service or when the feat. layer is added to the map. So, if your at a scale within the layer visible scale range, it will identify, regardless if it's 'turned on' or not in the dijit.legend widget. I even tried adding LAYER_OPTION_VISIBLE param to the begining of the click event, so the layer visibility list would be 'more up to date' but it didn't work. I did find that the identifyParams.layerIds does restrict the identify layers, so I simply added this to the beginning of the onClick function, prior to identifyTask.execute(identifyParams): //lets manually set the identifyParams.layerIds //to the layers that are currently checked in the legend widget var lids = []; dojo.forEach(legendLayers, function(layer){ if (layer.layer.visible === true){ lids.push(map.getLayer(layer.layer.id).layerId) } }); identifyParams.layerIds = lids;
//lets manually set the identifyParams.layerIds //to the layers that are currently checked in the legend widget var lids = []; dojo.forEach(legendLayers, function(layer){ if (layer.layer.visible === true){ lids.push(map.getLayer(layer.layer.id).layerId) } }); identifyParams.layerIds = lids;
identifyParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_VISIBLE;
<script type="text/javascript"> var djConfig = { parseOnLoad: true }; </script> <script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.6"></script> <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.dijit.Popup"); var layer, map, visible = []; var identifyTask,identifyParams; function init() { //Popup esri.bundle.widgets.popup.NLS_searching = "Zoeken..."; esri.bundle.widgets.popup.NLS_noInfo = "Niets gevonden"; esri.bundle.widgets.popup.NLS_nextFeature = "Volgende"; esri.bundle.widgets.popup.NLS_prevFeature = "Vorige"; esri.bundle.widgets.popup.NLS_maximize = "Maximaliseren"; esri.bundle.widgets.popup.NLS_restore = "Vorig formaat"; esri.bundle.widgets.popup.NLS_close = "Sluiten"; esri.bundle.widgets.popup.NLS_zoomTo = "Zoom in op selectie"; var initialExtent = new esri.geometry.Extent({"xmin":157741,"ymin":378600,"xmax":181240,"ymax":394100,"spatialReference":{"wkid":28992}}); //setup the popup window 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([0,255,255]), 2), new dojo.Color([255,255,0,0])) }, dojo.create("div")); map = new esri.Map("map",{ infoWindow:popup, extent: initialExtent, logo: false}); dojo.addClass(map.infoWindow.domNode, "myTheme");//instellen dat de popup "myTheme" gebruikt dojo.connect(map, 'onLoad', mapReady); dojo.connect(map, "onLoad", function() { map.disableDoubleClickZoom(); }); basemap = new esri.layers.ArcGISTiledMapServiceLayer("http://atlas.sre.nl/ArcGIS/rest/services/TOPOGRAFIE/OSM_2011_ZW/MapServer"); map.addLayer(basemap); layer = new esri.layers.ArcGISDynamicMapServiceLayer("http://atlas.sre.nl/ArcGIS/rest/services/REGIO/lijst/MapServer", {opacity:.5}); if (layer.loaded) { buildLayerList(layer); } else { dojo.connect(layer, "onLoad", buildLayerList); } } function buildLayerList(layer) { var items = dojo.map(layer.layerInfos,function(info,index){ if (info.defaultVisibility) { visible.push(info.id); } return "<input type='checkbox' class='list_item' checked='" + (info.defaultVisibility ? "checked" : "") + "' id='" + info.id + "' onclick='updateLayerVisibility();' /><label for='" + info.id + "'>" + info.name + "</label><br>"; }); dojo.byId("layer_list").innerHTML = items.join(""); layer.setVisibleLayers(visible); map.addLayer(layer); } function updateLayerVisibility() { var inputs = dojo.query(".list_item"), input; visible = []; dojo.forEach(inputs,function(input){ if (input.checked) { visible.push(input.id); } }); //if there aren't any layers visible set the array to be -1 if(visible.length === 0){ visible.push(-1); } layer.setVisibleLayers(visible); } function mapReady(map){ dojo.connect(map,"onClick",executeIdentifyTask); //create identify tasks and setup parameters identifyTask = new esri.tasks.IdentifyTask("http://atlas.sre.nl/ArcGIS/rest/services/REGIO/lijst/MapServer"); identifyParams = new esri.tasks.IdentifyParameters(); identifyParams.tolerance = 10; identifyParams.returnGeometry = true; identifyParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_VISIBLE; identifyParams.width = map.width; identifyParams.height = map.height; //resize the map when the browser resizes dojo.connect(dijit.byId('map'), 'resize', map,map.resize); } function executeIdentifyTask(evt) { identifyParams.geometry = evt.mapPoint; identifyParams.mapExtent = map.extent; var deferred = identifyTask.execute(identifyParams); deferred.addCallback(function(response) { // response is an array of identify result objects // Let's return an array of features. return dojo.map(response, function(result) { var feature = result.feature; feature.attributes.layerName = result.layerName; if(result.layerName === 'Archeologie'){ console.log(feature.attributes.PARCELID); var template = new esri.InfoTemplate("", "<p><strong>Monumentnummer:</strong> ${MONUMENTNR}<br><strong>Waarde:</strong> ${WAARDE}<br><strong>Type:</strong> ${COMPLEX}<br><strong>Toponiem:</strong> ${TOPONIEM}<br><strong>Begin periode:</strong> ${BEGIN_PERI}<br><strong>Eind periode:</strong> ${EIND_PERIO}</p><p><strong>Toelichting:</strong><br/>${TOELICHTING}</p>"); feature.setInfoTemplate(template); } else if(result.layerName === 'Monumenten'){ console.log(feature.attributes.PARCELID); var template = new esri.InfoTemplate("", "<p><strong>Monumentstatus:</strong> ${Monumentstatus}<br/><strong>Monumentnummer:</strong> ${Monumentnummer}<br/><strong>Aanduiding:</strong> ${Aanduiding}<br><strong>Adres:</strong> ${Adres}<br><strong>Postcode:</strong> ${Postcode}<br><strong>Gemeente:</strong> ${Gemeente}<br><strong>Bouwjaar:</strong> ${Bouwjaar}<br><strong>Architect:</strong> ${Architect}</p><p><strong><a id=info href=${html} target=${target}>Meer informatie</a></strong></p>"); feature.setInfoTemplate(template); } else if (result.layerName === 'Rijksbeschermd stads/dorps-gezichten'){ var template = new esri.InfoTemplate("", "<p><strong>Monumentstatus:</strong> Rijksbeschemd stads/dorps-gezicht<br/><strong>Naam: </strong>${NAAM}</p><p><strong><a id=info href=${KICHLINK} target=${target}>Meer informatie</a></strong></p>"); feature.setInfoTemplate(template); } return feature; }); }); // InfoWindow expects an array of features from each deferred // object that you pass. If the response from the task execution // above is not an array of features, then you need to add a callback // like the one above to post-process the response and return an // array of features. map.infoWindow.setFeatures([ deferred ]); map.infoWindow.show(evt.mapPoint); } //show map on load dojo.addOnLoad(init); </script> </head> <body class="soria"> <div dojotype="dijit.layout.BorderContainer" design="headline" gutters="false" style="width: 100%; height: 100%; margin: 0;"> <div id="map" dojotype="dijit.layout.ContentPane" region="center"> <div style="position:absolute; top: 5px; text-align: left; right:5px; z-index:50" id="layerlist"> <strong>Kaartlagen:</strong><br> <span id="layer_list" ></span> <br> <span style="font-size:x-small;">Ondergrond: © <a href="http://www.openstreetmap.org" title="OpenStreetMap" target="_blank">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/" title="Creative Commons Attribution-ShareAlike" target="_blank">CC-BY-SA</a></span></div> </div> </div> </body> </html>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=7,IE=9" /> <!--The viewport meta tag is used to improve the presentation and behavior of the samples on iOS devices--> <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/> <title>Rijk van Dommel en Aa</title> <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/2.6/js/dojo/dijit/themes/soria/soria.css"> <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/2.6/js/esri/dijit/css/Popup.css"> <style type="text/css"> html, body { height: 100%; width: 100%; margin: 0; padding: 0; } body{ background-color:#FFF; overflow:hidden; font-family: "Trebuchet MS"; } #map{ overflow:hidden; padding:0; } #layerlist{ background-color: #FFF; padding: 5px; border: solid 1px #769dc0; } a:link { color: #009FB4; text-decoration: none; } a:visited { text-decoration: none; color: #009FB4; } a:hover { text-decoration: underline; color: #009FB4; } a:active { text-decoration: none; color: #009FB4; } #info { color:#F00; } /*Opmaak Popup Window*/ .esriPopup.myTheme .sizer { width: 400px; } .esriPopup.myTheme .titlePane, .dj_ie7 .esriPopup.myTheme .titlePane .title { background-color: #b7dafb; /*Achtergrondkleur titel*/ color:#4a4a4a; /*Textkleur titel*/ font-weight:700; /*dikte letters*/ z-index:100; } .esriPopup.myTheme .titlePane { border:1px solid #769dc0; /*kleur border titel*/ z-index: 100; } .esriPopup.myTheme a { color:#0095aa; /*kleur van de hyperlinks*/ z-index:100; } .esriPopup.myTheme .titleButton, .esriPopup.myTheme .pointer, .esriPopup.myTheme .outerPointer, .esriPopup.myTheme .esriViewPopup .gallery .mediaHandle, .esriPopup.myTheme .esriViewPopup .gallery .mediaIcon { background-image:url(images/popup_sprite.png); /*afbeelding met de opmaak van de popup*/ z-index:100; } .esriPopup.myTheme .contentPane,.esriPopup.myTheme .actionsPane { background-color:#ffffff; /*Achtergrondkleur inhoud*/ color:#000000;/*Tekstkleur inhoud*/ border-left:1px solid #769dc0;/*border links kleur inhoud*/ border-right:1px solid #769dc0;/*border rechts kleur inhoud*/ z-index:100; } /*.esriPopup.myTheme{ border-bottom: 1px solid #769dc0; /*border onder kleur inhoud*/ z-index:100; }*/ </style>
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.