public static LayerListItem CreateLayerListItemForMeasureOverlay(LayerListItem overlayEntity)
        {
            var measureOverlay = overlayEntity.ConcreteObject as MeasureTrackInteractiveOverlay;

            if (measureOverlay != null && measureOverlay.ShapeLayer.MapShapes.Count > 0)
            {
                overlayEntity.Name = "Measurements";
                overlayEntity.ChildrenContainerVisibility = Visibility.Visible;
                overlayEntity.ContextMenuItems.Clear();
                overlayEntity.ContextMenuItems.Add(LayerListMenuItemHelper.GetZoomToExtentMenuItem());
                overlayEntity.ContextMenuItems.Add(LayerListMenuItemHelper.GetRemoveOverlayMenuItem());
                overlayEntity.PropertyChanged += new PropertyChangedEventHandler(OverlayEntity_PropertyChanged);
                overlayEntity.SideImage        = new Image {
                    Source = new BitmapImage(new Uri(upIconPackUri, UriKind.Relative))
                };
                overlayEntity.IsChecked = measureOverlay.ShapeLayer.MapShapes.Any(m => m.Value.ZoomLevels.ZoomLevel01.IsActive);

                foreach (var subEntity in CollectSubEntities(measureOverlay))
                {
                    subEntity.Parent = overlayEntity;
                    overlayEntity.Children.Add(subEntity);
                }
            }
            else
            {
                overlayEntity = null;
            }

            return(overlayEntity);
        }
        private static IEnumerable <LayerListItem> CollectSubEntities(MeasureTrackInteractiveOverlay trackOverlay)
        {
            foreach (var item in trackOverlay.ShapeLayer.MapShapes)
            {
                var mapShape = item.Value;
                if (!mapShape.Feature.ColumnValues.ContainsKey("DisplayName"))
                {
                    mapShape.Feature.ColumnValues["DisplayName"] = mapShape.Feature.Id;
                }
                var subEntity = new LayerListItem
                {
                    Name                     = mapShape.Feature.ColumnValues["DisplayName"],
                    ConcreteObject           = mapShape,
                    ExpandButtonVisibility   = Visibility.Collapsed,
                    HighlightBackgroundBrush = new SolidColorBrush(Colors.White)
                };

                subEntity.ContextMenuItems.Add(LayerListMenuItemHelper.GetRenameMenuItem());
                subEntity.ContextMenuItems.Add(LayerListMenuItemHelper.GetRemoveFeatureMenuItem());
                StopRefreshProcess(() =>
                {
                    subEntity.IsChecked = mapShape.ZoomLevels.ZoomLevel01.IsActive;
                });

                var          wkt          = mapShape.Feature.GetWellKnownType();
                Styles.Style drawingStyle = null;
                if (wkt == WellKnownType.Line || wkt == WellKnownType.Multiline)
                {
                    drawingStyle = mapShape.ZoomLevels.ZoomLevel01.CustomStyles.OfType <LineStyle>().FirstOrDefault();
                }
                else
                {
                    drawingStyle = mapShape.ZoomLevels.ZoomLevel01.CustomStyles.OfType <AreaStyle>().FirstOrDefault();
                }
                subEntity.PreviewImage = new Image {
                    Source = drawingStyle.GetPreviewImage(26, 26)
                };

                subEntity.PropertyChanged += new PropertyChangedEventHandler(SubEntity_PropertyChanged);

                yield return(subEntity);
            }
        }
