private void Layers_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            MapContentsConfiguration conf = DataContext as MapContentsConfiguration;

            if (conf != null)
            {
                conf.LayerIds   = GetLayerIds(conf.ExcludedLayerIds, conf.HideBasemaps);
                conf.LayerInfos = GetLayerInfos(conf.ExcludedLayerIds);
            }
        }
        void Configuration_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            MapContentsConfiguration conf = sender as MapContentsConfiguration;

            if (conf != null)
            {
                if (e.PropertyName == "ExcludedLayerIds" || e.PropertyName == "HideBasemaps")
                {
                    conf.LayerIds = GetLayerIds(conf.ExcludedLayerIds, conf.HideBasemaps);
                }
                else if (e.PropertyName == "Mode" || e.PropertyName == "ShowLayersVisibleAtScale")
                {
                    if (_legend != null)
                    {
                        _legend.Refresh();
                    }
                }
            }
        }
        void AssociatedObject_Checked(object sender, RoutedEventArgs e)
        {
            LayerInfo layerInfo = AssociatedObject.DataContext as LayerInfo;

            if (layerInfo != null && layerInfo.Layer != null && !string.IsNullOrWhiteSpace(layerInfo.Layer.ID))
            {
                MapContentsConfigControl parentConfigControl = ControlTreeHelper.FindAncestorOfType <MapContentsConfigControl>(AssociatedObject);
                if (parentConfigControl != null)
                {
                    MapContentsConfiguration conf = parentConfigControl.DataContext as MapContentsConfiguration;
                    if (conf != null)
                    {
                        List <string> excludedLayers = conf.ExcludedLayerIds == null ? null : conf.ExcludedLayerIds.ToList <string>();
                        if (AssociatedObject.IsChecked == true)
                        {
                            if (excludedLayers == null)
                            {
                                conf.ExcludedLayerIds = new string[] { layerInfo.Layer.ID };
                            }
                            else if (!excludedLayers.Contains(layerInfo.Layer.ID))
                            {
                                excludedLayers.Add(layerInfo.Layer.ID);
                                conf.ExcludedLayerIds = excludedLayers.ToArray();
                            }
                        }
                        else
                        {
                            if (excludedLayers != null)
                            {
                                excludedLayers.Remove(layerInfo.Layer.ID);
                                conf.ExcludedLayerIds = excludedLayers.ToArray();
                            }
                        }
                    }
                }
            }
        }
 public void LoadConfiguration(string configData)
 {
     Configuration = MapContentsConfiguration.FromString(configData);
 }
Exemple #5
0
        void AssociatedObject_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
        {
            MapContents cont = ControlTreeHelper.FindAncestorOfType <MapContents>(AssociatedObject);

            if (cont == null)
            {
                return;
            }

            MapContentsConfiguration conf = cont.DataContext as MapContentsConfiguration;

            if (conf == null)
            {
                return;
            }

            if (ToolPanels.Current != null && !string.IsNullOrWhiteSpace(conf.ContextMenuToolPanelName))
            {
                _toolPanel = ToolPanels.Current[conf.ContextMenuToolPanelName];
            }

            if (_toolPanel == null)
            {
                return;
            }

            _contextMenu = new ContextMenu();
            if (ContextMenuStyle != null)
            {
                _contextMenu.Style = ContextMenuStyle;
            }

            // Bind background and foreground properties to context menu
            Binding b = new Binding("ContextMenuBackground")
            {
                Source = this
            };

            _contextMenu.SetBinding(ContextMenu.BackgroundProperty, b);

            b = new Binding("ContextMenuForeground")
            {
                Source = this
            };
            _contextMenu.SetBinding(ContextMenu.ForegroundProperty, b);

            // set the control to the current culture settings (LTR/RTL)
            RTLHelper helper = System.Windows.Application.Current.Resources["RTLHelper"] as RTLHelper;

            Debug.Assert(helper != null);
            if (helper != null)
            {
                _contextMenu.FlowDirection = helper.FlowDirection;
            }

            foreach (FrameworkElement button in _toolPanel.ToolPanelItems)
            {
                System.Windows.Controls.Primitives.ButtonBase btnBase = button as System.Windows.Controls.Primitives.ButtonBase;
                if (btnBase != null)
                {
                    MenuItem          item = new MenuItem();
                    ButtonDisplayInfo info = btnBase.DataContext as ButtonDisplayInfo;
                    if (info != null)
                    {
                        item.Header = info.Label;
                        if (!string.IsNullOrEmpty(info.Icon))
                        {
                            Image   image   = new Image();
                            Binding binding = new Binding("Icon")
                            {
                                Converter = _urlResolver
                            };
                            image.SetBinding(Image.SourceProperty, binding);
                            image.DataContext = info;
                            item.Icon         = image;
                        }
                        item.Command = btnBase.Command;
                        _contextMenu.Items.Add(item);
                    }
                }
                else
                {
                    _contextMenu.Items.Add(new Separator());
                }
            }

            Point point = e.GetPosition(null);

            if (point != null)
            {
                _contextMenu.HorizontalOffset = point.X;
                _contextMenu.VerticalOffset   = point.Y;
            }

            LayerItemViewModel layerViewModel = AssociatedObject.DataContext as LayerItemViewModel;

            if (layerViewModel != null && layerViewModel.Layer != null)
            {
                if (!CoreExtensions.GetIsSelected(layerViewModel.Layer))
                {
                    SetSelectedLayer(layerViewModel.Layer);
                }
            }
            if (_contextMenu.Items.Count > 0)
            {
                _contextMenu.IsOpen = true;

                if (_contextMenu.FlowDirection == FlowDirection.RightToLeft)
                {
                    // Now that the popup is open, we can update the layout measurements so that
                    // the ActualWidth is available.
                    _contextMenu.UpdateLayout();
                    _contextMenu.HorizontalOffset -= _contextMenu.ActualWidth;
                }
            }
        }
        private void CorrectLegendImages(LegendItemViewModel model)
        {
            LayerItemViewModel mod = model as LayerItemViewModel;

            if (mod != null)
            {
                MapContentsConfiguration config = AssociatedObject.DataContext as MapContentsConfiguration;
                if (config.Mode == Mode.LayerList)
                {
                    if (mod.LegendItems != null)
                    {
                        mod.LegendItems.Clear();
                    }
                }

                bool isBaseMap = false;
                if (mod.Layer != null)
                {
                    isBaseMap = (bool)mod.Layer.GetValue(ESRI.ArcGIS.Client.WebMap.Document.IsBaseMapProperty);
                }
                if (isBaseMap || config.Mode == Mode.TopLevelLayersOnly)
                {
                    if (mod.LegendItems != null)
                    {
                        mod.LegendItems.Clear();
                    }
                    if (mod.LayerItems != null)
                    {
                        mod.LayerItems.Clear();
                    }

                    //only show map layer level
                    return;
                }

                if (mod.Tag == null)//first time only
                {
                    mod.Tag = config;

                    if (mod.Layer != null)
                    {
                        mod.IsExpanded = config.ExpandLayersOnAdd;
                    }

                    if (mod.LegendItems != null)
                    {
                        foreach (LegendItemViewModel leg in mod.LegendItems)
                        {
                            leg.Tag = config;
                        }
                    }
                }
            }

            if (model.LayerItemsSource != null)
            {
                foreach (LegendItemViewModel subModel in model.LayerItemsSource)
                {
                    CorrectLegendImages(subModel);
                }
            }
        }