// 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"); } })); }
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); })); }
//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 symbolFromStyleItem.SetRealWorldUnits(ftrLayer.UsesRealWorldSymbolSizes); //Set current renderer's symbol reference = symbol reference of the newly created symbol currentRenderer.Symbol = symbolFromStyleItem.MakeSymbolReference(); //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); }); }