public void CreatePolyGraphic() { var graphicsLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType <ArcGIS.Desktop.Mapping.GraphicsLayer>().FirstOrDefault(); if (graphicsLayer == null) { return; } QueuedTask.Run(() => { #region Polygon Graphic Element using CIMGraphic //On the QueuedTask //Place a polygon symbol using the mapview extent geometry var extent = MapView.Active.Extent; //Contract the extent var polygonEnv = extent.Expand(-100000, -90000, false); //create a polygon using the envelope var polygon = PolygonBuilder.CreatePolygon(polygonEnv); //specify a symbol var poly_symbol = SymbolFactory.Instance.ConstructPolygonSymbol( ColorFactory.Instance.GreenRGB); //create a CIMGraphic var graphic = new CIMPolygonGraphic() { Symbol = poly_symbol.MakeSymbolReference(), Polygon = polygon, }; graphicsLayer.AddElement(graphic); #endregion }); }
/// <summary> /// Adds the outlines to the current map view graphics overlay /// </summary> /// <param name="boundaries"></param> /// <param name="maskKind"></param> /// <param name="clearGraphics"></param> public void AddOutlines(List <Polygon> boundaries, MaskKind maskKind, bool clearGraphics = false) { if (clearGraphics) { ClearGraphics(); } CIMColor color = ColorFactory.Instance.BlueRGB; //ExactSimplified switch (maskKind) { case MaskKind.Box: color = ColorFactory.Instance.CreateRGBColor(4, 117, 34); break; case MaskKind.ConvexHull: color = ColorFactory.Instance.RedRGB; break; case MaskKind.Exact: color = ColorFactory.Instance.CreateColor( System.Windows.Media.Colors.Purple); break; } var outline = SymbolFactory.Instance.ConstructPolygonSymbol( null, SymbolFactory.Instance.ConstructStroke( color, 1.5)).MakeSymbolReference(); foreach (var bnd in boundaries) { var polyGraphic = new CIMPolygonGraphic() { Polygon = bnd, Symbol = outline }; _graphics.Add(MapView.Active.AddOverlay(polyGraphic)); } }
protected override Task <bool> OnSketchCompleteAsync(Geometry geometry) { if (ActiveElementContainer == null) { Task.FromResult(true); } if (Module1.SelectedSymbol == null) { return(Task.FromResult(true)); } return(QueuedTask.Run(() => { var cimGraphic = new CIMPolygonGraphic() { Polygon = geometry as Polygon, Symbol = Module1.SelectedSymbol.MakeSymbolReference() }; ElementFactory.Instance.CreateGraphicElement(this.ActiveElementContainer, cimGraphic); return true; })); }
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 (_polygonSymbol == 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 Polygon? if (selectedElements.Count() == 1) { if (selectedElements.FirstOrDefault().GetGraphic() is CIMPolygonGraphic) //It is a polygon { //So we use it var polySymbol = selectedElements.FirstOrDefault().GetGraphic() as CIMPolygonGraphic; _polygonSymbol = polySymbol.Symbol.Symbol as CIMPolygonSymbol; } } var cimGraphicElement = new CIMPolygonGraphic { Polygon = geometry as Polygon, Symbol = _polygonSymbol.MakeSymbolReference() }; Module1.Current.SelectedGraphicsLayerTOC.AddElement(cimGraphicElement); return true; })); }
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 (_polygonSymbol == null) { return(Task.FromResult(true)); } return(QueuedTask.Run(() => { var selectedElements = Module1.Current.SelectedGraphicsLayerTOC.GetSelectedElements(). OfType <GraphicElement>(); if (selectedElements.Count() == 1) { if (selectedElements.FirstOrDefault().GetGraphic() is CIMPolygonGraphic) { var polySymbol = selectedElements.FirstOrDefault().GetGraphic() as CIMPolygonGraphic; _polygonSymbol = polySymbol.Symbol.Symbol as CIMPolygonSymbol; } } var cimGraphicElement = new CIMPolygonGraphic { Polygon = geometry as Polygon, Symbol = _polygonSymbol.MakeSymbolReference() }; Module1.Current.SelectedGraphicsLayerTOC.AddElement(cimGraphicElement); MapPoint pntPolygon = null; pntPolygon = GeometryEngine.Instance.LabelPoint(geometry); if (selectedElements.Count() == 1) { if (selectedElements.FirstOrDefault().GetGraphic() is CIMTextGraphic) { //So we use it var textSymbol = selectedElements.FirstOrDefault().GetGraphic() as CIMTextGraphic; _textSymbol = textSymbol.Symbol.Symbol as CIMTextSymbol; } } // Get the ribbon or the dockpane text values string txtBoxString = null; string queryTxtBoxString = null; if (Module1.Current.blnDockpaneOpenStatus == false) { // Use value in the edit boxes txtBoxString = Module1.Current.TextValueEditBox.Text; queryTxtBoxString = Module1.Current.QueryValueEditBox.Text; if (txtBoxString == null || txtBoxString == "") { txtBoxString = " Default Text"; } else { txtBoxString = " " + txtBoxString; } if (queryTxtBoxString != null && queryTxtBoxString != "") { txtBoxString = txtBoxString + "\r\n " + queryTxtBoxString; } } if (Module1.Current.blnDockpaneOpenStatus == true) { _dockpane = FrameworkApplication.DockPaneManager.Find("GraphicTools_TextPane") as TextPaneViewModel; txtBoxString = _dockpane.TxtBoxDoc; queryTxtBoxString = _dockpane.QueryTxtBoxDoc; if (txtBoxString == null || txtBoxString == "") { txtBoxString = " Default Text"; } else { txtBoxString = " " + txtBoxString; } if (queryTxtBoxString != null && queryTxtBoxString != "") { txtBoxString = txtBoxString + "\r\n " + queryTxtBoxString; } } var textGraphic = new CIMParagraphTextGraphic { Symbol = _textSymbol.MakeSymbolReference(), Shape = geometry as Polygon, Text = txtBoxString }; Module1.Current.SelectedGraphicsLayerTOC.AddElement(textGraphic); Module1.Current.SelectedGraphicsLayerTOC.ClearSelection(); 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; } } } }