/// <summary> /// Zoom map to a feature layer's extent. If its SR is different than the base map's, re-project the extent /// </summary> private void MenuItemZoomTo_Click(object sender, MenuItemClickEventArgs e) { HideConextMenu(); if (e.ItemTag is LivingMapLayer) { LivingMapLayer mapConfig = e.ItemTag as LivingMapLayer; Envelope extent = this.MapControl.Layers[mapConfig.ID].FullExtent; if (!SpatialReference.AreEqual(extent.SpatialReference, this.MapControl.SpatialReference, false)) { GeometryTool.ProjectEnvelope(this.AppConfig.GeometryService, extent, this.MapSRWKID, (s, g) => { if (g.ProjectedGeometry != null) { this.MapControl.ZoomTo(g.ProjectedGeometry); } }); } else { this.MapControl.ZoomTo(extent); } } else if (e.ItemTag is TOCNodeInfo) { TOCNodeInfo nodeInfo = e.ItemTag as TOCNodeInfo; if (nodeInfo.LayerExtent == null) { this.IsBusy = true; Layer layer = this.MapControl.Layers[nodeInfo.MapID]; string layerUrl = (nodeInfo.IsTiledMap) ? (layer as ArcGISTiledMapServiceLayer).Url : (layer as ArcGISDynamicMapServiceLayer).Url; ArcGISLayerInfoReader layerInfoReader = new ArcGISLayerInfoReader(layerUrl + "/" + nodeInfo.LayerID); layerInfoReader.InfoReady += (obj, arg) => { if (!SpatialReference.AreEqual(arg.LayerInfo.Extent.SpatialReference, this.MapControl.SpatialReference, false)) { GeometryTool.ProjectEnvelope(this.AppConfig.GeometryService, arg.LayerInfo.Extent, this.MapSRWKID, (s, g) => { this.IsBusy = false; if (g.ProjectedGeometry != null) { nodeInfo.LayerExtent = g.ProjectedGeometry as Envelope; this.MapControl.ZoomTo(nodeInfo.LayerExtent); } }); } else { this.IsBusy = false; nodeInfo.LayerExtent = nodeInfo.LayerExtent = arg.LayerInfo.Extent; this.MapControl.ZoomTo(nodeInfo.LayerExtent); } }; } else { this.MapControl.ZoomTo(nodeInfo.LayerExtent); } } }
/// <summary> /// Layer Node Right Click Event Handler - Show Context Menu /// </summary> private void LayerNode_RightClick(object sender, MouseButtonEventArgs e) { this.Focus(); e.Handled = true; Point p = e.GetPosition(this.ContentContainer); ContextMenuBlock.Visibility = System.Windows.Visibility.Visible; ContextMenuBlock.Margin = new Thickness(p.X - 4 + this.ScrollHorizontalOffset, p.Y - 4 + this.ScrollVerticalOffset, 0, 0); TreeViewItem nodeTreeItem = (sender is TreeViewItem) ? (sender as TreeViewItem) : (sender as Control).Tag as TreeViewItem; MenuItemZoomTo.Tag = nodeTreeItem.Tag; bool isGroupNode = false; if (nodeTreeItem.Tag is LivingMapLayer) { LivingMapLayer mapConfig = nodeTreeItem.Tag as LivingMapLayer; isGroupNode = mapConfig.ServiceType == ArcGISServiceType.Dynamic && !mapConfig.ToggleLayer; } else if (nodeTreeItem.Tag is TOCNodeInfo) { isGroupNode = (nodeTreeItem.Tag as TOCNodeInfo).IsGroupLayer; } if (isGroupNode) { MenuItemShowAll.Tag = nodeTreeItem; MenuItemShowNon.Tag = nodeTreeItem; } MenuItemShowAll.IsEnabled = isGroupNode; MenuItemShowNon.IsEnabled = isGroupNode; }
/// <summary> /// Create a Node for ArcGIS Map Service Layer (Living Maps in the configuration) /// </summary> private TreeViewItem CreateMapLayerNode(LivingMapLayer mapConfig) { TreeViewItem tvItem = new TreeViewItem(); tvItem.Tag = mapConfig; CheckBox checkBox = new CheckBox() { Tag = tvItem, IsChecked = mapConfig.VisibleInitial }; checkBox.MouseRightButtonDown += new MouseButtonEventHandler(LayerNode_RightClick); checkBox.Click += new RoutedEventHandler(OnToggleMapLayer); if (mapConfig.OpacityBar) { StackPanel headPanel = new StackPanel() { Orientation = Orientation.Vertical, Margin = new Thickness(0, 0, 0, -20) }; headPanel.Children.Add(new TextBlock() { Text = mapConfig.Title }); Slider opacitySlider = new Slider() { Tag = mapConfig.ID, Value = mapConfig.Opacity, Minimum = 0.0, Maximum = 1.0, Width = 100 }; opacitySlider.ValueChanged += new RoutedPropertyChangedEventHandler <double>(OpacitySlider_ValueChanged); opacitySlider.HorizontalAlignment = HorizontalAlignment.Left; opacitySlider.Orientation = Orientation.Horizontal; ToolTipService.SetToolTip(opacitySlider, "Opacity"); opacitySlider.Margin = new Thickness(0, 2, 0, 0); headPanel.Children.Add(opacitySlider); checkBox.Content = headPanel; tvItem.ItemContainerStyle = this.Resources["TreeViewItemsContainerStyle"] as Style; tvItem.Margin = new Thickness(0, 0, 0, 24); tvItem.Header = checkBox; } else { checkBox.Content = mapConfig.Title; tvItem.Margin = new Thickness(0, 0, 0, 4); tvItem.Header = checkBox; } return(tvItem); }
private LivingMapLayer GetLivingMapConfig(string name) { LivingMapLayer layerConfig = null; foreach (LivingMapLayer layer in AppConfig.MapConfig.LivingMaps) { if (name.Equals(layer.Title, StringComparison.CurrentCultureIgnoreCase)) { layerConfig = layer; break; } } return(layerConfig); }
/// <summary> /// Toggle the visibility of an ArcGIS Map Service Layer (Living Maps) /// </summary> private void OnToggleMapLayer(object sender, RoutedEventArgs e) { HideConextMenu(); if (sender is CheckBox) { CheckBox check = sender as CheckBox; LivingMapLayer mapConfig = (check.Tag as TreeViewItem).Tag as LivingMapLayer; Layer theLayer = this.MapControl.Layers[mapConfig.ID] as Layer; if (theLayer != null) { theLayer.Visible = check.IsChecked.Value; EventCenter.DispatchMapLayerVisibilityChangeEvent(this, new MapLayerVisibilityChangeEventArgs(theLayer)); } } }
private void DoIdentification(MapPoint point) { IdentifyParameters identifyParams = new IdentifyParameters(); identifyParams.LayerOption = (LayerOption)Enum.Parse(typeof(LayerOption), widgetConfig.IdentifyOption, true); identifyParams.Tolerance = widgetConfig.Tolerance; identifyParams.MapExtent = this.MapControl.Extent; identifyParams.Height = (int)this.MapControl.ActualHeight; identifyParams.Width = (int)this.MapControl.ActualWidth; identifyParams.SpatialReference = new SpatialReference(this.MapSRWKID); identifyParams.ReturnGeometry = true; identifyParams.Geometry = point; this.IsBusy = true; this.ClearGraphics(0); for (int i = 0; i < widgetConfig.IdentifyLayers.Length; i++) { LivingMapLayer livingMapConfig = GetLivingMapConfig(widgetConfig.IdentifyLayers[i].Title); if (livingMapConfig != null && !string.IsNullOrEmpty(livingMapConfig.RESTURL)) { identifyParams.LayerIds.Clear(); int[] doLayers = GetIdentifiableLayers(livingMapConfig.ID, widgetConfig.IdentifyLayers[i].LayerIDs); foreach (int kk in doLayers) { identifyParams.LayerIds.Add(kk); } IdentifyTask identifyTask = new IdentifyTask(livingMapConfig.RESTURL); identifyTask.ExecuteCompleted += new EventHandler <IdentifyEventArgs>(IdentifyTask_ExecuteCompleted); identifyTask.Failed += new EventHandler <TaskFailedEventArgs>(IdentifyTask_Failed); identifyTask.Token = (livingMapConfig.Token == null) ? "" : livingMapConfig.Token; identifyTask.ProxyURL = livingMapConfig.ProxyURL; identifyTask.ExecuteAsync(identifyParams, livingMapConfig.Title); } } }
private void OnLegendInfoSucceed(LayerLegendInfo legendInfo, TreeViewItem mapTreeNode) { layerCount++; // Count Legend-Initialized LivingMap if (mapTreeNode != null && mapTreeNode.Tag != null) { LivingMapLayer mapConfig = mapTreeNode.Tag as LivingMapLayer; if (legendInfo.LayerLegendInfos != null) { if (this.MapControl.Layers[mapConfig.ID] is ArcGISDynamicMapServiceLayer) { ArcGISDynamicMapServiceLayer dynamicLayer = this.MapControl.Layers[mapConfig.ID] as ArcGISDynamicMapServiceLayer; List <int> layerIDs = GetDynamicMapLayerIDs(mapConfig, dynamicLayer.Layers); List <int> visibleLayerIDs = new List <int>(); CreateDynamicLayerTree(mapConfig.ID, legendInfo, mapTreeNode, dynamicLayer.Layers, layerIDs, visibleLayerIDs, mapConfig.ToggleLayer, true); // Initialize map visibilities dynamicLayer.VisibleLayers = visibleLayerIDs.ToArray(); EventCenter.DispatchMapLayerVisibilityChangeEvent(this, new MapLayerVisibilityChangeEventArgs(dynamicLayer, new int[0])); } else { CreateCachedLayerTree(mapConfig.ID, legendInfo, mapTreeNode); } } else if (legendInfo.LegendItemInfos != null) // Feature Layer { mapTreeNode.ItemTemplate = this.Resources["SymbolTreeNode"] as DataTemplate; mapTreeNode.ItemsSource = legendInfo.LegendItemInfos; } } if (layerCount == MapContentTree.Items.Count) { this.IsBusy = false; } }
/// <summary> /// Get All Layer IDs in a Dynamic Map Service /// </summary> private List <int> GetDynamicMapLayerIDs(LivingMapLayer mapConfig, LayerInfo[] lyrInfos) { List <int> layerIDs = new List <int>(); if (string.IsNullOrEmpty(mapConfig.VisibleLayers) || mapConfig.VisibleLayers == "*") { for (int j = 0; j < lyrInfos.Length; j++) { layerIDs.Add(lyrInfos[j].ID); } } else { string[] tmpIDs = mapConfig.VisibleLayers.Split(','); for (int j = 0; j < tmpIDs.Length; j++) { layerIDs.Add(int.Parse(tmpIDs[j])); } } return(layerIDs); }