// 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);
});
}