private void SetTreeViewItemVisibility() { if (ShowLayersVisibleAtScale) { bool isNodeVisible = IsInScaleRange == true; if (isNodeVisible) { LayerItemViewModel mod = this.DataContext as LayerItemViewModel; if (mod != null && mod.LayerItems != null) { LayerItemViewModel child = mod.LayerItems.FirstOrDefault(lm => lm.IsInScaleRange); if (child == null) { isNodeVisible = false; } } } //hide the node if not visible at current extent TreeViewItem item = ControlTreeHelper.FindAncestorOfType <TreeViewItem>(this); if (item != null) { item.Visibility = isNodeVisible ? Visibility.Visible : Visibility.Collapsed; if (item.Visibility == Visibility.Visible) { EnsureAncestorsVisible(item); } } } }
private void AssociatedObject_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (!doubleClick) //single click { timer.Start(); doubleClick = true; //mark as doubleclick until timer ellapses if (this.AssociatedObject != null) { LayerItemViewModel layerViewModel = AssociatedObject.DataContext as LayerItemViewModel; if (layerViewModel != null) { if ((MapApplication.Current != null && !MapApplication.Current.IsEditMode) || layerViewModel.Layer == null || (layerViewModel.Layer != null && LayerExtensions.GetInitialUpdateFailed(layerViewModel.Layer))) { return; } isSelected = MapApplication.Current != null ? MapApplication.Current.SelectedLayer == layerViewModel.Layer : false;//has already been selected programmatically (non-user selection) if (layerViewModel.Layer != null) { lazyClick = isSelected; //if user selects between multiple layers on map contents, reset lazyclick } } } } else //double click { lazyClick = false; } }
private void Legend_Refreshed(object sender, Legend.RefreshedEventArgs e) { LayerItemViewModel removeLayerItemVM = null; // If a map layer has sublayers, iterate through them. if (e.LayerItem.LayerItems != null) { // Iterate through all the sublayer items. foreach (LayerItemViewModel layerItemVM in e.LayerItem.LayerItems) { // Collapse all sublayers in the legend. if (layerItemVM.IsExpanded) { layerItemVM.IsExpanded = false; } // Remove the sublayer named "states" from the legend. The layer remains visible in the map. if (layerItemVM.Label == "states") { removeLayerItemVM = layerItemVM; } } if (removeLayerItemVM != null) { e.LayerItem.LayerItems.Remove(removeLayerItemVM); } } else { // Collapse all map layers in the legend. e.LayerItem.IsExpanded = false; } }
void AssociatedObject_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (!IsEnabled) { return; } if (AssociatedObject == null) { return; } if (MapApplication.Current == null || MapApplication.Current.Map == null || MapApplication.Current.Map.Layers == null) { return; } LayerItemViewModel layerVM = AssociatedObject.DataContext as LayerItemViewModel; if (layerVM == null || layerVM.Layer == null) { return; } MapApplication.Current.SelectedLayer = layerVM.Layer; }
private void Legend_Refreshed(object sender, Legend.RefreshedEventArgs e) { LayerItemViewModel removeLayerItemVM = null; if (e.LayerItem.LayerItems != null) { foreach (LayerItemViewModel layerItemVM in e.LayerItem.LayerItems) { if (layerItemVM.IsExpanded) { layerItemVM.IsExpanded = false; } if (layerItemVM.Label == "states") { removeLayerItemVM = layerItemVM; } } if (removeLayerItemVM != null) { e.LayerItem.LayerItems.Remove(removeLayerItemVM); } } else { e.LayerItem.IsExpanded = false; } }
override void OnApplyTemplate() { base.OnApplyTemplate(); if (!_isLoaded) { _isLoaded = true; if (CompatUtility.IsDesignMode && (Layers == null || !Layers.Any())) { if (_legendTree.LayerItems == null) { // Create a basic hierarchy for design : Map Layer -> SubLayer -> LegendItemViewModel var legendItem1 = new LegendItemViewModel { Label = "LegendItem1", Symbol = new SimpleMarkerSymbol { Style = SimpleMarkerStyle.Circle, Color = Colors.Red } }; var legendItem2 = new LegendItemViewModel { Label = "LegendItem2", Symbol = new SimpleMarkerSymbol { Style = SimpleMarkerStyle.Diamond, Color = Colors.Green } }; var layerItem = new LayerItemViewModel { Label = "LayerItem", LegendItems = new ObservableCollection <LegendItemViewModel> { legendItem1, legendItem2 } }; var mapLayerItem = new LayerItemViewModel { Label = "MapLayerItem", LayerType = MapLayerItem.MapLayerType, LayerItems = new ObservableCollection <LayerItemViewModel> { layerItem }, }; _legendTree.LayerItems = new ObservableCollection <LayerItemViewModel> { mapLayerItem }; } } else { // Initialize the Map now that all parameters are well known _legendTree.Layers = Layers; } } }
void AssociatedObject_LostFocus(object sender, RoutedEventArgs e) { StackPanel sp = AssociatedObject.Parent as StackPanel; if (sp == null) { return; } LayerItemViewModel model = sp.DataContext as LayerItemViewModel; if (model == null || model.Layer == null || (model != null && model.Layer != null && LayerExtensions.GetInitialUpdateFailed(model.Layer))) { return; } model.Layer.SetValue(MapApplication.LayerNameProperty, AssociatedObject.Text); sp.SetValue(CoreExtensions.IsEditProperty, false); }
internal void EnableRenameForLayer(Layer layer) { if (!Configuration.AllowLayerSelection) { return; } if (layer == null) { return; } if (_legend != null) { try { List <TreeViewItemExtended> treeViewItems = ControlTreeHelper.FindChildrenOfType <TreeViewItemExtended>(_legend, 1); if (treeViewItems != null) { foreach (TreeViewItemExtended item in treeViewItems) { LayerItemViewModel model = item.DataContext as LayerItemViewModel; if (model != null && layer == model.Layer) { StackPanel panel = ControlTreeHelper.FindChildOfType <StackPanel>(item, 6); if (panel != null && panel.Name == "layerStackPanel") { panel.SetValue(CoreExtensions.IsEditProperty, true); } return; } } } } catch { } } }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { object name = null; LayerItemViewModel layerModel = value as LayerItemViewModel; if (layerModel != null) { if (layerModel.Layer != null && MapContentsControlHelper.IsTopMostLayerType(layerModel.LayerType)) { string layerName = layerModel.Layer.GetValue(MapApplication.LayerNameProperty) as string; if (string.IsNullOrWhiteSpace(layerName)) { layerName = layerModel.Label; if (string.IsNullOrWhiteSpace(layerName)) { layerName = layerModel.Layer.ID; } } name = layerName; } else { name = layerModel.Label; } } else { LegendItemViewModel legendModel = value as LegendItemViewModel; if (legendModel != null) { name = legendModel.Label; } } return(name); }
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; } } }
internal RefreshedEventArgs(LayerItemViewModel layerItem, Exception ex) { LayerItem = layerItem; Error = ex; }
private void CorrectRendererNodes(LegendItemViewModel model) { LayerItemViewModel mod = model as LayerItemViewModel; if (mod != null) { if (MapContentsControlHelper.IsTopMostLayerType(mod.LayerType)) { GraphicsLayer lay = mod.Layer as GraphicsLayer; if (lay == null) { return; } ClassBreaksRenderer classBreaksrenderer = lay.Renderer as ClassBreaksRenderer; if (classBreaksrenderer != null) { if (mod.LegendItems != null && mod.LegendItems.Count > 0 && string.IsNullOrWhiteSpace(mod.LegendItems[0].Label)) { mod.LegendItems[0].Label = Resources.Strings.DefaultLegentItemViewModelLabel; } } else { UniqueValueRenderer uniqueRenderer = lay.Renderer as UniqueValueRenderer; if (uniqueRenderer != null && string.IsNullOrWhiteSpace(uniqueRenderer.DefaultLabel)) { uniqueRenderer.DefaultLabel = Resources.Strings.DefaultLegentItemViewModelLabel; } } //TODO: //TODO: This code adds a new node for the renderer attribute field, but currently there is no //TODO: way for us to set a different template as LayerItemViewModel.Template is read-only. //TODO //string attribute = null; //ClassBreaksRenderer classBreaksrenderer = lay.Renderer as ClassBreaksRenderer; //if (classBreaksrenderer != null) //{ // attribute = classBreaksrenderer.Attribute; //} //else //{ // UniqueValueRenderer uniqueRenderer = lay.Renderer as UniqueValueRenderer; // if (uniqueRenderer != null) // attribute = uniqueRenderer.Attribute; //} //if (renModel.LegendItems != null && renModel.LegendItems.Count > 0) //{ // if (string.IsNullOrWhiteSpace(renModel.LegendItems[0].Label)) // renModel.LegendItems[0].Label = Resources.Strings.DefaultLegentItemViewModelLabel; //} //if (string.IsNullOrWhiteSpace(attribute)) // return; //LayerItemViewModel renModel = new LayerItemViewModel(mod.Layer); //renModel.Label = attribute; //renModel.LayerItems = mod.LayerItems; //renModel.LegendItems = mod.LegendItems; //renModel.Tag = AssociatedObject.DataContext; //renModel.LayerType = "Renderer Layer"; //mod.LayerItems = null; //mod.LegendItems = null; //mod.LayerItems = new System.Collections.ObjectModel.ObservableCollection<LayerItemViewModel>(); //mod.LayerItems.Add(renModel); } } }
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); } } }