protected override async void OnClick() { //Get all styles in the project var styles = Project.Current.GetItems <StyleProjectItem>(); //Get a specific style in the project StyleProjectItem style = styles.First(x => x.Name == "CustomStyle"); var pointSymbols = await style.SearchSymbolsAsync(StyleItemType.PointSymbol, "Tree"); var treeSymbolItem = pointSymbols.FirstOrDefault(); if (treeSymbolItem == null) { return; } var colorRamps = await style.SearchColorRampsAsync("UniqueValues"); var colorRampItem = colorRamps.FirstOrDefault(); if (colorRampItem == null) { return; } var layer = MapView.Active.Map.GetLayersAsFlattenedList().FirstOrDefault(l => l.Name == "Trees") as FeatureLayer; Task t = QueuedTask.Run(() => { var symbol = treeSymbolItem.Symbol; symbol.SetSize(12.0); var renderer = new UniqueValueRendererDefinition() { UseDefaultSymbol = false, ValueFields = new string[] { "type" }, SymbolTemplate = symbol.MakeSymbolReference(), ColorRamp = colorRampItem.ColorRamp }; //Update the feature layer renderer layer.SetRenderer(layer.CreateRenderer(renderer)); }); }
protected override async void OnClick() { //Get all styles in the project var styles = Project.Current.GetItems <StyleProjectItem>(); //Get a specific style in the project StyleProjectItem style = styles.First(x => x.Name == "CustomStyle"); var results = await style.SearchSymbolsAsync(StyleItemType.PointSymbol, "Tree"); var treeSymbolItem = results.FirstOrDefault(); if (treeSymbolItem == null) { return; } var layer = MapView.Active.Map.GetLayersAsFlattenedList().FirstOrDefault(l => l.Name == "Trees") as FeatureLayer; if (layer == null) { return; } Task t = QueuedTask.Run(() => { var symbol = treeSymbolItem.Symbol as CIMPointSymbol; symbol.SetSize(12.0); symbol.SetColor(ColorFactory.CreateRGBColor(24, 69, 59)); var renderer = new GraduatedSymbolsRendererDefinition() { BreakCount = 5, ClassificationField = "height", ClassificationMethod = ClassificationMethod.EqualInterval, SymbolTemplate = symbol.MakeSymbolReference(), MinimumSymbolSize = 6.0, MaximumSymbolSize = 20.0 }; //Update the feature layer renderer layer.SetRenderer(layer.CreateRenderer(renderer)); }); }
protected override async void OnClick() { //Get all styles in the project var styles = Project.Current.GetItems <StyleProjectItem>(); //Get a specific style in the project StyleProjectItem style = styles.First(x => x.Name == "CustomStyle"); var results = await style.SearchSymbolsAsync(StyleItemType.PointSymbol, "Tree"); var treeSymbolItem = results.FirstOrDefault(); if (treeSymbolItem == null) { return; } var layer = MapView.Active.Map.GetLayersAsFlattenedList().FirstOrDefault(l => l.Name == "Trees") as FeatureLayer; if (layer == null) { return; } Task t = QueuedTask.Run(() => { var symbol = treeSymbolItem.Symbol as CIMPointSymbol; symbol.SymbolLayers = new CIMSymbolLayer[] { symbol.SymbolLayers[0] }; symbol.SetSize(12.0); symbol.SetColor(ColorFactory.CreateRGBColor(24, 69, 59)); var renderer = new SimpleRendererDefinition(symbol.MakeSymbolReference()); //Update the feature layer renderer layer.SetRenderer(layer.CreateRenderer(renderer)); }); }
private Task SearchSymbols() { //return QueuedTask.Run(async () => //{ // //Get results and populate symbol gallery // IList<SymbolStyleItem> pointSymbols = await _militaryStyleItem.SearchSymbolsAsync(StyleItemType.PointSymbol, _searchString); // IList<SymbolStyleItem> lineSymbols = await _militaryStyleItem.SearchSymbolsAsync(StyleItemType.LineSymbol, _searchString); // IList<SymbolStyleItem> polygonSymbols = await _militaryStyleItem.SearchSymbolsAsync(StyleItemType.PolygonSymbol, _searchString); // IList<SymbolStyleItem> combinedSymbols = new List<SymbolStyleItem>(); // (combinedSymbols as List<SymbolStyleItem>).AddRange(pointSymbols); // (combinedSymbols as List<SymbolStyleItem>).AddRange(lineSymbols); // (combinedSymbols as List<SymbolStyleItem>).AddRange(polygonSymbols); // int outParse; // _styleItems = combinedSymbols.Where(x => (x.Key.Length == 8 && int.TryParse(x.Key, out outParse)) || // (x.Key.Length == 10 && x.Key[8] == '_' && int.TryParse(x.Key[9].ToString(), out outParse))).ToList(); // _progressDialog.Hide(); //}); return(QueuedTask.Run(async() => { var list = new List <StyleItemType>() { StyleItemType.PointSymbol, StyleItemType.LineSymbol, StyleItemType.PolygonSymbol }; IEnumerable <Task <IList <SymbolStyleItem> > > symbolQuery = from type in list select _militaryStyleItem.SearchSymbolsAsync(type, _searchString); var combinedSymbols = new List <SymbolStyleItem>(); int outParse; // start the query var searchTasks = symbolQuery.ToList(); while (searchTasks.Count > 0) { var nextTask = await Task.WhenAny(searchTasks); var results = await nextTask; searchTasks.Remove(nextTask); combinedSymbols.AddRange(results.Where(x => (x.Key.Length == 8 && int.TryParse(x.Key, out outParse)) || (x.Key.Length == 10 && x.Key[8] == '_' && int.TryParse(x.Key[9].ToString(), out outParse)))); } //_styleItems = combinedSymbols.Where(x => (x.Key.Length == 8 && int.TryParse(x.Key, out outParse)) || // (x.Key.Length == 10 && x.Key[8] == '_' && int.TryParse(x.Key[9].ToString(), out outParse))).ToList(); _styleItems = combinedSymbols; _progressDialog.Hide(); })); }
protected async override void OnClick() { // To use this utility, you need to add the style that you want to update to your ArcGIS Pro project // If necessary and not alreadly listed, update the line below to include the name of the style that // you want to update // Note: no ".stylx" extension List <string> stylxFiles = new List <string>() { "mil2525d", "mil2525c", "app6b" }; string stylxUpdatedNames = string.Empty; foreach (string stylxToUpdateName in stylxFiles) { StyleProjectItem projectStyleItem = null; try { projectStyleItem = Project.Current.GetItems <StyleProjectItem>().First(x => x.Name == stylxToUpdateName); } catch (Exception ex) { projectStyleItem = null; } if (projectStyleItem == null) { continue; } stylxUpdatedNames += stylxToUpdateName + ";"; //update point symbols var ptSymbols = await projectStyleItem.SearchSymbolsAsync(StyleItemType.PointSymbol, ""); await QueuedTask.Run(() => { foreach (SymbolStyleItem s in ptSymbols) { CIMPointSymbol symbol = (CIMPointSymbol)s.Symbol; if (symbol == null) { continue; } try { var lyrs = symbol.SymbolLayers; foreach (CIMVectorMarker x in lyrs) { if (x.ScaleSymbolsProportionally == false) { x.ScaleSymbolsProportionally = true; } } symbol.SymbolLayers = lyrs; s.Symbol = symbol; projectStyleItem.UpdateItem(s); } catch (Exception ex2) { } } }); //update line symbols var lineSymbols = await projectStyleItem.SearchSymbolsAsync(StyleItemType.LineSymbol, ""); await QueuedTask.Run(() => { foreach (SymbolStyleItem s in lineSymbols) { try { if (s.Symbol is CIMLineSymbol) { CIMLineSymbol symbol = (CIMLineSymbol)s.Symbol; var lyrs = symbol.SymbolLayers; foreach (CIMSymbolLayer lyr in lyrs) { CIMVectorMarker x = lyr as CIMVectorMarker; if (x != null) { if (x.ScaleSymbolsProportionally == false) { x.ScaleSymbolsProportionally = true; } } } symbol.SymbolLayers = lyrs; s.Symbol = symbol; } else if (s.Symbol is CIMPointSymbol) { CIMPointSymbol symbol = (CIMPointSymbol)s.Symbol; var lyrs = symbol.SymbolLayers; foreach (CIMSymbolLayer lyr in lyrs) { CIMVectorMarker x = lyr as CIMVectorMarker; if (x != null) { if (x.ScaleSymbolsProportionally == false) { x.ScaleSymbolsProportionally = true; } } } symbol.SymbolLayers = lyrs; s.Symbol = symbol; s.ItemType = StyleItemType.LineSymbol; } projectStyleItem.UpdateItem(s); } catch (Exception ex3) { } } }); //update polygon symbols var polygonSymbols = await projectStyleItem.SearchSymbolsAsync(StyleItemType.PolygonSymbol, ""); await QueuedTask.Run(() => { foreach (SymbolStyleItem s in polygonSymbols) { try { if (s.Symbol is CIMPolygonSymbol) { CIMPolygonSymbol symbol = (CIMPolygonSymbol)s.Symbol; var lyrs = symbol.SymbolLayers; foreach (CIMSymbolLayer lyr in lyrs) { CIMVectorMarker x = lyr as CIMVectorMarker; if (x != null) { if (x.ScaleSymbolsProportionally == false) { x.ScaleSymbolsProportionally = true; } } } symbol.SymbolLayers = lyrs; s.Symbol = symbol; } else if (s.Symbol is CIMPointSymbol) { CIMPointSymbol symbol = (CIMPointSymbol)s.Symbol; var lyrs = symbol.SymbolLayers; foreach (CIMSymbolLayer lyr in lyrs) { CIMVectorMarker x = lyr as CIMVectorMarker; if (x != null) { if (x.ScaleSymbolsProportionally == false) { x.ScaleSymbolsProportionally = true; } } } symbol.SymbolLayers = lyrs; s.Symbol = symbol; s.ItemType = StyleItemType.PolygonSymbol; } projectStyleItem.UpdateItem(s); } catch (Exception ex3) { } } }); } // end foreach if (string.IsNullOrEmpty(stylxUpdatedNames)) { string stylxs = string.Join(";", stylxFiles); ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Could not find any styles: " + stylxs + " in Project"); } else { ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Stylx Update DONE, styles updated:" + stylxUpdatedNames); } } // OnClick