private void PropagateTemplate()
 {
     // set the template on all descendants including the legend items
     LayerItems.Descendants(item => item.LayerItems).ForEach(item =>
     {
         item.Template = item.GetTemplate();
         item.LegendItems.ForEach(legendItem => legendItem.Template = legendItem.GetTemplate());
     });
 }
 internal void UpdateLayerVisibilities()
 {
     LayerItems.ForEach(layerItem =>
     {
         layerItem.DeferLayerItemsSourceChanged = true;
         layerItem.UpdateLayerVisibilities(true, true, true);
         layerItem.DeferLayerItemsSourceChanged = false;
     }
                        );
 }
        /// <summary>
        /// Updates recursively the properties IsEnabled, IsVisible, IsInScaleRange and IsInTimeExtent.
        /// </summary>
        /// <param name="isParentVisible">The visibility of the parent.</param>
        /// <param name="isParentInScaleRange">The scale range status of the parent.</param>
        /// <param name="isParentInTimeExtent">The time extent status of the parent.</param>
        internal void UpdateLayerVisibilities(bool isParentVisible, bool isParentInScaleRange, bool isParentInTimeExtent)
        {
            bool isEnabled;

            if (Layer.GetType() != typeof(ArcGISDynamicMapServiceLayer))
            {
                if (Layer != null)
                {
                    isEnabled = Layer.IsVisible;
                }
                else
                {
                    isEnabled = true;
                }

                if (isEnabled != IsEnabled)
                {
                    _isEnabled = isEnabled; // Note : don't set directly the property to avoid an useless call to SetLayerVisibility
                    OnPropertyChanged("IsEnabled");
                }
            }

            double mapScale = (LegendTree != null) ? LegendTree.Scale : double.NaN;

            if (isParentInScaleRange)
            {
                // all ascendants are in scale range ==> Take care of resolution
                if (mapScale > 0.0)
                {
                    IsInScaleRange = double.IsNaN(mapScale) || !(MaximumScale > mapScale || MinimumScale < mapScale);
                }
            }
            else
            {
                // Parent not in scale range ==> layer can't be in scale range
                IsInScaleRange = false;
            }

            // A layer is visible if it's checked on, if all its ascendants are visible, if it's in scale range and if it's in time extent
            bool isVisible = _isEnabled && isParentVisible && IsInScaleRange && IsInTimeExtent;

            // Check if there is no initialization failure and if a tiled layer is using the same spatial reference as the map (bug1419)
            if (isVisible && IsMapLayer && Layer != null)
            {
                if (Layer.InitializationException != null)
                {
                    isVisible = false;
                }
            }

            IsVisible = isVisible;

            // Update properties recursively
            LayerItems.ForEach(layerItem => layerItem.UpdateLayerVisibilities(IsVisible, IsInScaleRange, IsInTimeExtent));
        }
 private void PropagateLayerItemsOptions(LayerItemsOpts layerItemsOptions)
 {
     if (!LayerItemsOptions.Equals(layerItemsOptions))
     {
         DeferLayerItemsSourceChanged = true;
         LayerItemsOptions            = layerItemsOptions;
         // set value on all descendants
         LayerItems.Descendants(layerItem => layerItem.LayerItems).ForEach(layerItem => layerItem.LayerItemsOptions = layerItemsOptions);
         DeferLayerItemsSourceChanged = false;
     }
 }
        internal override void Attach(LegendTree legendTree)
        {
            if (legendTree == null)
            {
                return;
            }

            base.Attach(legendTree);

            LayerItemsOptions = legendTree.LayerItemsOptions;

            LayerItems.ForEach(item => item.Attach(legendTree));
            LegendItems.ForEach(item => item.Attach(legendTree));
        }
        public Dictionary <String, LegendItemDescriptor> GetLayerDescriptors()
        {
            if (LayerItems == null)
            {
                LayerItems = Config.GetUser(User, "MapLegend.LayerDescriptors", new Dictionary <String, LegendItemDescriptor>());
            }

            var found = new List <String>();

            foreach (ILayer layer in MapBox.Map.Layers)
            {
                found.Add(layer.LayerName);
                if (!LayerItems.ContainsKey(layer.LayerName))
                {
                    LayerItems.Add(layer.LayerName, new LegendItemDescriptor {
                        LayerName = layer.LayerName, IsVisible = true, Title = layer.LayerName, TitleColor = Color.Black
                    });
                }
            }

            var killList = new List <String>();

            foreach (String name in LayerItems.Keys)
            {
                if (!found.Contains(name))
                {
                    killList.Add(name);
                }
            }

            foreach (String name in killList)
            {
                LayerItems.Remove(name);
            }

            return(LayerItems);
        }
 /// <summary>
 /// Refreshes the legend control.
 /// </summary>
 /// <remarks>Note : In most cases, the control is always up to date without calling the refresh method.</remarks>
 internal void Refresh()
 {
     // refresh all map layer items (due to group layers we have to go through the legend hierarchy
     LayerItems.Descendants(item => item.LayerItems).OfType <MapLayerItem>().ForEach(mapLayerItem => mapLayerItem.Refresh());
 }
        /// <summary>
        /// Updates recursively the properties IsEnabled, IsVisible, IsInScaleRange and IsInTimeExtent.
        /// </summary>
        /// <param name="isParentVisible">The visibility of the parent.</param>
        /// <param name="isParentInScaleRange">The scale range status of the parent.</param>
        /// <param name="isParentInTimeExtent">The time extent status of the parent.</param>
        internal void UpdateLayerVisibilities(bool isParentVisible, bool isParentInScaleRange, bool isParentInTimeExtent)
        {
            bool isEnabled;

            if (!IsMapLayer && Layer is ISublayerVisibilitySupport)
            {
                isEnabled = (Layer as ISublayerVisibilitySupport).GetLayerVisibility(SubLayerID);
            }
            else if (Layer != null)
            {
                isEnabled = Layer.Visible;
            }
            else
            {
                isEnabled = true;
            }

            if (isEnabled != IsEnabled)
            {
                _isEnabled = isEnabled;                 // Note : don't set directly the property to avoid an useless call to SetLayerVisibility
                OnPropertyChanged("IsEnabled");
            }

            if (isParentInScaleRange)
            {
                // all ascendants are in scale range ==> Take care of resolution
                if (LegendTree != null &&
                    LegendTree.Map != null && LegendTree.Map.Resolution > 0.0)
                {
                    IsInScaleRange = !(MinimumResolution > LegendTree.Map.Resolution || MaximumResolution < LegendTree.Map.Resolution);
                }
            }
            else
            {
                // Parent not in scale range ==> layer can't be in scale range
                IsInScaleRange = false;
            }

            if (isParentInTimeExtent)
            {
                // all ascendants are in time extent ==> Take care of Time extent
                if (LegendTree != null &&
                    LegendTree.Map != null && LegendTree.Map.TimeExtent != null && VisibleTimeExtent != null)
                {
                    IsInTimeExtent = VisibleTimeExtent.Intersects(LegendTree.Map.TimeExtent);
                }
                else
                {
                    IsInTimeExtent = true;
                }
            }
            else
            {
                // Parent not in time extent ==> layer can't be in time extent
                IsInTimeExtent = false;
            }

            // A layer is visible if it's checked on, if all its ascendants are visible, if it's in scale range and if it's in time extent
            bool isVisible = _isEnabled && isParentVisible && IsInScaleRange && IsInTimeExtent;

            // Check if there is no initialization failure and if a tiled layer is using the same spatial reference as the map (bug1419)
            if (isVisible && IsMapLayer && Layer != null)
            {
                if (Layer.InitializationFailure != null)
                {
                    isVisible = false;
                }
                else if (LegendTree != null && LegendTree.Map != null && Layer is TiledLayer)
                {
                    isVisible = SpatialReference.AreEqual(LegendTree.Map.SpatialReference, Layer.SpatialReference, true);
                }
            }

            IsVisible = isVisible;

            // Update properties recursively
            LayerItems.ForEach(layerItem => layerItem.UpdateLayerVisibilities(IsVisible, IsInScaleRange, IsInTimeExtent));
        }
 internal override void Detach()
 {
     LayerItems.ForEach(item => item.Detach());
     LegendItems.ForEach(item => item.Detach());
     base.Detach();
 }