Collection <int> getIdentifyLayerIds(Layer layer)
        {
            if (!(layer is ArcGISDynamicMapServiceLayer) && !(layer is ArcGISTiledMapServiceLayer))
            {
                throw new ArgumentException(Strings.LayerTypeError);
            }

            // Get layer as dynamic to access GetLayerVisibility without type-casting
            dynamic dynLayer = layer as dynamic;

            IDictionary <int, string> templates = LayerProperties.GetPopupDataTemplates(layer);

            if (templates == null && ESRI.ArcGIS.Mapping.Core.LayerExtensions.GetUsePopupFromWebMap(layer))
            {
                templates = ESRI.ArcGIS.Mapping.Core.LayerExtensions.GetWebMapPopupDataTemplates(layer);
            }

            Collection <int> ids = new Collection <int>();

            if (templates != null) // web map pop-ups are being used.  Base inclusion on whether sub-layer is visible.
            {
                foreach (var item in templates)
                {
                    if (!string.IsNullOrEmpty(item.Value) && dynLayer.GetLayerVisibility(item.Key))
                    {
                        ids.Add(item.Key);
                    }
                }
            }
            else
            {
                // Get sub-layers for which pop-ups have been enabled
                Collection <int> enabledIDs = ESRI.ArcGIS.Mapping.Core.LayerExtensions.GetIdentifyLayerIds(layer);

                // Filter sub-layers based on visibility
                foreach (int id in enabledIDs)
                {
                    // Check whether sub-layer and parent layers are visible
                    if (dynLayer.GetLayerVisibility(id) && parentLayersVisible(layer, id))
                    {
                        ids.Add(id);
                    }
                }
            }

            return(ids);
        }