public CIMRenderer GetRenderer()
Public Overloads Function GetRenderer() As CIMRenderer
Return Value
A CIMRenderer.
public CIMRenderer GetRenderer()
Public Overloads Function GetRenderer() As CIMRenderer
Exception | Description |
---|---|
ArcGIS.Core.CalledOnWrongThreadException | This method or property must be called within the lambda passed to QueuedTask.Run. |
var lyr = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault(f => f.ShapeType == esriGeometryType.esriGeometryPolygon); if (lyr == null) return; QueuedTask.Run(() => { // GetRenderer from Layer (assumes it is a unique value renderer) var uvRenderer = lyr.GetRenderer() as CIMUniqueValueRenderer; if (uvRenderer == null) return; //layer has STATE_NAME field //community sample Data\Admin\AdminSample.aprx string expression = "if ($view.scale > 21000000) { return $feature.STATE_NAME } else { return 'All' }"; CIMExpressionInfo updatedExpressionInfo = new CIMExpressionInfo { Expression = expression, Title = "Custom" // can be any string used for UI purpose. }; //set the renderer's expression uvRenderer.ValueExpressionInfo = updatedExpressionInfo; //SetRenderer on Layer lyr.SetRenderer(uvRenderer); });
var lyr = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault(f => f.ShapeType == esriGeometryType.esriGeometryPolygon); if (lyr == null) return; QueuedTask.Run(() => { //Get the layer's definition //community sample Data\Admin\AdminSample.aprx var lyrDefn = lyr.GetDefinition() as CIMFeatureLayer; if (lyrDefn == null) return; //Get the label classes - we need the first one var listLabelClasses = lyrDefn.LabelClasses.ToList(); var theLabelClass = listLabelClasses.FirstOrDefault(); //set the label class Expression to use the Arcade expression theLabelClass.Expression = "return $feature.STATE_NAME + TextFormatting.NewLine + $feature.POP2000;"; //Set the label definition back to the layer. lyr.SetDefinition(lyrDefn); });
public 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 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(); //Apply the renderer to the feature layer featureLayer.SetRenderer(renderer); }); }
//Note: Call within QueuedTask.Run() if (MapView.Active.Map == null) return; //Get an existing Layer. This layer has a symbol you want to use in a new layer. var lyr = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>() .Where(l => l.ShapeType == esriGeometryType.esriGeometryPoint).FirstOrDefault(); //This is the renderer to use in the new Layer var renderer = lyr.GetRenderer() as CIMSimpleRenderer; //Set the DataConnection for the new layer Geodatabase geodatabase = new Geodatabase( new FileGeodatabaseConnectionPath(new Uri(@"E:\Data\Admin\AdminData.gdb"))); FeatureClass featureClass = geodatabase.OpenDataset<FeatureClass>("Cities"); var dataConnection = featureClass.GetDataConnection(); //Create the definition for the new feature layer var featureLayerParams = new FeatureLayerCreationParams(dataConnection) { RendererDefinition = new SimpleRendererDefinition(renderer.Symbol), IsVisible = true, }; //create the new layer LayerFactory.Instance.CreateLayer<FeatureLayer>( featureLayerParams, MapView.Active.Map);
Target Platforms: Windows 11, Windows 10