Select to view content in your preferred language

Popup for visible layers only?

1787
6
Jump to solution
05-21-2012 06:38 AM
KarenEllett
Regular Contributor
Is there a way to constrain the popup behavior to only layers that are currently checked as visible?  Right now, with on-click popup, even layers that are turned off show up in the results.
0 Kudos
1 Solution

Accepted Solutions
KatherineDalton
Esri Regular Contributor
Hi Karen,

We've verified that this is a bug: Pop-ups display when a sub-layer is unchecked. If the parent map service layer is unchecked, then popups do not appear for any layers within the service.

Katy
Katy Dalton | Technical Consultant
THE SCIENCE OF WHERE™

View solution in original post

0 Kudos
6 Replies
KarenEllett
Regular Contributor
Does anyone have any knowledge or guidance on this?  I've looked everywhere I can think to look, but I can't figure out if this is customizeable or not.
0 Kudos
KatherineDalton
Esri Regular Contributor
Hi Karen,

We've verified that this is a bug: Pop-ups display when a sub-layer is unchecked. If the parent map service layer is unchecked, then popups do not appear for any layers within the service.

Katy
Katy Dalton | Technical Consultant
THE SCIENCE OF WHERE™
0 Kudos
KarenEllett
Regular Contributor
Thanks!  I know you can't give any solid answers yet, but do you think this is a bug that will be fixed with the next release?
0 Kudos
KatherineDalton
Esri Regular Contributor
Yes, unfortunately I don't know at this time, but it's definitely in our bug queue.

Katy
Katy Dalton | Technical Consultant
THE SCIENCE OF WHERE™
0 Kudos
JeffMcConnell
Occasional Contributor
I've created a work around for this issue, I simply reset the value of the IdentifyLayerIds collection when the layer visibility changes. As the Identify behavior only returns results from visible layers, it does require that the web services have all of their sub-layers turned on by default in order work properly.  Layer/Sub-layer visibility should to be set in the viewer configuration.

using System;
using System.ComponentModel.Composition;
using System.Windows.Interactivity;
using ESRI.ArcGIS.Client;
using ESRI.ArcGIS.Client.Extensibility;

namespace IndentifyFix.AddIns
{
    [Export(typeof(Behavior<Map>))]
    [DisplayName("IdentifyFix")]
    [ESRI.ArcGIS.Client.Extensibility.Category("TEP Tools")]
    [ESRI.ArcGIS.Client.Extensibility.Description("Fix the identify tool so that it only hits the visible layers")]
    public class IdentifyVisible : Behavior<Map>
    {
        #region Behavior Overrides
        protected override void OnAttached()
        {
            base.OnAttached();
            MapApplication.Current.Initialized += new EventHandler(Current_Initialized);
            MapApplication.Current.Map.Layers.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(Layers_CollectionChanged);
        }

        #endregion

        void Current_Initialized(object sender, EventArgs e)
        {
            AddEventHandlers();
            MapApplication.Current.Initialized -= new EventHandler(Current_Initialized);
        }

        private void AddEventHandlers()
        {
            foreach (Layer layer in MapApplication.Current.Map.Layers)
            {
                if ((layer as ArcGISDynamicMapServiceLayer) != null)
                {
                    ArcGISDynamicMapServiceLayer agsDynamicLayer = (layer as ArcGISDynamicMapServiceLayer);
                    agsDynamicLayer.VisibilityChanged += new EventHandler<EventArgs>(ArcGISDynamicMapServiceLayer_VisibilityChanged);
                    UpdateIndentify(agsDynamicLayer);
                }
            }
        }

        private void Layers_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
            {
                foreach (var item in e.NewItems)
                {
                    if (item is ArcGISDynamicMapServiceLayer)
                    {
                        ArcGISDynamicMapServiceLayer agsDynamicLayer = (item as ArcGISDynamicMapServiceLayer);
                        agsDynamicLayer.VisibilityChanged += new EventHandler<EventArgs>(ArcGISDynamicMapServiceLayer_VisibilityChanged);
                        UpdateIndentify(agsDynamicLayer);
                        agsDynamicLayer.VisibilityChanged += new EventHandler<EventArgs>(ArcGISDynamicMapServiceLayer_VisibilityChanged);
                    }
                }
            }
            if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Remove)
            {
                foreach (var item in e.OldItems)
                {
                    if (item is ArcGISDynamicMapServiceLayer)
                    {
                        (item as ArcGISDynamicMapServiceLayer).VisibilityChanged -= new EventHandler<EventArgs>(ArcGISDynamicMapServiceLayer_VisibilityChanged);
                    }
                }
            }
        }

        void ArcGISDynamicMapServiceLayer_VisibilityChanged(object sender, EventArgs e)
        {
            ArcGISDynamicMapServiceLayer agsDynamicLayer = sender as ArcGISDynamicMapServiceLayer;
            UpdateIndentify(agsDynamicLayer);
        }

        private static void UpdateIndentify(ArcGISDynamicMapServiceLayer agsDynamicLayer)
        {
            if (agsDynamicLayer != null)
            {
                System.Collections.ObjectModel.Collection<int> visibleLayers = new System.Collections.ObjectModel.Collection<int>();
                if (agsDynamicLayer.VisibleLayers != null)
                {
                    foreach (var i in agsDynamicLayer.VisibleLayers)
                    {
                        visibleLayers.Add(i);
                    }
                }
                else
                {
                    foreach (var li in agsDynamicLayer.Layers)
                    {
                        if (li.DefaultVisibility == true)
                            visibleLayers.Add(li.ID);
                    }
                }
                ESRI.ArcGIS.Mapping.Core.LayerExtensions.SetIdentifyLayerIds(agsDynamicLayer as Layer, visibleLayers);
            }
        }
    }
}



ps You will need to add a reference to ESRI.ArcGIS.Mapping.Core which can be found in Viewer.xap

Thanks,
Jeff
0 Kudos
ElisabethvanderLeeuw
Emerging Contributor
Jeff,

This is great!  Especially for a Viewer which contains a lot of layers with subgroups.

thanks,

Elisabeth
0 Kudos