Ejemplo n.º 1
0
        protected void OnClickInternal(UIMouseEventArgs e)
        {
            if (!Enabled)
            {
                return;
            }

            var menuId            = RegisteredFunction.Invoke <string>("BlazorContextMenu.MenuItem.GetMenuId", MenuItemElement);
            var menu              = BlazorContextMenuHandler.GetMenu(menuId);
            var contextMenuTarget = menu.GetTarget();
            var args              = new MenuItemClickEventArgs(e, menuId, contextMenuTarget, MenuItemElement, this);

            if (Click != null)
            {
                Click(args);
                if (!args.IsCanceled)
                {
                    BlazorContextMenuHandler.HideMenu(menuId);
                }
            }
            else if (ClickAsync != null)
            {
                ClickAsync(args).ContinueWith((t) =>
                {
                    if (!args.IsCanceled)
                    {
                        BlazorContextMenuHandler.HideMenu(menuId);
                    }
                });
            }
        }
        /// <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);
                }
            }
        }
 private void WidgetMenuItem_Click(object sender, MenuItemClickEventArgs e)
 {
     if (sender is ContextMenuItem)
     {
         string     title  = (sender as ContextMenuItem).Text;
         WidgetBase widget = WidgetManager.FindWidgetByTitle(title);
         if (widget != null)
         {
             widget.IsOpen = true;
         }
     }
 }
        /// <summary>
        /// Toggle the Visibilities of a Group of Layers
        /// </summary>
        private void MenuItemToggleGroup_Click(object sender, MenuItemClickEventArgs e)
        {
            if (e.ItemTag is TreeViewItem)
            {
                bool         show     = (sender == MenuItemShowAll);
                TreeViewItem treeItem = e.ItemTag as TreeViewItem;
                ToggleChildNodes(treeItem, show);

                string       mapID        = "";
                bool         isMapNode    = false;
                TreeViewItem mapLayerNode = null;
                if (treeItem.Tag is LivingMapLayer)
                {
                    mapID        = (treeItem.Tag as LivingMapLayer).ID;
                    mapLayerNode = treeItem;
                    isMapNode    = true;
                }
                else if (treeItem.Tag is TOCNodeInfo)
                {
                    mapID        = (treeItem.Tag as TOCNodeInfo).MapID;
                    mapLayerNode = GetMapLayerNode(treeItem);
                }

                if (treeItem.Header is CheckBox)
                {
                    (treeItem.Header as CheckBox).IsChecked = show;
                }
                else if (treeItem.Header is RadioButton)
                {
                    (treeItem.Header as RadioButton).IsChecked = show;
                }

                if (mapID != "")
                {
                    ArcGISDynamicMapServiceLayer dynamicMap = this.MapControl.Layers[mapID] as ArcGISDynamicMapServiceLayer;
                    int[] oldVisibles = (int[])dynamicMap.VisibleLayers.Clone();

                    List <int> layerIDs = new List <int>();
                    GetVisibleLayerIDs(mapLayerNode, layerIDs);
                    dynamicMap.VisibleLayers = layerIDs.ToArray();
                    if (isMapNode)
                    {
                        dynamicMap.Visible = show;
                    }

                    EventCenter.DispatchMapLayerVisibilityChangeEvent(this, new MapLayerVisibilityChangeEventArgs(dynamicMap, oldVisibles));
                }

                HideConextMenu();
            }
        }
        private void LinkMenuButton_MenuItemClick(object sender, MenuItemClickEventArgs e)
        {
            string sUrl = (string)e.ItemTag;

            if (!string.IsNullOrEmpty(sUrl))
            {
                if (sUrl.Equals("About"))
                {
                    if (AboutWindow == null)
                    {
                        AboutWindow = new PopupWindow()
                        {
                            Title = "About", Background = this.Background, ShowArrow = false, IsResizable = false, IsFloatable = true
                        };
                        StackPanel aboutContent = new StackPanel()
                        {
                            Orientation = Orientation.Vertical, Margin = new Thickness(12, 12, 12, 12)
                        };
                        AboutWindow.Content = aboutContent;

                        string[] contentLines = Regex.Split(AppConfig.AppHelpMenu.About.Text, @"\\n");
                        for (int i = 0; i < contentLines.Length; i++)
                        {
                            if (contentLines[i].Trim().StartsWith("http://", StringComparison.CurrentCultureIgnoreCase))
                            {
                                HyperlinkButton linkBlock = new HyperlinkButton()
                                {
                                    NavigateUri = new Uri(contentLines[i].Trim(), UriKind.Absolute), Content = contentLines[i].Trim(), Margin = new Thickness(2), FontSize = 12.5, Foreground = new SolidColorBrush(Colors.Blue), HorizontalAlignment = System.Windows.HorizontalAlignment.Center, TargetName = "_blank"
                                };
                                aboutContent.Children.Add(linkBlock);
                            }
                            else
                            {
                                TextBlock textBlock = new TextBlock()
                                {
                                    Text = contentLines[i].Trim(), Margin = new Thickness(2), FontSize = 12.5, HorizontalAlignment = System.Windows.HorizontalAlignment.Center
                                };
                                aboutContent.Children.Add(textBlock);
                            }
                        }
                    }

                    FloatingPopup.Show(AboutWindow);
                }
                else
                {
                    try
                    {
                        System.Windows.Browser.HtmlPopupWindowOptions winOptions = new System.Windows.Browser.HtmlPopupWindowOptions()
                        {
                            Resizeable = true, Width = 1000, Height = 800
                        };
                        System.Windows.Browser.HtmlWindow win = System.Windows.Browser.HtmlPage.PopupWindow(new Uri(sUrl, UriKind.Absolute), "_blank", winOptions);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }
        }