Exemple #1
0
        protected override Task <bool> OnSketchCompleteAsync(Geometry geometry)
        {
            if (ActiveElementContainer == null)
            {
                Task.FromResult(true);
            }
            if (geometry == null)
            {
                return(Task.FromResult(true));
            }
            if (Module1.SelectedSymbol == null)
            {
                return(Task.FromResult(true));
            }

            return(QueuedTask.Run(() =>
            {
                var cimGraphicElement = new CIMLineGraphic
                {
                    Line = geometry as Polyline,
                    Symbol = Module1.SelectedSymbol.MakeSymbolReference()
                };
                LayoutElementFactory.Instance.CreateGraphicElement(this.ActiveElementContainer, cimGraphicElement);
                return true;
            }));
        }
Exemple #2
0
        public void CreateLineGraphic()
        {
            var graphicsLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType <ArcGIS.Desktop.Mapping.GraphicsLayer>().FirstOrDefault();

            if (graphicsLayer == null)
            {
                return;
            }
            QueuedTask.Run(() =>
            {
                #region Line Graphic Element using CIMGraphic
                //On the QueuedTask
                //Place a line symbol using the extent's lower left and upper right corner.
                var extent = MapView.Active.Extent;
                //get the lower left corner of the extent
                var pointFromCoordinates = new Coordinate2D(extent.XMin, extent.YMin);
                //get the upper right corner of the extent
                var pointToCoordinates     = new Coordinate2D(extent.XMax, extent.YMax);
                List <Coordinate2D> points = new List <Coordinate2D> {
                    pointFromCoordinates, pointToCoordinates
                };
                //create the polyline
                var lineSegment = PolylineBuilder.CreatePolyline(points);

                //specify a symbol
                var line_symbol = SymbolFactory.Instance.ConstructLineSymbol(
                    ColorFactory.Instance.GreenRGB);

                //create a CIMGraphic
                var graphic = new CIMLineGraphic()
                {
                    Symbol = line_symbol.MakeSymbolReference(),
                    Line   = lineSegment,
                };
                graphicsLayer.AddElement(graphic);
                #endregion
            });
        }
Exemple #3
0
        protected override Task <bool> OnSketchCompleteAsync(Geometry geometry)
        {
            if (Module1.Current.SelectedGraphicsLayerTOC == null)
            {
                MessageBox.Show("Select a graphics layer in the TOC", "No graphics layer selected",
                                System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Exclamation);
                return(Task.FromResult(true));
            }
            if (_lineSymbol == null)
            {
                return(Task.FromResult(true));
            }
            return(QueuedTask.Run(() =>
            {
                var selectedElements = Module1.Current.SelectedGraphicsLayerTOC.GetSelectedElements().
                                       OfType <GraphicElement>();

                //If only one element is selected, is it of type Line?
                if (selectedElements.Count() == 1)
                {
                    if (selectedElements.FirstOrDefault().GetGraphic() is CIMLineGraphic) //It is a line
                    {
                        //So we use it
                        var lineSymbol = selectedElements.FirstOrDefault().GetGraphic() as CIMLineGraphic;
                        _lineSymbol = lineSymbol.Symbol.Symbol as CIMLineSymbol;
                    }
                }
                var cimGraphicElement = new CIMLineGraphic
                {
                    Line = geometry as Polyline,
                    Symbol = _lineSymbol.MakeSymbolReference()
                };
                Module1.Current.SelectedGraphicsLayerTOC.AddElement(cimGraphicElement);
                return true;
            }));
        }
        /// <summary>
        /// グラフィックの作成
        /// </summary>
        private void CreateGraphic(FeatureClass featureClass, QueryFilter queryFilter)
        {
            var mapView = MapView.Active;

            using (RowCursor rowCursor = featureClass.Search(queryFilter, true))
            {
                rowCursor.MoveNext();

                //レコードを取得
                using (Row row = rowCursor.Current)
                {
                    Feature  feature = row as Feature;
                    Geometry shape   = feature.GetShape();

                    RemoveFromMapOverlay(); // 既存のグラフィックを削除

                    switch (shape.GeometryType)
                    {
                    // ポイントの場合(マルチには対応していません)
                    case GeometryType.Point:
                        // ポイント作成
                        var      point    = shape as MapPoint;
                        MapPoint mapPoint = MapPointBuilder.CreateMapPoint(point.X, point.Y, shape.SpatialReference);

                        // グラフィック作成
                        var pointGraphic = new CIMPointGraphic();
                        pointGraphic.Location = mapPoint;

                        // シンボル作成
                        CIMPointSymbol pointSymbol = SymbolFactory.Instance.ConstructPointSymbol(ColorFactory.Instance.RedRGB, 5);
                        pointGraphic.Symbol = pointSymbol.MakeSymbolReference();

                        // グラフィックをマップビューに追加
                        _overlayObject = mapView.AddOverlay(pointGraphic);

                        break;

                    case GeometryType.Polygon:

                        // アノテーションの場合
                        if (feature.GetType().Name == "AnnotationFeature")
                        {
                            // グラフィック作成
                            var annoGraphic = new CIMPolygonGraphic();
                            annoGraphic.Polygon = shape as Polygon;

                            // シンボル作成
                            CIMStroke        outline       = SymbolFactory.Instance.ConstructStroke(ColorFactory.Instance.RedRGB, 2, SimpleLineStyle.Solid);
                            CIMPolygonSymbol polygonSymbol = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.BlueRGB, SimpleFillStyle.Null, outline);
                            annoGraphic.Symbol = polygonSymbol.MakeSymbolReference();

                            // グラフィックをマップビューに追加
                            _overlayObject = mapView.AddOverlay(annoGraphic);
                        }
                        else
                        {
                            // グラフィック作成
                            var polygonGraphic = new CIMPolygonGraphic();
                            polygonGraphic.Polygon = shape as Polygon;

                            // シンボル作成
                            CIMPolygonSymbol polygonSymbol = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.RedRGB);
                            polygonGraphic.Symbol = polygonSymbol.MakeSymbolReference();

                            // グラフィックをマップビューに追加
                            _overlayObject = mapView.AddOverlay(polygonGraphic);
                        }

                        break;

                    case GeometryType.Polyline:

                        // グラフィック作成
                        var lineGraphic = new CIMLineGraphic();
                        lineGraphic.Line = shape as Polyline;

                        // シンボル作成
                        CIMLineSymbol lineSymbol = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.RedRGB, 5);
                        lineGraphic.Symbol = lineSymbol.MakeSymbolReference();

                        // グラフィックをマップビューに追加
                        _overlayObject = mapView.AddOverlay(lineGraphic);

                        break;

                    default:
                        break;
                    }
                }
            }
        }