/// <summary> /// Method to override the sketch symbol after collecting the second vertex /// </summary> /// <returns>If the sketch symbology was successfully changed.</returns> protected override async Task <bool> OnSketchModifiedAsync() { // retrieve the current sketch geometry Polyline cutGeometry = await base.GetCurrentSketchAsync() as Polyline; await QueuedTask.Run(() => { // if there are more than 2 vertices in the geometry if (cutGeometry.PointCount > 2) { // adjust the sketch symbol var symbolReference = base.SketchSymbol; if (symbolReference == null) { var cimLineSymbol = SymbolFactory.ConstructLineSymbol(ColorFactory.RedRGB, 3, SimpleLineStyle.DashDotDot); base.SketchSymbol = cimLineSymbol.MakeSymbolReference(); } else { symbolReference.Symbol.SetColor(ColorFactory.RedRGB); base.SketchSymbol = symbolReference; } } }); return(true); }
internal async Task AddGraphicToMap(Geometry geom, CIMColor color, bool IsTempGraphic = false, double size = 1.0, string text = "") { if (geom == null || MapView.Active == null) { return; } CIMSymbolReference symbol = null; if (!string.IsNullOrWhiteSpace(text) && geom.GeometryType == GeometryType.Point) { await QueuedTask.Run(() => { //var tg = new CIMTextGraphic() { Placement = Anchor.CenterPoint, Text = text}; }); } else if (geom.GeometryType == GeometryType.Point) { await QueuedTask.Run(() => { var s = SymbolFactory.ConstructPointSymbol(color, size, SimpleMarkerStyle.Circle); symbol = new CIMSymbolReference() { Symbol = s }; }); } else if (geom.GeometryType == GeometryType.Polyline) { await QueuedTask.Run(() => { var s = SymbolFactory.ConstructLineSymbol(color, size); symbol = new CIMSymbolReference() { Symbol = s }; }); } else if (geom.GeometryType == GeometryType.Polygon) { await QueuedTask.Run(() => { var outline = SymbolFactory.ConstructStroke(ColorFactory.Black, 1.0, SimpleLineStyle.Solid); var s = SymbolFactory.ConstructPolygonSymbol(color, SimpleFillStyle.Solid, outline); symbol = new CIMSymbolReference() { Symbol = s }; }); } await QueuedTask.Run(() => { var disposable = MapView.Active.AddOverlay(geom, symbol); overlayObjects.Add(disposable); GraphicsList.Add(new ProGraphic(disposable, geom, IsTempGraphic)); }); }
internal async Task AddGraphicToMap(Geometry geom, CIMColor color, bool IsTempGraphic = false, double size = 1.0) { if (geom == null || MapView.Active == null) { return; } CIMSymbolReference symbol = null; if (geom.GeometryType == GeometryType.Point) { await QueuedTask.Run(() => { var s = SymbolFactory.ConstructPointSymbol(color, size, SimpleMarkerStyle.Circle); symbol = new CIMSymbolReference() { Symbol = s }; }); } else if (geom.GeometryType == GeometryType.Polyline) { await QueuedTask.Run(() => { var s = SymbolFactory.ConstructLineSymbol(color, size); symbol = new CIMSymbolReference() { Symbol = s }; }); } else if (geom.GeometryType == GeometryType.Polygon) { await QueuedTask.Run(() => { var outline = SymbolFactory.ConstructStroke(ColorFactory.RedRGB, 1.0, SimpleLineStyle.Solid); var s = SymbolFactory.ConstructPolygonSymbol(color, SimpleFillStyle.Null, outline); symbol = new CIMSymbolReference() { Symbol = s }; }); } await QueuedTask.Run(() => { var disposable = MapView.Active.AddOverlay(geom, symbol); overlayObjects.Add(disposable); var gt = GetGraphicType(); GraphicsList.Add(new Graphic(gt, disposable, geom, this, IsTempGraphic)); RaisePropertyChanged(() => HasMapGraphics); }); }
/// <summary> /// When the active map view changes, update the graphic overlay on the map control /// </summary> /// <param name="args"></param> private void OnMapViewCameraChanged(MapViewCameraChangedEventArgs args) { if (MapView.Active == null) { return; } if (MapView.Active.Extent == null) { return; } if (MapView.Active.ViewingMode != ArcGIS.Core.CIM.MapViewingMode.Map) { return; } //get the Map view's extent var viewExtent = MapView.Active.Extent.Clone() as Envelope; QueuedTask.Run(() => { //Line symbol to be used to draw the overview rectangle. if (_lineSymbol == null) { _lineSymbol = SymbolFactory.ConstructLineSymbol(ColorFactory.RedRGB, 2.0, SimpleLineStyle.Solid); } _graphic?.Dispose(); //Clear out the old overlay _overviewEnvelope = viewExtent; //overview envelope based on active map view if (_overviewEnvelope == null) { return; } //Creating the overview rectangle IList <MapPoint> segments = new List <MapPoint>(); segments.Add(MapPointBuilder.CreateMapPoint(_overviewEnvelope.XMin, _overviewEnvelope.YMin, _overviewEnvelope.SpatialReference)); segments.Add(MapPointBuilder.CreateMapPoint(_overviewEnvelope.XMax, _overviewEnvelope.YMin, _overviewEnvelope.SpatialReference)); segments.Add(MapPointBuilder.CreateMapPoint(_overviewEnvelope.XMax, _overviewEnvelope.YMax, _overviewEnvelope.SpatialReference)); segments.Add(MapPointBuilder.CreateMapPoint(_overviewEnvelope.XMin, _overviewEnvelope.YMax, _overviewEnvelope.SpatialReference)); segments.Add(MapPointBuilder.CreateMapPoint(_overviewEnvelope.XMin, _overviewEnvelope.YMin, _overviewEnvelope.SpatialReference)); _polyLine = PolylineBuilder.CreatePolyline(segments, _overviewEnvelope.SpatialReference); _graphic = _mapControl.AddOverlay(_polyLine, _lineSymbol.MakeSymbolReference()); }); }
internal async Task <string> AddGraphicToMap(Geometry geom, CIMColor color, bool IsTempGraphic = false, double size = 1.0, string text = "", SimpleMarkerStyle markerStyle = SimpleMarkerStyle.Circle, string tag = "") { if (geom == null || MapView.Active == null) { return(string.Empty); } CIMSymbolReference symbol = null; if (!string.IsNullOrWhiteSpace(text) && geom.GeometryType == GeometryType.Point) { await QueuedTask.Run(() => { // TODO add text graphic //var tg = new CIMTextGraphic() { Placement = Anchor.CenterPoint, Text = text}; }); } else if (geom.GeometryType == GeometryType.Point) { await QueuedTask.Run(() => { var s = SymbolFactory.ConstructPointSymbol(color, size, markerStyle); symbol = new CIMSymbolReference() { Symbol = s }; }); } else if (geom.GeometryType == GeometryType.Polyline) { await QueuedTask.Run(() => { var s = SymbolFactory.ConstructLineSymbol(color, size); symbol = new CIMSymbolReference() { Symbol = s }; }); } else if (geom.GeometryType == GeometryType.Polygon) { await QueuedTask.Run(() => { var outline = SymbolFactory.ConstructStroke(ColorFactory.Black, 1.0, SimpleLineStyle.Solid); var s = SymbolFactory.ConstructPolygonSymbol(color, SimpleFillStyle.Solid, outline); symbol = new CIMSymbolReference() { Symbol = s }; }); } var result = await QueuedTask.Run(() => { var disposable = MapView.Active.AddOverlay(geom, symbol); var guid = Guid.NewGuid().ToString(); ProGraphicsList.Add(new ProGraphic(disposable, guid, geom, IsTempGraphic, tag)); return(guid); }); return(result); }
/// <summary> /// Create polyline features from graphics and add to table /// </summary> /// <param name="graphicsList">List of graphics to add to table</param> /// <returns></returns> private static async Task CreateFeatures(List <Graphic> graphicsList) { RowBuffer rowBuffer = null; bool isLine = false; try { await QueuedTask.Run(() => { var layer = MapView.Active.GetSelectedLayers()[0]; if (layer is FeatureLayer) { var featureLayer = layer as FeatureLayer; using (var table = featureLayer.GetTable()) { TableDefinition definition = table.GetDefinition(); int shapeIndex = definition.FindField("Shape"); foreach (Graphic graphic in graphicsList) { rowBuffer = table.CreateRowBuffer(); if (graphic.Geometry is Polyline) { PolylineBuilder pb = new PolylineBuilder(graphic.Geometry as Polyline); pb.HasZ = false; rowBuffer[shapeIndex] = pb.ToGeometry(); isLine = true; } else if (graphic.Geometry is Polygon) { rowBuffer[shapeIndex] = new PolygonBuilder(graphic.Geometry as Polygon).ToGeometry(); } Row row = table.CreateRow(rowBuffer); } } //Get simple renderer from feature layer CIMSimpleRenderer currentRenderer = featureLayer.GetRenderer() as CIMSimpleRenderer; CIMSymbolReference sybmol = currentRenderer.Symbol; var outline = SymbolFactory.ConstructStroke(ColorFactory.RedRGB, 1.0, SimpleLineStyle.Solid); CIMSymbol s; if (isLine) { s = SymbolFactory.ConstructLineSymbol(outline); } else { s = SymbolFactory.ConstructPolygonSymbol(ColorFactory.RedRGB, SimpleFillStyle.Null, outline); } CIMSymbolReference symbolRef = new CIMSymbolReference() { Symbol = s }; currentRenderer.Symbol = symbolRef; featureLayer.SetRenderer(currentRenderer); } }); } catch (GeodatabaseException exObj) { Console.WriteLine(exObj); throw; } finally { if (rowBuffer != null) { rowBuffer.Dispose(); } } }