Ejemplo n.º 3
0
        public static MenuItem GetAddStyleMenuItem(AddStyleTypes addStyleType, FeatureLayer featureLayer)
        {
            var command = new ObservedCommand(() => { }, () => !(GisEditor.LayerListManager.SelectedLayerListItems.Count > 0));

            var menuItem = GetMenuItem(GisEditor.LanguageManager.GetStringResource("StyleBuilderWindowAddStyleLabel"), "/GisEditorPluginCore;component/Images/addstyle.png", null);

            menuItem.Items.Add(GetLoadFromLibraryMenuItem());
            menuItem.Items.Add(new Separator());
            AddSubMenuItems(addStyleType, menuItem);

            ShapeFileFeatureLayer shpLayer = featureLayer as ShapeFileFeatureLayer;

            if (shpLayer != null)
            {
                if (menuItem.Items.Count > 0)
                {
                    menuItem.Items.Add(new Separator());
                }
                menuItem.Items.Add(LayerListMenuItemHelper.GetAddStyleWizardMenuItem(shpLayer));
            }
            return(menuItem);
        }
        protected override Collection <MenuItem> GetLayerListItemContextMenuItemsCore(GetLayerListItemContextMenuParameters parameters)
        {
            var menuItems = base.GetLayerListItemContextMenuItemsCore(parameters);
            ShapeFileFeatureLayer shpLayer = (ShapeFileFeatureLayer)parameters.LayerListItem.ConcreteObject;
            MenuItem rebuildShpItem        = new MenuItem();

            rebuildShpItem.Header = GisEditor.LanguageManager.GetStringResource("ShapefileRebuildHeader");
            rebuildShpItem.Name   = "Rebuild";
            rebuildShpItem.Icon   = new Image {
                Source = new BitmapImage(new Uri("/GisEditorPluginCore;component/Images/rebuildShp.png", UriKind.RelativeOrAbsolute))
            };
            rebuildShpItem.Click += (s, e) =>
            {
                string directory = Path.Combine(GisEditor.InfrastructureManager.TemporaryPath, "Output");
                if (!Directory.Exists(directory))
                {
                    Directory.CreateDirectory(directory);
                }

                shpLayer.CloseInOverlay();

                //bool isCanceld = false;

                ProgressWindow window = new ProgressWindow();
                window.Title = GisEditor.LanguageManager.GetStringResource("RebuildShapefileWindowTitle");
                window.WindowStartupLocation = WindowStartupLocation.CenterOwner;
                window.Owner       = Application.Current.MainWindow;
                window.MainContent = "Rebuilding...";

                window.ProgressAction = () =>
                {
                    shpLayer.SafeProcess(() =>
                    {
                        ShapeFileFeatureSource.Rebuilding += (sender, e1) =>
                        {
                            if (e1.ShapePathFilename.Equals(shpLayer.ShapePathFilename, StringComparison.InvariantCultureIgnoreCase))
                            {
                                e1.Cancel = window.IsCanceled;
                                Application.Current.Dispatcher.BeginInvoke(() =>
                                {
                                    window.Maximum       = e1.RecordCount;
                                    window.ProgressValue = e1.CurrentRecordIndex;
                                });
                            }
                        };
                        ShapeFileFeatureSource.Rebuild(shpLayer.ShapePathFilename);
                    });

                    Application.Current.Dispatcher.BeginInvoke(() =>
                    {
                        if (window.DialogResult == null)
                        {
                            window.DialogResult = !window.IsCanceled;
                        }
                    });
                };

                if (window.ShowDialog().GetValueOrDefault())
                {
                    GisEditor.ActiveMap.GetOverlaysContaining(shpLayer).ForEach(o => o.Invalidate());
                    MessageBox.Show(GisEditor.LanguageManager.GetStringResource("RebuildCompletedLabel"));
                }
            };
            var index = menuItems.Count - 3;

            if (index >= 0 && index <= menuItems.Count)
            {
                menuItems.Insert(index, LayerListMenuItemHelper.GetRebuildIndexMenuItem());
                menuItems.Insert(index++, rebuildShpItem);
            }
            return(menuItems);
        }
