public void Update([CanBeNull] Overlaps newOverlaps) { DisposeOverlays(); if (newOverlaps == null) { return; } foreach (var overlapsBySourceRef in newOverlaps.OverlapGeometries) { IList <Geometry> overlapGeometries = overlapsBySourceRef.Value; if (overlapGeometries.Count == 0) { continue; } Geometry overlaps = GeometryEngine.Instance.Union(overlapsBySourceRef.Value); CIMSymbol symbol = overlaps is Polygon ? _overlapPolygonSymbol : (CIMSymbol)_overlapLineSymbol; var addedOverlay = MapView.Active.AddOverlay(overlaps, symbol.MakeSymbolReference()); _overlays.Add(addedOverlay); } }
private void Reset() { _featureOID = -1; _name = ""; _symbol = null; _msg = ""; }
/// <summary> /// Creates a SymbolStyleItem from a symbol /// </summary> /// <param name="symbol"></param> /// <param name="data"></param> /// <returns></returns> private Task <SymbolStyleItem> CreateSymbolStyleItem(CIMSymbol symbol, string data) { var symbolStyleItem = QueuedTask.Run(() => { SymbolStyleItem sItem = null; try { sItem = new SymbolStyleItem() //define the symbol { Symbol = symbol, ItemType = styleItemType, //Category = "Shapes", Name = data, Key = data, Tags = data, }; } catch (Exception) { } return(sItem); }); return(symbolStyleItem); }
//Create a CIMSymbol from style item selected in the results gallery list box and //apply this newly created symbol to the feature layer currently selected in Contents pane private async void ApplyTheSelectedSymbol(StyleItem selectedStyleItemToApply) { if (selectedStyleItemToApply == null || string.IsNullOrEmpty(selectedStyleItemToApply.Key)) { return; } await QueuedTask.Run(() => { //Get the feature layer currently selected in the Contents pane FeatureLayer ftrLayer = MappingModule.ActiveTOC.MostRecentlySelectedLayer as FeatureLayer; if (ftrLayer == null) { return; } //Create symbol from style item. CIMSymbol symbolFromStyleItem = selectedStyleItemToApply.GetObject() as CIMSymbol; //Set real world setting for created symbol = feature layer's setting //so that there isn't a mismatch between symbol and feature layer SymbolBuilder.SetRealWorldUnits(symbolFromStyleItem, ftrLayer.UsesRealWorldSymbolSizes); //Get simple renderer from feature layer CIMSimpleRenderer currentRenderer = ftrLayer.GetRenderer() as CIMSimpleRenderer; //Set current renderer's symbol reference = symbol reference of the newly created symbol currentRenderer.Symbol = SymbolBuilder.MakeSymbolReference(symbolFromStyleItem); //Update feature layer renderer with new symbol ftrLayer.SetRenderer(currentRenderer); }); }
public Task SetFeatureLayerSymbolFromStyleItemAsync(FeatureLayer ftrLayer, SymbolStyleItem symbolItem) { if (ftrLayer == null || symbolItem == null) { throw new System.ArgumentNullException(); } return(QueuedTask.Run(() => { //Get simple renderer from the feature layer CIMSimpleRenderer currentRenderer = ftrLayer.GetRenderer() as CIMSimpleRenderer; if (currentRenderer == null) { return; } //Get symbol from the SymbolStyleItem CIMSymbol symbol = symbolItem.Symbol; //Set symbol's real world setting to be the same as that of the feature layer symbol.SetRealWorldUnits(ftrLayer.UsesRealWorldSymbolSizes); //Update the symbol of the current simple renderer currentRenderer.Symbol = symbol.MakeSymbolReference(); //Update the feature layer renderer ftrLayer.SetRenderer(currentRenderer); })); }
// Map Authoring Snippet private Task ApplySymbolToFeatureLayerAsync(FeatureLayer featureLayer, string symbolName) { return(QueuedTask.Run(async() => { //Get the ArcGIS 2D System style from the Project var arcGIS3DStyle = Project.Current.GetItems <StyleProjectItem>().FirstOrDefault(s => s.Name == "Sample 3D Models"); //Search for the symbolName style items within the ArcGIS 2D style project item. var items = await QueuedTask.Run(() => arcGIS3DStyle.SearchSymbols(StyleItemType.PointSymbol, symbolName)); //Gets the CIMSymbol CIMSymbol symbol = items.FirstOrDefault().Symbol; //Get the renderer of the point feature layer CIMSimpleRenderer renderer = featureLayer.GetRenderer() as CIMSimpleRenderer; //Set symbol's real world setting to be the same as that of the feature layer symbol.SetRealWorldUnits(featureLayer.UsesRealWorldSymbolSizes); //Apply the symbol to the feature layer's current renderer renderer.Symbol = symbol.MakeSymbolReference(); try { //Appy the renderer to the feature layer featureLayer.SetRenderer(renderer); } catch (Exception ex) { MessageBox.Show("Error in ApplySymbolToFeatureLayerAsync: " + ex.ToString(), "Error"); } })); }
private void SetXmlText(CIMSymbol symbol) { var xml = symbol?.ToXml() ?? ""; this.AvalonTextEditor.Text = FormatXml(xml); this._xmlFolding.UpdateFoldings(this._foldingManager, this.AvalonTextEditor.Document); }
public SelectedSymbolChangedEventArgs(CIMSymbol symbol, string featureLayer, long oid, string msg) { SelectedSymbol = symbol; SelectedFeatureLayer = featureLayer; SelectedOID = oid; Message = msg; }
private void AddOverlay(Geometry polyline, CIMSymbol symbol) { var addedOverlay = MapView.Active.AddOverlay(polyline, symbol.MakeSymbolReference()); _overlays.Add(addedOverlay); }
private void AddOverlay(Geometry geometry, CIMSymbol symbol) { IDisposable addedOverlay = MapView.Active.AddOverlay(geometry, symbol.MakeSymbolReference()); _overlays.Add(addedOverlay); }
public void SetSelectedSymbol(CIMSymbol symbol, string featureLayer, long oid, string msg) { _selectedSymbol = symbol; _featureLayer = featureLayer; _oid = oid; _msg = msg; SelectedSymbolChangedEvent.Publish( new SelectedSymbolChangedEventArgs(symbol, featureLayer, oid, msg)); }
private void RefreshSymbol(CIMSymbol symbol, string msg, bool forceMsg = false) { _img = GenerateBitmapImageAsync(symbol).Result; //block if (!string.IsNullOrEmpty(msg) || forceMsg) { _msg = msg; } NotifyPropertyChanged("SymbolImageSource"); NotifyPropertyChanged("Message"); }
/// <summary> /// Get SymbolStyleItem for a given Symbol ... /// </summary> /// <param name="symbol"></param> /// <returns></returns> private SymbolStyleItem GetSymbolStyleItem(CIMSymbol symbol) { var si = new SymbolStyleItem() { Symbol = symbol, PatchHeight = 32, PatchWidth = 32 }; return(si); }
// What is called a Primitive Override in CIM is called // a "symbol property connection" or an "attribute mapping" // in the user interface. Overrides live on the SymbolReference, // not on the Symbol. They refer to properties of geometric // effects, symbol layers, and marker placements by means // of a PrimitiveName and the PropertyName. The PrimitiveName // is set to a GUID on both the primitive and the override. // // Overrides are "typically set by renderers at draw time". // // The name "override" is unfortunate because it collides // with a C# keyword; here we use the name "mapping" instead. public static CIMSymbolReference CreateReference(this CIMSymbol symbol) { if (symbol == null) { throw new ArgumentNullException(nameof(symbol)); } return(new CIMSymbolReference { Symbol = symbol }); }
private static IDisposable AddOverlay([CanBeNull] Geometry geometry, [NotNull] CIMSymbol cimSymbol) { if (geometry == null || geometry.IsEmpty) { return(null); } IDisposable result = MapView.Active.AddOverlay( geometry, cimSymbol.MakeSymbolReference()); return(result); }
private static Task getSwatch(CIMSymbol symbol) { return(QueuedTask.Run(() => { //CIMSymbol symbol = SymbolFactory.Instance.ConstructPointSymbol(ColorFactory.Instance.GreenRGB, 1.0, SimpleMarkerStyle.Circle); //You can generate a swatch for a text symbols also. var si = new SymbolStyleItem() { Symbol = symbol, PatchHeight = 64, PatchWidth = 64 }; return si.PreviewImage; })); }
protected override Task InitializeAsync() { SelectedSymbolChangedEvent.Subscribe((args) => { _selectedSymbol = args.SelectedSymbol; string msg = ""; if (args.SelectedOID >= 0) { msg = $"{args.SelectedFeatureLayer}: {args.SelectedOID}"; } SetXmlText(_selectedSymbol); RefreshSymbol(_selectedSymbol, msg, true); }); return(Task.FromResult(0)); }
private Task <ImageSource> GenerateBitmapImageAsync(Dictionary <string, object> attributes) { return(QueuedTask.Run(() => { CIMSymbol symbol = ArcGIS.Desktop.Mapping.SymbolFactory.Instance.GetDictionarySymbol("mil2525d", attributes); //At 1.3, 64 is the max pixel size we can scale to. This will be enhanced at 1.4 to support //scaling (eg up to 256, the preferred review size for military symbols) var si = new SymbolStyleItem() { Symbol = symbol, PatchHeight = 64, PatchWidth = 64 }; return si.PreviewImage; })); }
/// <summary> /// Test if the feature layer's geometry type matches the symbol type. /// </summary> private bool IsMatchingShapeType(FeatureLayer layer, CIMSymbol symbol) { if (symbol is CIMPointSymbol && layer.ShapeType == esriGeometryType.esriGeometryPoint) { return(true); } if (symbol is CIMLineSymbol && layer.ShapeType == esriGeometryType.esriGeometryPolyline) { return(true); } if (symbol is CIMPolygonSymbol && layer.ShapeType == esriGeometryType.esriGeometryPolygon) { return(true); } return(false); }
public FeatureItem(FeatureLayer featureLayer, long oid, CIMSymbol cimSymbol) { _featureLayer = featureLayer; _layerName = featureLayer.Name; _oid = oid.ToString(); _cimSymbol = cimSymbol; var si = new SymbolStyleItem() { Symbol = cimSymbol, PatchHeight = 32, PatchWidth = 32 }; var bm = si.PreviewImage as BitmapSource; bm.Freeze(); _symbolImageSource = bm; }
private ImageSource SavePicturetoFile4(CIMSymbol cimSymbol, string fname) { var si1 = new SymbolStyleItem() { Symbol = cimSymbol, PatchHeight = 32, PatchWidth = 32 }; ImageSource _symbolPicture = si1.PreviewImage; Directory.CreateDirectory(System.IO.Path.GetDirectoryName(fname)); FileStream fs = new FileStream(fname, FileMode.Create); var encoder = new System.Windows.Media.Imaging.PngBitmapEncoder(); encoder.Frames.Add(System.Windows.Media.Imaging.BitmapFrame.Create(_symbolPicture as System.Windows.Media.Imaging.BitmapSource)); encoder.Save(fs); fs.Flush(); return(_symbolPicture); }
private static Task CreateSymbolSwatch() { return(QueuedTask.Run(() => { #region Create a Swatch for a given symbol //Note: call within QueuedTask.Run() CIMSymbol symbol = SymbolFactory.Instance.ConstructPointSymbol(ColorFactory.Instance.GreenRGB, 1.0, SimpleMarkerStyle.Circle); //You can generate a swatch for a text symbols also. var si = new SymbolStyleItem() { Symbol = symbol, PatchHeight = 64, PatchWidth = 64 }; return si.PreviewImage; #endregion })); }
private Task <ImageSource> GenerateBitmapImageAsync(CIMSymbol symbol) { return(QueuedTask.Run(() => { if (symbol == null) { return null; } var si = new SymbolStyleItem() { Symbol = symbol, PatchHeight = 64, PatchWidth = 64 }; var bm = si.PreviewImage as BitmapSource; bm.Freeze(); return (ImageSource)bm; //var bm = new TransformedBitmap((BitmapSource)si.PreviewImage, new ScaleTransform(2,2)); //return (ImageSource)bm; })); }
public async Task <string> GenerateGmlAsync() { MapView mapView = MapView.Active; Map map = mapView?.Map; SpatialReference mapSpatRef = map?.SpatialReference; MySpatialReference myCyclSpatRef = _settings.CycloramaViewerCoordinateSystem; SpatialReference cyclSpatRef = (myCyclSpatRef == null) ? mapSpatRef : (myCyclSpatRef.ArcGisSpatialReference ?? (await myCyclSpatRef.CreateArcGisSpatialReferenceAsync())); Unit unit = cyclSpatRef?.Unit; double factor = unit?.ConversionFactor ?? 1; Color color = Color.White; string result = "<wfs:FeatureCollection xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:wfs=\"http://www.opengis.net/wfs\" xmlns:gml=\"http://www.opengis.net/gml\">"; await QueuedTask.Run(async() => { SpatialReference layerSpatRef = Layer.GetSpatialReference(); IList <IList <Segment> > geometries = new List <IList <Segment> >(); ICollection <Viewer> viewers = _viewerList.Viewers; foreach (var viewer in viewers) { double distance = viewer.OverlayDrawDistance; RecordingLocation recordingLocation = viewer.Location; if (recordingLocation != null) { if (cyclSpatRef?.IsGeographic ?? true) { distance = distance * factor; } else { distance = distance / factor; } double x = recordingLocation.X; double y = recordingLocation.Y; double xMin = x - distance; double xMax = x + distance; double yMin = y - distance; double yMax = y + distance; Envelope envelope = EnvelopeBuilder.CreateEnvelope(xMin, yMin, xMax, yMax, cyclSpatRef); Envelope copyEnvelope = envelope; if (layerSpatRef.Wkid != 0) { ProjectionTransformation projection = ProjectionTransformation.Create(cyclSpatRef, layerSpatRef); copyEnvelope = GeometryEngine.Instance.ProjectEx(envelope, projection) as Envelope; } Polygon copyPolygon = PolygonBuilder.CreatePolygon(copyEnvelope, layerSpatRef); ReadOnlyPartCollection polygonParts = copyPolygon.Parts; IEnumerator <ReadOnlySegmentCollection> polygonSegments = polygonParts.GetEnumerator(); IList <Segment> segments = new List <Segment>(); while (polygonSegments.MoveNext()) { ReadOnlySegmentCollection polygonSegment = polygonSegments.Current; foreach (Segment segment in polygonSegment) { segments.Add(segment); } } geometries.Add(segments); } } GC.Collect(); Polygon polygon = PolygonBuilder.CreatePolygon(geometries, layerSpatRef); using (FeatureClass featureClass = Layer?.GetFeatureClass()) { string uri = Layer?.URI; SpatialQueryFilter spatialFilter = new SpatialQueryFilter { FilterGeometry = polygon, SpatialRelationship = SpatialRelationship.Intersects, SubFields = "*" }; using (RowCursor existsResult = featureClass?.Search(spatialFilter, false)) { while (existsResult?.MoveNext() ?? false) { Row row = existsResult.Current; long objectId = row.GetObjectID(); if ((_selection == null) || (!_selection.Contains(objectId))) { Feature feature = row as Feature; var fieldvalues = new Dictionary <string, string> { { FieldUri, uri }, { FieldObjectId, objectId.ToString() } }; Geometry geometry = feature?.GetShape(); GeometryType geometryType = geometry?.GeometryType ?? GeometryType.Unknown; Geometry copyGeometry = geometry; if ((geometry != null) && (layerSpatRef.Wkid != 0)) { ProjectionTransformation projection = ProjectionTransformation.Create(layerSpatRef, cyclSpatRef); copyGeometry = GeometryEngine.Instance.ProjectEx(geometry, projection); } if (copyGeometry != null) { string gml = string.Empty; switch (geometryType) { case GeometryType.Envelope: break; case GeometryType.Multipatch: break; case GeometryType.Multipoint: break; case GeometryType.Point: MapPoint point = copyGeometry as MapPoint; if (point != null) { gml = $"<gml:Point {GmlDimension(copyGeometry)}><gml:coordinates>{await GmlPointAsync(point)}</gml:coordinates></gml:Point>"; } break; case GeometryType.Polygon: Polygon polygonGml = copyGeometry as Polygon; if (polygonGml != null) { ReadOnlyPartCollection polygonParts = polygonGml.Parts; IEnumerator <ReadOnlySegmentCollection> polygonSegments = polygonParts.GetEnumerator(); while (polygonSegments.MoveNext()) { ReadOnlySegmentCollection segments = polygonSegments.Current; gml = $"{gml}<gml:MultiPolygon><gml:PolygonMember><gml:Polygon {GmlDimension(copyGeometry)}><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>"; for (int i = 0; i < segments.Count; i++) { if (segments[i].SegmentType == SegmentType.Line) { MapPoint polygonPoint = segments[i].StartPoint; gml = $"{gml}{((i == 0) ? string.Empty : " ")}{await GmlPointAsync(polygonPoint)}"; if (i == (segments.Count - 1)) { polygonPoint = segments[i].EndPoint; gml = $"{gml} {await GmlPointAsync(polygonPoint)}"; } } } gml = $"{gml}</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:PolygonMember></gml:MultiPolygon>"; } } break; case GeometryType.Polyline: Polyline polylineGml = copyGeometry as Polyline; if (polylineGml != null) { ReadOnlyPartCollection polylineParts = polylineGml.Parts; IEnumerator <ReadOnlySegmentCollection> polylineSegments = polylineParts.GetEnumerator(); while (polylineSegments.MoveNext()) { ReadOnlySegmentCollection segments = polylineSegments.Current; gml = $"{gml}<gml:MultiLineString><gml:LineStringMember><gml:LineString {GmlDimension(copyGeometry)}><gml:coordinates>"; for (int i = 0; i < segments.Count; i++) { if (segments[i].SegmentType == SegmentType.Line) { MapPoint linePoint = segments[i].StartPoint; gml = $"{gml}{((i == 0) ? string.Empty : " ")}{await GmlPointAsync(linePoint)}"; if (i == (segments.Count - 1)) { linePoint = segments[i].EndPoint; gml = $"{gml} {await GmlPointAsync(linePoint)}"; } } } gml = $"{gml}</gml:coordinates></gml:LineString></gml:LineStringMember></gml:MultiLineString>"; } } break; case GeometryType.Unknown: break; } string fieldValueStr = fieldvalues.Aggregate(string.Empty, (current, fieldvalue) => string.Format("{0}<{1}>{2}</{1}>", current, fieldvalue.Key, fieldvalue.Value)); result = $"{result}<gml:featureMember><xs:Geometry>{fieldValueStr}{gml}</xs:Geometry></gml:featureMember>"; } } } } } CIMRenderer renderer = Layer.GetRenderer(); CIMSimpleRenderer simpleRenderer = renderer as CIMSimpleRenderer; CIMUniqueValueRenderer uniqueValueRendererRenderer = renderer as CIMUniqueValueRenderer; CIMSymbolReference symbolRef = simpleRenderer?.Symbol ?? uniqueValueRendererRenderer?.DefaultSymbol; CIMSymbol symbol = symbolRef?.Symbol; CIMColor cimColor = symbol?.GetColor(); double[] colorValues = cimColor?.Values; int red = ((colorValues != null) && (colorValues.Length >= 1)) ? ((int)colorValues[0]) : 255; int green = ((colorValues != null) && (colorValues.Length >= 2)) ? ((int)colorValues[1]) : 255; int blue = ((colorValues != null) && (colorValues.Length >= 3)) ? ((int)colorValues[2]) : 255; int alpha = ((colorValues != null) && (colorValues.Length >= 4)) ? ((int)colorValues[3]) : 255; color = Color.FromArgb(alpha, red, green, blue); }); GmlChanged = (Color != color); Color = color; string newGml = $"{result}</wfs:FeatureCollection>"; GmlChanged = ((newGml != Gml) || GmlChanged); return(Gml = newGml); }
public async void Examples() { #region Get symbol from SymbolStyleItem SymbolStyleItem symbolItem = null; CIMSymbol symbol = await QueuedTask.Run <CIMSymbol>(() => { return(symbolItem.Symbol); }); #endregion #region Get color from ColorStyleItem ColorStyleItem colorItem = null; CIMColor color = await QueuedTask.Run <CIMColor>(() => { return(colorItem.Color); }); #endregion #region Get color ramp from ColorRampStyleItem ColorRampStyleItem colorRampItem = null; CIMColorRamp colorRamp = await QueuedTask.Run <CIMColorRamp>(() => { return(colorRampItem.ColorRamp); }); #endregion #region Get north arrow from NorthArrowStyleItem NorthArrowStyleItem northArrowItem = null; CIMNorthArrow northArrow = await QueuedTask.Run <CIMNorthArrow>(() => { return(northArrowItem.NorthArrow); }); #endregion #region Get scale bar from ScaleBarStyleItem ScaleBarStyleItem scaleBarItem = null; CIMScaleBar scaleBar = await QueuedTask.Run <CIMScaleBar>(() => { return(scaleBarItem.ScaleBar); }); #endregion #region Get label placement from LabelPlacementStyleItem LabelPlacementStyleItem labelPlacementItem = null; CIMLabelPlacementProperties labelPlacement = await QueuedTask.Run <CIMLabelPlacementProperties>(() => { return(labelPlacementItem.LabelPlacement); }); #endregion #region Get grid from GridStyleItem GridStyleItem gridItem = null; CIMMapGrid grid = await QueuedTask.Run <CIMMapGrid>(() => { return(gridItem.Grid); }); #endregion #region Get legend from LegendStyleItem LegendStyleItem legendItem = null; CIMLegend legend = await QueuedTask.Run <CIMLegend>(() => { return(legendItem.Legend); }); #endregion #region Get table frame from TableFrameStyleItem TableFrameStyleItem tableFrameItem = null; CIMTableFrame tableFrame = await QueuedTask.Run <CIMTableFrame>(() => { return(tableFrameItem.TableFrame); }); #endregion #region Get map surround from MapSurroundStyleItem MapSurroundStyleItem mapSurroundItem = null; CIMMapSurround mapSurround = await QueuedTask.Run <CIMMapSurround>(() => { return(mapSurroundItem.MapSurround); }); #endregion }
//Create a CIMSymbol from style item selected in the results gallery list box and //apply this newly created symbol to the feature layer currently selected in Contents pane private async void ApplyTheSelectedSymbol(SymbolStyleItem selectedStyleItemToApply) { if (selectedStyleItemToApply == null || string.IsNullOrEmpty(selectedStyleItemToApply.Key)) { return; } await QueuedTask.Run(() => { //Get the feature layer currently selected in the Contents pane var selectedLayers = MapView.Active.GetSelectedLayers(); //Only one feature layer should be selected in the Contents pane if (selectedLayers.Count != 1) { ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Select the feature layer to which you want to apply the selected symbol. Only one feature layer should be selected."); //Clear the current selection in gallery _selectedStyleItem = null; NotifyPropertyChanged(() => SelectedStyleItem); return; } FeatureLayer ftrLayer = selectedLayers[0] as FeatureLayer; //The selected layer should be a feature layer if (ftrLayer == null) { return; } //Get symbol from symbol style item. CIMSymbol symbolFromStyleItem = selectedStyleItemToApply.Symbol; //Make sure there isn't a mismatch between the type of selected symbol in gallery and feature layer geometry type if ((symbolFromStyleItem is CIMPointSymbol && ftrLayer.ShapeType != esriGeometryType.esriGeometryPoint) || (symbolFromStyleItem is CIMLineSymbol && ftrLayer.ShapeType != esriGeometryType.esriGeometryPolyline) || (symbolFromStyleItem is CIMPolygonSymbol && ftrLayer.ShapeType != esriGeometryType.esriGeometryPolygon && ftrLayer.ShapeType != esriGeometryType.esriGeometryMultiPatch)) { ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("There is a mismatch between symbol type and feature layer geometry type."); //Clear the current selection in gallery _selectedStyleItem = null; NotifyPropertyChanged(() => SelectedStyleItem); return; } //Get simple renderer from feature layer CIMSimpleRenderer currentRenderer = ftrLayer.GetRenderer() as CIMSimpleRenderer; if (currentRenderer == null) { ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Select a feature layer symbolized with a simple renderer."); //Clear the current selection in gallery _selectedStyleItem = null; NotifyPropertyChanged(() => SelectedStyleItem); return; } //Set real world setting for created symbol = feature layer's setting //so that there isn't a mismatch between symbol and feature layer SymbolFactory.SetRealWorldUnits(symbolFromStyleItem, ftrLayer.UsesRealWorldSymbolSizes); //Set current renderer's symbol reference = symbol reference of the newly created symbol currentRenderer.Symbol = SymbolFactory.MakeSymbolReference(symbolFromStyleItem); //Update feature layer renderer with new symbol ftrLayer.SetRenderer(currentRenderer); }); }
private Task SetFeatureLayerSymbolAsync(FeatureLayer ftrLayer, CIMSymbol symbolToApply) { if (ftrLayer == null || symbolToApply == null) throw new System.ArgumentNullException(); return QueuedTask.Run(() => { //Get simple renderer from the feature layer CIMSimpleRenderer currentRenderer = ftrLayer.GetRenderer() as CIMSimpleRenderer; if (currentRenderer == null) return; //Set symbol's real world setting to be the same as that of the feature layer symbolToApply.SetRealWorldUnits(ftrLayer.UsesRealWorldSymbolSizes); //Update the symbol of the current simple renderer currentRenderer.Symbol = symbolToApply.MakeSymbolReference(); //Update the feature layer renderer ftrLayer.SetRenderer(currentRenderer); }); }
public static T FindPrimitive <T>(CIMSymbol symbol, Guid label) where T : CIMObject { // TextSymbol has no PrimitiveName; all other symbols derive from MultiLayerSymbol if (!(symbol is CIMMultiLayerSymbol multiLayerSymbol)) { return(null); } string primitiveName = FormatGuid(label); if (multiLayerSymbol.Effects != null) { foreach (var effect in multiLayerSymbol.Effects) { if (string.Equals(effect.PrimitiveName, primitiveName)) { if (effect is T found) { return(found); } } } } if (multiLayerSymbol.SymbolLayers != null) { foreach (var layer in multiLayerSymbol.SymbolLayers) { if (string.Equals(layer.PrimitiveName, primitiveName)) { if (layer is T found) { return(found); } } if (layer is CIMMarker marker) { var placement = marker.MarkerPlacement; if (placement != null && string.Equals(placement.PrimitiveName, primitiveName)) { if (placement is T found) { return(found); } } if (layer is CIMVectorMarker vectorMarker) { var graphics = vectorMarker.MarkerGraphics; if (graphics != null) { foreach (var graphic in graphics) { if (string.Equals(graphic.PrimitiveName, primitiveName)) { if (graphic is T found) { return(found); } } } } } } if (layer.Effects != null) { foreach (var effect in layer.Effects) { if (string.Equals(effect.PrimitiveName, primitiveName)) { if (effect is T found) { return(found); } } } } } } return(null); // not found }
protected async override Task <bool> OnSketchCompleteAsync(Geometry geometry) { Reset(); if (MapView.Active.Map.IsScene) { return(false); } var mv = MapView.Active; Geometry sel_geom = null; IDisposable sel_graphic = null; //Flash the selection geometry so we can see where we clicked QueuedTask.Run(() => { sel_geom = GeometryEngine.Instance.Buffer(geometry, _bufferDist) as Polygon; sel_graphic = mv.AddOverlay(sel_geom, _polyOutline); }); await QueuedTask.Run(() => { var result = MapView.Active.SelectFeatures( sel_geom, SelectionCombinationMethod.New, false, false); var result2 = MapView.Active.SelectElements( sel_geom, SelectionCombinationMethod.New, false); _msg = "No basic feature layers or graphics layers selected"; //first anno layer (if there is one) var annoLayer = result.Keys.OfType <AnnotationLayer>().FirstOrDefault(); //get the first feature layer that supports symbol lookup var symbolLayer = result.Keys.FirstOrDefault(layer => { if (layer is FeatureLayer featureLayer) { //Test whether symbol lookup is supported with CanLookupSymbol() return(featureLayer.CanLookupSymbol()); } return(false); }) as FeatureLayer; sel_graphic?.Dispose(); //Graphics Layer takes precedence... if (result2.Count > 0) { var elem = result2.First() as GraphicElement; _symbol = elem.GetGraphic().Symbol.Symbol; _name = ((GraphicsLayer)elem.GetParent()).Name; _featureOID = -1; _msg = $"Graphic element {elem.Name}"; } //Then Annotation... else if (annoLayer != null) { _name = annoLayer.Name; _featureOID = result[annoLayer][0]; _msg = $"anno feature {_featureOID}"; var qf = new QueryFilter() { ObjectIDs = new List <long> { _featureOID } }; var rowcursor = annoLayer.GetSelection().Search(qf); if (rowcursor.MoveNext()) { var af = rowcursor.Current as AnnotationFeature; var graphic = af.GetGraphic() as CIMTextGraphic; _symbol = graphic.Symbol.Symbol; } rowcursor.Dispose(); } //Then anything else... else if (symbolLayer != null) { _name = symbolLayer.Name; _featureOID = result[symbolLayer][0]; _msg = $"feature {_featureOID}"; _symbol = symbolLayer.LookupSymbol(_featureOID, MapView.Active); } }); Module1.Current.SetSelectedSymbol(_symbol, _name, _featureOID, _msg); return(true); }
/// <summary> /// Find and return the "primitive" (that is, symbol layer, geometric effect, /// or marker placement) at the specified location within the given symbol. /// Location specification is one of: /// <list type="bullet"> /// <item>effect N</item> /// <item>layer N</item> /// <item>layer N placement</item> /// <item>layer N graphic M</item> /// <item>layer N effect M</item> /// </list> /// where N and M are non-negative integers. /// </summary> /// <typeparam name="T">Typically one of CIMGeometricEffect or CIMSymbolLayer /// or CIMMarkerPlacement or a subtype of these.</typeparam> /// <returns>The primitive found, or <c>null</c> if not found</returns> public static T FindPrimitive <T>(CIMSymbol symbol, string spec) where T : CIMObject { if (string.IsNullOrEmpty(spec)) { return(null); } if (!(symbol is CIMMultiLayerSymbol multiLayerSymbol)) { return(null); } const char blank = ' '; const char tab = '\t'; var parts = spec.Split(new[] { blank, tab }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length < 2 || parts.Length > 4) { throw InvalidPrimitiveSpec(spec); } if (!TryParseIndex(parts[1], out int index) || index < 0) { throw InvalidPrimitiveSpec(spec); } int localIndex = -1; if (parts.Length == 4 && (!TryParseIndex(parts[3], out localIndex) || localIndex < 0)) { throw InvalidPrimitiveSpec(spec); } string root = parts[0].Trim(); string suffix = parts.Length >= 3 ? parts[2].Trim() : null; if (string.Equals(root, "effect", StringComparison.OrdinalIgnoreCase)) { var effects = multiLayerSymbol.Effects; var effect = effects != null && index < effects.Length ? effects[index] : null; return(string.IsNullOrEmpty(suffix) ? effect as T : null); } if (string.Equals(root, "layer", StringComparison.OrdinalIgnoreCase)) { var layers = multiLayerSymbol.SymbolLayers; var layer = layers != null && index < layers.Length ? layers[index] : null; if (string.IsNullOrEmpty(suffix)) { return(layer as T); } if (string.Equals(suffix, "placement", StringComparison.OrdinalIgnoreCase)) { return(layer is CIMMarker marker ? marker.MarkerPlacement as T : null); } if (string.Equals(suffix, "effect", StringComparison.OrdinalIgnoreCase)) { var effects = layer?.Effects; var effect = effects != null && localIndex < effects.Length ? effects[localIndex] : null; return(effect as T); } if (string.Equals(suffix, "graphic", StringComparison.OrdinalIgnoreCase)) { var graphics = (layer as CIMVectorMarker)?.MarkerGraphics; var graphic = graphics != null && localIndex < graphics.Length ? graphics[localIndex] : null; return(graphic as T); // TODO MarkerGraphic has a PrimitiveName, but no suitable properties for mapping; instead, recurse on graphic.Symbol } throw InvalidPrimitiveSpec(spec); } throw InvalidPrimitiveSpec(spec); }