Exception | Description |
---|---|
ArcGIS.Core.CalledOnWrongThreadException | This property must be called within the lambda passed to QueuedTask.Run |
//Must be on QueuedTask.Run(() => { ... //Build geometry List<Coordinate2D> plCoords = new List<Coordinate2D>(); plCoords.Add(new Coordinate2D(1, 8.5)); plCoords.Add(new Coordinate2D(1.66, 9)); plCoords.Add(new Coordinate2D(2.33, 8.1)); plCoords.Add(new Coordinate2D(3, 8.5)); Polyline linePl = PolylineBuilderEx.CreatePolyline(plCoords); //Reference a line symbol in a style var ProjectStyles = Project.Current.GetItems<StyleProjectItem>(); StyleProjectItem style = ProjectStyles.First(x => x.Name == "ArcGIS 2D"); var symStyle = style.SearchSymbols(StyleItemType.LineSymbol, "Line with 2 Markers")[0]; CIMLineSymbol lineSym = symStyle.Symbol as CIMLineSymbol; lineSym.SetSize(20); //Set symbolology, create and add element to layout //CIMLineSymbol lineSym = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlueRGB, 4.0, SimpleLineStyle.Solid); ElementFactory.Instance.CreateGraphicElement( container, linePl, lineSym, "New Line");
//Must be on QueuedTask.Run(() => { ... //Build geometry Coordinate2D coord2D = new Coordinate2D(2.0, 10.0); //Reference a point symbol in a style StyleProjectItem stylePrjItm = Project.Current.GetItems<StyleProjectItem>() .FirstOrDefault(item => item.Name == "ArcGIS 2D"); SymbolStyleItem symStyleItm = stylePrjItm.SearchSymbols( StyleItemType.PointSymbol, "City Hall")[0]; CIMPointSymbol pointSym = symStyleItm.Symbol as CIMPointSymbol; pointSym.SetSize(50); var elemInfo = new ElementInfo() { CustomProperties = new List<CIMStringMap>() { new CIMStringMap() { Key = "Key1", Value = "Value1"}, new CIMStringMap() { Key = "Key2", Value = "Value2"} }, Anchor = Anchor.TopRightCorner, Rotation = 45.0 }; var graphic = GraphicFactory.Instance.CreateSimpleGraphic( coord2D.ToMapPoint(), pointSym); ElementFactory.Instance.CreateGraphicElement( container, graphic, "New Point", true, elemInfo);
SymbolStyleItem symbolItem = null; CIMSymbol symbol = await QueuedTask.Run<CIMSymbol>(() => { return symbolItem.Symbol; });
SymbolStyleItem symbolItem = null; CIMSymbol symbol = await QueuedTask.Run<CIMSymbol>(() => { return symbolItem.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;
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); }); }
// var map = MapView.Active.Map; // if (map == null) // return; // var pointFeatureLayer = // map.GetLayersAsFlattenedList() // .OfType<FeatureLayer>() // .Where(fl => fl.ShapeType == esriGeometryType.esriGeometryPoint); // await ApplySymbolToFeatureLayerAsync(pointFeatureLayer.FirstOrDefault(), "Fire Station"); public Task ApplySymbolToFeatureLayerAsync(FeatureLayer featureLayer, string symbolName) { return QueuedTask.Run(async () => { //Get the ArcGIS 2D System style from the Project var arcGIS2DStyle = Project.Current.GetItems<StyleProjectItem>().FirstOrDefault(s => s.Name == "ArcGIS 2D"); //Search for the symbolName style items within the ArcGIS 2D style project item. var items = await QueuedTask.Run(() => arcGIS2DStyle.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(); //Appy the renderer to the feature layer featureLayer.SetRenderer(renderer); }); }
Target Platforms: Windows 11, Windows 10