Ejemplo n.º 5
0
        private static void AddSubMenuItems(AddStyleTypes addStyleType, MenuItem menuItem)
        {
            if ((addStyleType & AddStyleTypes.AddAreaStyle) == AddStyleTypes.AddAreaStyle)
            {
                bool hasItems = false;
                foreach (StylePlugin stylePlugin in GisEditor.StyleManager
                         .GetStylePlugins(StyleCategories.Area | StyleCategories.Composite))
                {
                    hasItems = true;
                    menuItem.Items.Add(LayerListMenuItemHelper.GetAddSpecifiedStyleByPluginMenuItem(stylePlugin));
                }

                if (hasItems)
                {
                    menuItem.Items.Add(new Separator());
                }
            }

            if ((addStyleType & AddStyleTypes.AddLineStyle) == AddStyleTypes.AddLineStyle)
            {
                bool hasItems = false;
                foreach (StylePlugin stylePlugin in GisEditor.StyleManager
                         .GetStylePlugins(StyleCategories.Line | StyleCategories.Composite))
                {
                    hasItems = true;
                    menuItem.Items.Add(LayerListMenuItemHelper.GetAddSpecifiedStyleByPluginMenuItem(stylePlugin));
                }

                if (hasItems)
                {
                    menuItem.Items.Add(new Separator());
                }
            }

            if ((addStyleType & AddStyleTypes.AddPointStyle) == AddStyleTypes.AddPointStyle)
            {
                bool hasItems = false;
                foreach (StylePlugin stylePlugin in GisEditor.StyleManager
                         .GetStylePlugins(StyleCategories.Point | StyleCategories.Composite))
                {
                    hasItems = true;
                    menuItem.Items.Add(LayerListMenuItemHelper.GetAddSpecifiedStyleByPluginMenuItem(stylePlugin));
                }

                if (hasItems)
                {
                    menuItem.Items.Add(new Separator());
                }
            }

            if ((addStyleType & AddStyleTypes.AddTextStyle) == AddStyleTypes.AddTextStyle)
            {
                foreach (StylePlugin stylePlugin in GisEditor.StyleManager
                         .GetStylePlugins(StyleCategories.Label))
                {
                    menuItem.Items.Add(LayerListMenuItemHelper.GetAddSpecifiedStyleByPluginMenuItem(stylePlugin));
                }
            }

            var lastItem = menuItem.Items[menuItem.Items.Count - 1] as Separator;

            if (lastItem != null)
            {
                menuItem.Items.Remove(lastItem);
            }
        }
        protected override LayerListItem GetLayerListItemCore(object concreteObject)
        {
            if (concreteObject is Overlay)
            {
                var overlay         = (Overlay)concreteObject;
                var overlayListItem = new LayerListItem();
                overlayListItem.ConcreteObject              = concreteObject;
                overlayListItem.CheckBoxVisibility          = Visibility.Visible;
                overlayListItem.ChildrenContainerVisibility = Visibility.Visible;
                overlayListItem.IsChecked = overlay.IsVisible;
                overlayListItem.Name      = overlay.Name;
                overlayListItem.HighlightBackgroundBrush = GetDefaultLayerGroupBackground();
                overlayListItem.PropertyChanged         += OverlayItemPropertyChanged;
                if (GisEditor.LayerListManager.SelectedLayerListItem != null && overlay == GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject)
                {
                    overlayListItem.HighlightBackgroundBrush         = new SolidColorBrush(Colors.LightBlue);
                    GisEditor.LayerListManager.SelectedLayerListItem = overlayListItem;
                }
                MenuItem toTopMenuItem    = LayerListMenuItemHelper.GetMovementMenuItem(MovementAction.ToTop);
                MenuItem toBottomMenuItem = LayerListMenuItemHelper.GetMovementMenuItem(MovementAction.ToBottom);
                MenuItem upMenuItem       = LayerListMenuItemHelper.GetMovementMenuItem(MovementAction.Up);
                MenuItem downMenuItem     = LayerListMenuItemHelper.GetMovementMenuItem(MovementAction.Down);

                overlayListItem.ContextMenuItems.Add(toTopMenuItem);
                overlayListItem.ContextMenuItems.Add(toBottomMenuItem);
                overlayListItem.ContextMenuItems.Add(upMenuItem);
                overlayListItem.ContextMenuItems.Add(downMenuItem);
                overlayListItem.ContextMenuItems.Add(new MenuItem()
                {
                    Header = "--"
                });
                overlayListItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetZoomToExtentMenuItem());
                overlayListItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetRenameMenuItem());
                overlayListItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetRemoveOverlayMenuItem());
                overlayListItem.ContextMenuItems.Add(new MenuItem()
                {
                    Header = "--"
                });
                if (concreteObject is LayerOverlay)
                {
                    overlayListItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetAddLayerMenuItem());
                    MenuItem newLayerItem = LayerListMenuItemHelper.GetNewLayerMenuItem();
                    if (newLayerItem != null)
                    {
                        overlayListItem.ContextMenuItems.Add(newLayerItem);
                    }
                    overlayListItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetRefreshLayersMenuItem((LayerOverlay)concreteObject));
                    //overlayListItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetCloneLayerCountMenuItem((LayerOverlay)concreteObject));
                }
                if (concreteObject is TileOverlay)
                {
                    overlayListItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetTileTypeMenuItem((TileOverlay)concreteObject));
                }

                //overlayListItem.ContextMenuItems.Add(new MenuItem() { Header = "--" });
                //overlayListItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetSetExceptionModeMenuItem());

                if (overlayListItem.ConcreteObject is BingMapsOverlay)
                {
                    //e.LayerListItem.Icon = new Image { Source = new BitmapImage(new Uri("/GisEditorPluginCore;component/Images/BingMaps.png", UriKind.Relative)) };
                    overlayListItem.SideImage = new Image {
                        Source = new BitmapImage(new Uri("/GisEditorPluginCore;component/Images/dr_base_maps.png", UriKind.Relative)), Width = 16, Height = 16
                    };
                    overlayListItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetBingMapStyleMenuItem());
                    overlayListItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetBaseMapsCacheMenuItem());
                    overlayListItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetTransparencyMenuItem(((BingMapsOverlay)overlayListItem.ConcreteObject).OverlayCanvas.Opacity));
                }
                else if (overlayListItem.ConcreteObject is OpenStreetMapOverlay)
                {
                    //e.LayerListItem.Icon = new Image { Source = new BitmapImage(new Uri("/GisEditorPluginCore;component/Images/osm_logo.png", UriKind.Relative)) };
                    overlayListItem.SideImage = new Image {
                        Source = new BitmapImage(new Uri("/GisEditorPluginCore;component/Images/dr_base_maps.png", UriKind.Relative)), Width = 16, Height = 16
                    };
                    overlayListItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetBaseMapsCacheMenuItem());
                    overlayListItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetTransparencyMenuItem(((OpenStreetMapOverlay)overlayListItem.ConcreteObject).OverlayCanvas.Opacity));
                }
                else if (overlayListItem.ConcreteObject is WorldMapKitMapOverlay)
                {
                    overlayListItem.SideImage = new Image {
                        Source = new BitmapImage(new Uri("/GisEditorPluginCore;component/Images/dr_base_maps.png", UriKind.Relative)), Width = 16, Height = 16
                    };
                    overlayListItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetWorldMapKitStyleMenuItem());
                    overlayListItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetBaseMapsCacheMenuItem());

                    //e.LayerListItem.Icon = new Image { Source = new BitmapImage(new Uri("/GisEditorPluginCore;component/Images/WMKOverlay.png", UriKind.Relative)) };
                    overlayListItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetTransparencyMenuItem(((WorldMapKitMapOverlay)overlayListItem.ConcreteObject).OverlayCanvas.Opacity));
                }
                else if (overlayListItem.ConcreteObject is DynamicLayerOverlay)
                {
                    overlayListItem.Name       = string.IsNullOrEmpty(overlay.Name) ? "Dynamic Layer Group" : overlay.Name;
                    toTopMenuItem.IsEnabled    = false;
                    toBottomMenuItem.IsEnabled = false;
                    upMenuItem.IsEnabled       = false;
                    downMenuItem.IsEnabled     = false;
                    InMemoryFeatureLayer[] featureLayersToDelete = ((DynamicLayerOverlay)overlay).Layers.OfType <InMemoryFeatureLayer>().Where(l => l.InternalFeatures.Count == 0).ToArray();
                    foreach (var item in featureLayersToDelete)
                    {
                        ((DynamicLayerOverlay)overlay).Layers.Remove(item);
                    }

                    //overlayListItem = null;
                }
                else if (overlayListItem.ConcreteObject is MeasureTrackInteractiveOverlay)
                {
                    if (Singleton <MeasureSetting> .Instance.AllowCollectFixedElements)
                    {
                        overlayListItem = LayerListHelper.CreateLayerListItemForMeasureOverlay(overlayListItem);
                    }
                    else
                    {
                        overlayListItem = null;
                    }
                }
                else if (overlayListItem.ConcreteObject is LayerOverlay)
                {
                    var layerOverlay = (LayerOverlay)overlay;

                    //e.LayerListItem.Icon = new Image { Source = new BitmapImage(new Uri("/GisEditorPluginCore;component/Images/LayerOverlay.png", UriKind.Relative)) };
                    overlayListItem.Name = string.IsNullOrEmpty(layerOverlay.Name) ? "Layer Group" : layerOverlay.Name;
                    overlayListItem.ChildrenContainerVisibility = Visibility.Visible;
                    overlayListItem.SideImage = new Image {
                        Source = new BitmapImage(new Uri("/GisEditorPluginCore;component/Images/up.png", UriKind.Relative))
                    };

                    //Dictionary<Layer, bool> elementVisibleDictionary = new Dictionary<Layer, bool>();
                    //layerOverlay.Layers.ForEach(layer => { elementVisibleDictionary.Add(layer, layer.IsVisible); });
                    overlayListItem.IsChecked = layerOverlay.Layers.Any(layer => layer.IsVisible);

                    //entity.SubEntities.ForEach(mapEntity => { mapEntity.IsVisible = elementVisibleDictionary[mapEntity]; });
                }
                else
                {
                    overlayListItem = null;
                }
                return(overlayListItem);
            }
            else if (concreteObject is Layer)
            {
                GdiPlusRasterLayerPlugin gdiPlusRasterLayerPlugin = new GdiPlusRasterLayerPlugin();
                LayerListItem            layerListItem            = gdiPlusRasterLayerPlugin.GetLayerListItem(concreteObject as Layer);
                if (string.IsNullOrEmpty(layerListItem.Name))
                {
                    layerListItem.Name = concreteObject.GetType().Name;
                }
                layerListItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetMovementMenuItem(MovementAction.ToTop));
                layerListItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetMovementMenuItem(MovementAction.ToBottom));
                layerListItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetMovementMenuItem(MovementAction.Up));
                layerListItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetMovementMenuItem(MovementAction.Down));
                layerListItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetZoomToExtentMenuItem());
                layerListItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetRenameMenuItem());
                layerListItem.ContextMenuItems.Add(LayerListMenuItemHelper.GetRemoveLayerMenuItem());
                return(layerListItem);
            }
            else
            {
                return(null);
            }
        }