示例#1
0
        public void CreateGraphicsLayer()
        {
            #region Create GraphicsLayer
            var map = MapView.Active.Map;
            if (map.MapType != MapType.Map)
            {
                return;// not 2D
            }
            var gl_param = new GraphicsLayerCreationParams {
                Name = "Graphics Layer"
            };
            QueuedTask.Run(() =>
            {
                //By default will be added to the top of the TOC
                var graphicsLayer = LayerFactory.Instance.CreateLayer <ArcGIS.Desktop.Mapping.GraphicsLayer>(gl_param, map);

                //Add to the bottom of the TOC
                LayerFactory.Instance.CreateLayer <ArcGIS.Desktop.Mapping.GraphicsLayer>(gl_param, map,
                                                                                         LayerPosition.AddToBottom);

                //Add a graphics layer to a group layer...
                var group_layer = map.GetLayersAsFlattenedList().OfType <GroupLayer>().First();
                LayerFactory.Instance.CreateLayer <ArcGIS.Desktop.Mapping.GraphicsLayer>(gl_param, group_layer);

                //TODO...use the graphics layer
            });
            #endregion
        }
示例#2
0
        protected override Task OnToolActivateAsync(bool hasMapViewChanged)
        {
            // Check if the current map is available and a 2D map.
            Map map = MapView.Active.Map;

            if (map.MapType != MapType.Map)
            {
                // Map isn't a 2d map.
                return(null);
            }

            QueuedTask.Run(() =>
            {
                FieldOfJoy = map.Layers.FirstOrDefault(item => item.GetType() == typeof(GraphicsLayer) && item.Name == "Boter Kaas en Eieren") as GraphicsLayer;
                if (FieldOfJoy == null)
                {
                    // Create a grapics layer
                    GraphicsLayerCreationParams gl_param = new GraphicsLayerCreationParams {
                        Name = "Boter Kaas en Eieren"
                    };
                    // By default will be added to the top of the TOC
                    FieldOfJoy = LayerFactory.Instance.CreateLayer <GraphicsLayer>(gl_param, map);
                }

                // Get the centre
                var x = MapView.Active.GetViewSize().Width / 2;
                var y = MapView.Active.GetViewSize().Height / 2;
                CreatePlayField(new System.Windows.Point(x, y), FieldOfJoy);
            });

            return(base.OnToolActivateAsync(hasMapViewChanged));
        }
        protected override void OnClick()
        {
            GroupLayer selectedGroupLayer = null;

            //If one group layer is selected, then add graphics layer to that one layer
            if (MapView.Active.GetSelectedLayers().Count == 1)
            {
                selectedGroupLayer = MapView.Active.GetSelectedLayers()[0] as GroupLayer;
            }

            var graphicsLayerCreationParams = new GraphicsLayerCreationParams {
                Name = "Graphics Layer"
            };

            QueuedTask.Run(() => {
                if (selectedGroupLayer != null)
                {
                    LayerFactory.Instance.CreateLayer <GraphicsLayer>(graphicsLayerCreationParams, selectedGroupLayer,
                                                                      LayerPosition.AutoArrange);
                }
                if (selectedGroupLayer == null)
                {
                    LayerFactory.Instance.CreateLayer <GraphicsLayer>(graphicsLayerCreationParams, MapView.Active.Map,
                                                                      LayerPosition.AutoArrange);
                }
            });
        }
示例#4
0
        private async void CheckAndCreateGraphicLayer()
        {
            var map = MapView.Active.Map;

            if (map.MapType != MapType.Map)
            {
                return;                             // not 2D
            }
            if (this._PolygonGraphicsLayer == null) //is that null?
            {
                //find in the current map
                this._PolygonGraphicsLayer = map.GetLayersAsFlattenedList().OfType <GraphicsLayer>().FirstOrDefault(x => x.Name.Equals(_graphicLayerName, StringComparison.OrdinalIgnoreCase));
                if (this._PolygonGraphicsLayer == null) // if it is not existing layer in the map
                {
                    var gl_param = new GraphicsLayerCreationParams {
                        Name = _graphicLayerName
                    };
                    await QueuedTask.Run(() =>
                    {
                        this._PolygonGraphicsLayer = LayerFactory.Instance.CreateLayer <GraphicsLayer>(gl_param, map);
                    });

                    this._PolygonGraphicsLayer.PropertyChanged += _PolygonGraphicsLayer_PropertyChanged;
                }
            }
        }