+ Reply to Thread
Results 1 to 24 of 24

Thread: IdentifyParameters.LAYER_OPTION_VISIBLE still gives identify results on all layers

  1. #1
    Swen Waschk
    Join Date
    Nov 2010
    Posts
    24
    Points
    1
    Answers Provided
    0


    0

    Default IdentifyParameters.LAYER_OPTION_VISIBLE still gives identify results on all layers

    I've used both the create layer list and the identify pop-up samples to create the following code (see first reply)


    But if I turn of a layer in the layerlist it still is identified. How do i stop this from happening?

  2. #2
    Swen Waschk
    Join Date
    Nov 2010
    Posts
    24
    Points
    1
    Answers Provided
    0


    0

    Default Re: IdentifyParameters.LAYER_OPTION_VISIBLE still gives identify results on all layer

    Code:
    <!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>

  3. #3
    Swen Waschk
    Join Date
    Nov 2010
    Posts
    24
    Points
    1
    Answers Provided
    0


    1

    Default Re: IdentifyParameters.LAYER_OPTION_VISIBLE still gives identify results on all layer

    part two of the code

    Code:
    <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>

  4. #4
    Shawn Holyoak
    Join Date
    Apr 2010
    Posts
    66
    Points
    4
    Answers Provided
    2


    0

    Exclamation Re: IdentifyParameters.LAYER_OPTION_VISIBLE still gives identify results on all layer

    I also have this issue. I'm using deferreds to identify from multiple services, but even if a particular layer in the service is not visible, it is still identified. My identifyParameters variable is set to
    Code:
    identifyParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_VISIBLE;
    . ESRI, what gives?

  5. #5
    dan becker
    Join Date
    Apr 2010
    Posts
    182
    Points
    21
    Answers Provided
    3


    1

    Default Re: IdentifyParameters.LAYER_OPTION_VISIBLE still gives identify results on all layer

    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):

    Code:
    //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;
    Last edited by dbecker88; 04-20-2012 at 09:00 AM.

  6. #6
    Swen Waschk
    Join Date
    Nov 2010
    Posts
    24
    Points
    1
    Answers Provided
    0


    0

    Default Re: IdentifyParameters.LAYER_OPTION_VISIBLE still gives identify results on all layer

    Quote Originally Posted by dbecker88 View Post
    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):

    Code:
    //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;
    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.

  7. #7
    dan becker
    Join Date
    Apr 2010
    Posts
    182
    Points
    21
    Answers Provided
    3


    0

    Default Re: IdentifyParameters.LAYER_OPTION_VISIBLE still gives identify results on all layer

    Quote Originally Posted by swenwaschk View Post
    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.
    i should have added, my map contains all featureLayers. I then add the layer definition info to a legendLayers array; pretty sure I got this from the visible layers sample.

    Code:
    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"});
    after the click event, you loop over the legendLayers array, checking to see which layers are visible; if visible, add the layerId to the lids array.

    console.log(lids) will tell you what layerId's are currently visible

  8. #8
    Adrian Marsden
    Join Date
    Apr 2010
    Posts
    372
    Points
    22
    Answers Provided
    3


    0

    Default Re: IdentifyParameters.LAYER_OPTION_VISIBLE still gives identify results on all layer

    I had the same issue and resolved it like this.

    I use this function from one of the samples

    Code:
    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);
    
    }
    I then added

    identifyParams.layerIds = visible
    In the relevant place and it all worked!

    I was quite surprised

    ACM

  9. #9
    Swen Waschk
    Join Date
    Nov 2010
    Posts
    24
    Points
    1
    Answers Provided
    0


    0

    Default Re: IdentifyParameters.LAYER_OPTION_VISIBLE still gives identify results on all layer

    Thanks, I'm going to try it and I'll get back to you

  10. #10
    Shuping Li
    Join Date
    May 2010
    Posts
    61
    Points
    26
    Answers Provided
    5


    1
    This post is marked as the answer

    Default Re: IdentifyParameters.LAYER_OPTION_VISIBLE still gives identify results on all layer

    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.

  11. #11
    Swen Waschk
    Join Date
    Nov 2010
    Posts
    24
    Points
    1
    Answers Provided
    0


    0

    Default Re: IdentifyParameters.LAYER_OPTION_VISIBLE still gives identify results on all layer

    Quote Originally Posted by Shuping View Post
    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.
    Could you tell how I do this? My code is still the same as in the first post because I don't seem to be able to find out how to integrate the IdentifyParameters.layerIds

  12. #12
    Adrian Marsden
    Join Date
    Apr 2010
    Posts
    372
    Points
    22
    Answers Provided
    3


    1

    Default Re: IdentifyParameters.LAYER_OPTION_VISIBLE still gives identify results on all layer

    It looks like you should be able just to add

    Code:
    identifyParams.layerIds = visible
    to

    Code:
       function executeIdentifyTask(evt) { 
            identifyParams.geometry = evt.mapPoint; 
            identifyParams.mapExtent = map.extent;
    to give you

    Code:
       function executeIdentifyTask(evt) { 
            identifyParams.geometry = evt.mapPoint; 
            identifyParams.mapExtent = map.extent;
    identifyParams.layerIds = visible
    Should work

  13. #13
    Swen Waschk
    Join Date
    Nov 2010
    Posts
    24
    Points
    1
    Answers Provided
    0


    0

    Default Re: IdentifyParameters.LAYER_OPTION_VISIBLE still gives identify results on all layer

    Quote Originally Posted by amarsden View Post
    It looks like you should be able just to add

    Code:
    identifyParams.layerIds = visible
    to

    Code:
       function executeIdentifyTask(evt) { 
            identifyParams.geometry = evt.mapPoint; 
            identifyParams.mapExtent = map.extent;
    to give you

    Code:
       function executeIdentifyTask(evt) { 
            identifyParams.geometry = evt.mapPoint; 
            identifyParams.mapExtent = map.extent;
    identifyParams.layerIds = visible
    Should work
    Thanks! It works!

  14. #14
    Adrian Marsden
    Join Date
    Apr 2010
    Posts
    372
    Points
    22
    Answers Provided
    3


    0

    Default Re: IdentifyParameters.LAYER_OPTION_VISIBLE still gives identify results on all layer

    An alternative I posted here

    http://forums.arcgis.com/threads/68803-BUG-.visibleLayers-returns-group-layeys?p=240650#post240650

    B
    asically I had moved away from the check boxes I had in my earlier post. Initially I tried "identifyParams.layerIds = dynamicMapServiceLayer.visibleLayers;" but that fails when you have group layyers - see post.

    So the function I now use is a simple check for layers and groups one

    Code:
    function getVisibleLayers() {    var visibleLayers = [];
        var items = dojo.map(dynamicMapServiceLayer.layerInfos, function (info, index) {
            layerID = info.id;
            if (info.visible && !info.subLayerIds) {
                visibleLayers.push(layerID)
            }
        }); return visibleLayers
    
    }


    Call in you id task code with

    Code:
          v = getVisibleLayers();
            identifyParams.layerIds = v;
    
    


    BTW, can anyone else (none esri staff) get the link to the bug report from
    Shuping Li to work?


    ACM

  15. #15
    # Rich #
    Join Date
    Apr 2010
    Posts
    358
    Points
    184
    Answers Provided
    31


    1

    Default Re: IdentifyParameters.LAYER_OPTION_VISIBLE still gives identify results on all layer

    Quote Originally Posted by amarsden View Post
    BTW, can anyone else (none esri staff) get the link to the bug report from [/FONT][/COLOR]Shuping Li to work?
    ACM
    FWIW, just search Nimbus using the report number and you'll get to:

    http://support.esri.com/en/bugs/nimbus/TklNMDQyNDQx

  16. #16
    Adrian Marsden
    Join Date
    Apr 2010
    Posts
    372
    Points
    22
    Answers Provided
    3


    0

    Default Re: IdentifyParameters.LAYER_OPTION_VISIBLE still gives identify results on all layer

    Many thanks - so reported over 3 years ago!! So, I don't think I'll hold my breath for a fix anytime soon.

  17. #17
    K M
    Join Date
    Feb 2011
    Posts
    100
    Points
    8
    Answers Provided
    0


    0

    Default Re: IdentifyParameters.LAYER_OPTION_VISIBLE still gives identify results on all layer

    Quote Originally Posted by amarsden View Post
    Many thanks - so reported over 3 years ago!! So, I don't think I'll hold my breath for a fix anytime soon.
    Anyone know if this is fixed in 3.6? (I am on lower API for a while longer). Or if ESRI can comment whether it will be fixed? NIM is still open.

    My suggestion would be for ESRI to include a sample that is an Identify widget that identifies all visible layers and works well with AGS JS TOC with dynamic layers with many cascading groups with hundreds of layers, as well as consider including AGS JS TOC in the API itself.

  18. #18
    Nianwei Liu
    Join Date
    Jul 2010
    Posts
    87
    Points
    58
    Answers Provided
    8


    0

    Default Re: IdentifyParameters.LAYER_OPTION_VISIBLE still gives identify results on all layer

    Quote Originally Posted by kmacleod View Post
    NIM is still open.
    In REST API, "visible" means default visibility defined in map service, not in the client map instance. The JS API design separated task from Map/service, as a result, the task has no knowledge of which layer is actually visible -- because it does not hold a reference to the map/service instance.

    Given the circumstance, it is much easier for the application code, which holds reference to both service and task, to passing the actual visible ID list into IdentifyParameter and use IDENITIFY_ALL.

    To fix the "bug", the identify task class has to accept the map service layer in the constructor, which would be a bit awkward coding neatness wise, and I see no incentive to fix that from Esri perspective, so my advise is that do not count on it, use the alternative and move on.
    Last edited by nliu; 09-04-2013 at 10:55 AM.

  19. #19
    Adrian Marsden
    Join Date
    Apr 2010
    Posts
    372
    Points
    22
    Answers Provided
    3


    0

    Default Re: IdentifyParameters.LAYER_OPTION_VISIBLE still gives identify results on all layer

    :-) Now why didn't anyone at Esri state the above - so, in Microsoft term, "This behaviour is by design"

    The "bug" should remain through, but be changed to say "make the documentation clear"

  20. #20
    Nicholas Gross
    Join Date
    Feb 2012
    Posts
    28
    Points
    2
    Answers Provided
    0


    0

    Question Re: IdentifyParameters.LAYER_OPTION_VISIBLE still gives identify results on all layer

    I've just run into this bug/design feature/whatever it is. I can't seem to figure a way around it. I have a popup window displaying the results of multiple identify tasks on multiple dynamic map service layers, each with sublayers. The layerId property of the IdentifyParameters seems to only acknowledge the ids of the sublayers, not the parent dynamic service.

    So, if I have two services, one of which is currently visible and the other not, and I want this reflected in the identify results by only displaying attributes of the visible service, there doesn't seem to be any way to tell the identify parameters to ignore the hidden parent service because the layerId property is only paying attention to the sublayers. If I assign the layerId property "0", it's seeing it as sublayer 0 (not parent layer 0), and of course, every dynamic service has a sublayer 0, so sublayer 0 will be displayed from both services.

    Does anyone know a good way around this?

  21. #21
    K M
    Join Date
    Feb 2011
    Posts
    100
    Points
    8
    Answers Provided
    0


    0

    Default Re: IdentifyParameters.LAYER_OPTION_VISIBLE still gives identify results on all layer

    nicholas if I understand you correctly, I want the same thing. I suspect most developers and end users do. We want an "Identify" like in ArcMap.

    What I need is to Identify on multiple dynamic layers, and identifies on only visible layers, and display all results with page-through, with those little arrows at the top of the infowindow, or another way if that is not supported. And work with scale-dependent layers as well. It should know visibility based on Nianwei's AGS JS TOC toggling control.

    Does anyone have a working example of this, such as a Fiddle, etc?

    Something perhaps that combines the efforts of these two Fiddles:

    http://jsfiddle.net/kenbuja/nvNQw/ (works with AGS JS TOC but only one layer)

    http://jsfiddle.net/blordcastillo/mULcz/ (multiple dynamic layers)

    It looks like perhaps Tracy created something like this in this thread http://forums.arcgis.com/threads/938...entify+visible

    A solution for scale dependency was apparently proposed in this thread: http://forums.arcgis.com/threads/688...of-Scale-Range

    This would probably be a good widget for ESRI to provide as an official Sample as well. It would be popular.

  22. #22
    Tracy Schloss
    Join Date
    Apr 2010
    Posts
    437
    Points
    58
    Answers Provided
    35


    1

    Default Re: IdentifyParameters.LAYER_OPTION_VISIBLE still gives identify results on all layer

    Yes, you can't tell from my thread, by I was able to get my identify to work the way I wanted. One of the gotchas I learned from another thread was that I needed to dynamically create my identifyParameters based on the current visibility. It's not enough to have them defined at the beginning. Once you introduce a TOC into the mix, the visibility isn't fixed.

    I have this set on a map click event
    Code:
    app.map.on("click", runIdentifies);
    These are my identify functions.
    Code:
    // 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[i].length;
            var lyrResult = idResults[i];
            for (j = 0; j < lyrResultLen; j++) {
              var featRes = lyrResult[j];
              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);
            }      
    }
    I have this other set of functions that allows me to pick and choose which output fields I want to display in the infoTemplate. It's the only 'project specific' bit of code that I have to edit.

    First you need to define an array of attributes per each layer.
    Code:
            var legisDistAtt = ['OBJECTID','District'];
            var prevDistAtt = ['OBJECTID','ID'];
            var countyAtt = ['OBJECTID', 'COUNTYNAME'];
    Then you want to create a infoTemplate and use a function to set its content:
    Code:
    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;
    }
    I throw these last functions in because they're called in the identify results handler to set up the feature's infoTemplate.
    Tracy Schloss
    Missouri Information Technology Services
    Office of Geospatial Information

  23. #23
    Nicholas Gross
    Join Date
    Feb 2012
    Posts
    28
    Points
    2
    Answers Provided
    0


    0

    Default Re: IdentifyParameters.LAYER_OPTION_VISIBLE still gives identify results on all layer

    Tracy, do you know whether the code you posted will work for multiple dynamic map services?

    The problem I'm having (or that I think I'm having) is that with multiple dynamic services, I have multiple sublayers with the same id. So, let's say I have two dynamic services, parentA and parentB. And both parentA and parentB have three sublayers each. The API automatically assigns ids to these sublayers; each set gets id 0-2. So now I have two sublayers at id 0, two at 1, and two at 2.

    When I assign ids to the layerId property on the IdentifyParameter object, it seems to completely ignore the parent ids and only pay attention to the sublayers. So if I assign layerId to parentA, it ignores that and assigns to sublayer 0. The bigger problem is that, because I'm not giving it the actual layer object, but rather a simple integer (or array of integers), it can't distinguish between sublayer 0 on parentA and sublayer 0 on parentB. It identifies both even though I only want one to be visible.

    When trying to identify only visible layers from multiple dynamic map services, due to the grouping of sublayers beneath a parent, I can't find any way around the bugged layerOption property or the limitations of the layerId property.

  24. #24
    Tracy Schloss
    Join Date
    Apr 2010
    Posts
    437
    Points
    58
    Answers Provided
    35


    1

    Default Re: IdentifyParameters.LAYER_OPTION_VISIBLE still gives identify results on all layer

    Nearly all my services have multiple layers within them. You aren't referring to group layers are you? It gets hard to have a discussion when we're using such generic terms as layer. It doesn't matter what the layers are called within the service, or if you have the same layer name in two different services. You aren't using these names when you set up your identify.

    What you are using in Identify is the unique ID you should be assigning to each layer as you load it into your map. When you add a layer,you should always give it an id. I give the same id as the variable, just to keep it straight in my head.
    Code:
        educationLayer = new ArcGISDynamicMapServiceLayer(pathName+"/ArcGIS/rest/services/BaseMap/Education/MapServer", {id:'educationLayer', visible:false})
    When you start up the runIdentifies function, the first thing it does is look at the current layers you have loaded. It's going to create an array of all the layers. This isn't a list of the names as they are called in the service directory.
    Code:
     var layers = arrayUtils.map(app.map.layerIds, function(layerId) {
            return app.map.getLayer(layerId);
        });
    When you define your identifyParameters, you don't care about the names of the layers here either. I have this set up to generate a new identifyTask and corresponding identifyParameters each time you click. Since the identifyParameters are created on-the-fly, you have the chance to specify which layers you want to identify. You need this extra parameter of layerIds, setting IdentifyParameters.LAYER_OPTION_VISIBLE isn't going to be enough.

    Code:
            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 = [];
            }
    When defining visLayers, it's returning the array of numbers, something like [0,2] or whatever you have currently turned on. Again, it doesn't matter what something is called in the service.
    Tracy Schloss
    Missouri Information Technology Services
    Office of Geospatial Information

+ Reply to Thread

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts