private Task AddStyleItemToStyle(StyleProjectItem styleProjectItem, CIMPolygonSymbol cimPolygonSymbol) { return(QueuedTask.Run(() => { if (styleProjectItem == null || cimPolygonSymbol == null) { throw new System.ArgumentNullException(); } SymbolStyleItem symbolStyleItem = new SymbolStyleItem()//define the symbol { Symbol = cimPolygonSymbol, ItemType = StyleItemType.PolygonSymbol, Category = "BuildingFacade", Name = SelectedRulePackage.Name, Key = SelectedRulePackage.Name, Tags = $"BuildingStyle, {SelectedRulePackage.Title}" }; //Does style already contain the styleItem? SymbolStyleItem item = (SymbolStyleItem)_styleProjectItem?.LookupItem(symbolStyleItem.ItemType, symbolStyleItem.Key); if (item == null) { styleProjectItem.AddItem(symbolStyleItem); } })); }
private void UpdateColorLocking(StyleProjectItem style, StyleItemType type) { IList <SymbolStyleItem> items = style.SearchSymbols(type, String.Empty); foreach (var item in items) { var symbol = item.GetObject() as CIMMultiLayerSymbol; if (symbol == null) { continue; } if (item.Category.IndexOf("Frame") == 0) { if (symbol is CIMPointSymbol) { SetFramePrimitiveNames(symbol as CIMPointSymbol, item.Key); } } else if (item.Category.IndexOf("Main Icon") != -1 || item.Category.IndexOf("Modifier 1") != -1 || item.Category.IndexOf("Modifier 2") != -1) { SetIconPrimitiveNames(symbol as CIMPointSymbol, true); } // update the symbol item.SetObject(symbol); style.UpdateItem(item); } }
static public bool IsStyleEditable(StyleProjectItem style) { if (style == null) { return(false); } if (!style.IsCurrent) { ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show( "Style is not current", "Check Style", MessageBoxButton.OK, MessageBoxImage.Exclamation); return(false); } if (style.IsReadOnly) { ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show( "Style is read only", "Check Style", MessageBoxButton.OK, MessageBoxImage.Exclamation); return(false); } return(true); }
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 colorRamps = await style.SearchColorRampsAsync("HeatMap"); 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 renderer = new CIMHeatMapRenderer() { ColorScheme = colorRampItem.ColorRamp, Field = "height", Radius = 25, RendererQuality = 5, Heading = "Height", MinLabel = "Sparse", MaxLabel = "Dense" }; //Update the feature layer renderer layer.SetRenderer(renderer); }); }
public async Task ApplyColorRampAsync(FeatureLayer featureLayer, string[] fields) { StyleProjectItem style = Project.Current.GetItems <StyleProjectItem>().FirstOrDefault(s => s.Name == "ColorBrewer Schemes (RGB)"); if (style == null) { return; } var colorRampList = await QueuedTask.Run(() => style.SearchColorRamps("Red-Gray (10 Classes)")); if (colorRampList == null || colorRampList.Count == 0) { return; } CIMColorRamp cimColorRamp = null; CIMRenderer renderer = null; await QueuedTask.Run(() => { cimColorRamp = colorRampList[0].ColorRamp; var rendererDef = new UniqueValueRendererDefinition(fields, null, cimColorRamp); renderer = featureLayer?.CreateRenderer(rendererDef); featureLayer?.SetRenderer(renderer); }); }
internal static CIMColorRamp GetColorRamp() { StyleProjectItem style = Project.Current.GetItems<StyleProjectItem>().FirstOrDefault(s => s.Name == "ArcGIS Colors"); if (style == null) return null; var colorRampList = style.SearchColorRamps("Heat Map 4 - Semitransparent"); if (colorRampList == null || colorRampList.Count == 0) return null; return colorRampList[0].ColorRamp; }
public Task <IList <ScaleBarStyleItem> > GetScaleBarsFromStyleAsync(StyleProjectItem style, string searchString) { if (style == null) { throw new System.ArgumentNullException(); } //Search for scale bars return(QueuedTask.Run(() => style.SearchScaleBars(searchString))); }
public async Task <IList <ColorStyleItem> > GetColorsFromStyleAsync(StyleProjectItem style, string searchString) { if (style == null) { throw new System.ArgumentNullException(); } //Search for colors return(await QueuedTask.Run(() => style.SearchColors(searchString))); }
public Task <IList <NorthArrowStyleItem> > GetNorthArrowsFromStyleAsync(StyleProjectItem style, string searchString) { if (style == null) { throw new System.ArgumentNullException(); } //Search for north arrows return(QueuedTask.Run(() => style.SearchNorthArrows(searchString))); }
//Pass in the full path to the style file on disk public async Task <bool> IsCurrent(string stylePath) { //Add the style to the current project await QueuedTask.Run(() => StyleHelper.AddStyle(Project.Current, stylePath)); StyleProjectItem style = Project.Current.GetItems <StyleProjectItem>().First(x => x.Path == stylePath); //returns true if style matches the current Pro version return(style.IsCurrent); }
//Pass in the full path to the style file on disk public async Task <bool> IsReadOnly(string stylePath) { //Add the style to the current project await QueuedTask.Run(() => StyleHelper.AddStyle(Project.Current, stylePath)); StyleProjectItem style = Project.Current.GetItems <StyleProjectItem>().First(x => x.Path == stylePath); //returns true if style is read-only return(style.IsReadOnly); }
public async Task <IList <SymbolStyleItem> > GetPolygonSymbolsFromStyleAsync(StyleProjectItem style, string searchString) { if (style == null) { throw new System.ArgumentNullException(); } //Search for polygon symbols return(await QueuedTask.Run(() => style.SearchSymbols(StyleItemType.PolygonSymbol, searchString))); }
//Pass in the full path to the style file on disk public async Task <bool> CanUpgradeStyleAsync(string stylePath) { //Add the style to the current project await QueuedTask.Run(() => StyleHelper.AddStyle(Project.Current, stylePath)); StyleProjectItem style = Project.Current.GetItems <StyleProjectItem>().First(x => x.Path == stylePath); //returns true if style can be upgraded return(style.CanUpgrade); }
protected MilitarySymbolDockpaneViewModel() { //Get Military Symbol Style Install Path string installPath = (string)Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\ESRI\ArcGISPro\", "InstallDir", null); if (installPath == null || installPath == "") { //Try to get the install path from current user instead of local machine installPath = (string)Registry.GetValue(@"HKEY_CURRENT_USER\SOFTWARE\ESRI\ArcGISPro\", "InstallDir", null); } if (installPath != null) { _mil2525dStyleFullFilePath = Path.Combine(installPath, _mil2525dRelativePath); } ArcGIS.Desktop.Core.Events.ProjectOpenedEvent.Subscribe(async(args) => { //Add military style to project Task <StyleProjectItem> getMilitaryStyle = GetMilitaryStyleAsync(); _militaryStyleItem = await getMilitaryStyle; }); ArcGIS.Desktop.Framework.Events.ActiveToolChangedEvent.Subscribe(OnActiveToolChanged); //Create locks for variables that are updated in worker threads BindingOperations.EnableCollectionSynchronization(MilitaryFieldsInspectorModel.IdentityDomainValues, _identityLock); BindingOperations.EnableCollectionSynchronization(MilitaryFieldsInspectorModel.EcholonDomainValues, _echelonLock); BindingOperations.EnableCollectionSynchronization(MilitaryFieldsInspectorModel.StatusesDomainValues, _statusesLock); BindingOperations.EnableCollectionSynchronization(MilitaryFieldsInspectorModel.OperationalConditionAmplifierDomainValues, _operationalConditionAmplifierLock); BindingOperations.EnableCollectionSynchronization(MilitaryFieldsInspectorModel.MobilityDomainValues, _mobilityLock); BindingOperations.EnableCollectionSynchronization(MilitaryFieldsInspectorModel.TfFdHqDomainValues, _tfFdHqLock); BindingOperations.EnableCollectionSynchronization(MilitaryFieldsInspectorModel.ContextDomainValues, _contextLock); BindingOperations.EnableCollectionSynchronization(MilitaryFieldsInspectorModel.Modifier1DomainValues, _modifier1Lock); BindingOperations.EnableCollectionSynchronization(MilitaryFieldsInspectorModel.Modifier2DomainValues, _modifier2Lock); BindingOperations.EnableCollectionSynchronization(MilitaryFieldsInspectorModel.ReinforcedDomainValues, _reinforcedLock); BindingOperations.EnableCollectionSynchronization(MilitaryFieldsInspectorModel.ReliabilityDomainValues, _reliabilityLock); BindingOperations.EnableCollectionSynchronization(MilitaryFieldsInspectorModel.CredibilityDomainValues, _credibilityLock); //Set up Commands SearchResultCommand = new RelayCommand(SearchStylesAsync, param => true); GoToTabCommand = new RelayCommand(GoToTab, param => true); //ActivateMapToolCommand = new RelayCommand(ActivateCoordinateMapTool, param => true); AddCoordinateToMapCommand = new RelayCommand(CreateNewFeatureAsync, CanCreatePolyFeatureFromCoordinates); ActivateAddToMapToolCommand = new RelayCommand(ActivateDrawFeatureSketchTool, param => true); _symbolAttributeSet.DateTimeValid = DateTime.Now; _symbolAttributeSet.DateTimeExpired = DateTime.Now; IsStyleItemSelected = false; PolyCoordinates = new ObservableCollection <CoordinateObject>(); SelectedStyleTags = new ObservableCollection <string>(); _progressDialog = new ProgressDialog("Searching..."); }
private async Task UpdateColorLocking() { StyleProjectItem style = await StyleUtil.GetStyleItem(_dictionaryPath); if (!StyleUtil.IsStyleEditable(style)) { return; } await _UpdateColorLocking(style); }
//style management #region ProSnippet Group: Style Management #endregion public void GetStyleInProjectByName() { #region How to get a style in project by name //Get all styles in the project var ProjectStyles = Project.Current.GetItems <StyleProjectItem>(); //Get a specific style in the project by name StyleProjectItem style = ProjectStyles.First(x => x.Name == "NameOfTheStyle"); #endregion }
public async Task <IList <ColorRampStyleItem> > GetColorRampsFromStyleAsync(StyleProjectItem style, string searchString) { //StyleProjectItem can be "ColorBrewer Schemes (RGB)", "ArcGIS 2D"... if (style == null) { throw new System.ArgumentNullException(); } //Search for color ramps //Color Ramp searchString can be "Spectral (7 Classes)", "Pastel 1 (3 Classes)", "Red-Gray (10 Classes)".. return(await QueuedTask.Run(() => style.SearchColorRamps(searchString))); }
/// <summary> /// Adds a styleitem to a style. /// </summary> /// <param name="styleProjectItem"></param> /// <param name="cimSymbolStyleItem"></param> /// <returns></returns> private Task AddStyleItemToStyle(StyleProjectItem styleProjectItem, SymbolStyleItem cimSymbolStyleItem) { return(QueuedTask.Run(() => { if (styleProjectItem == null || cimSymbolStyleItem == null) { return; } styleProjectItem.AddItem(cimSymbolStyleItem); })); }
public Task AddStyleItemAsync(StyleProjectItem style, StyleItem itemToAdd) { return(QueuedTask.Run(() => { if (style == null || itemToAdd == null) { throw new System.ArgumentNullException(); } //Add the item to style style.AddItem(itemToAdd); })); }
public Task RemoveStyleItemAsync(StyleProjectItem style, StyleItem itemToRemove) { return(QueuedTask.Run(() => { if (style == null || itemToRemove == null) { throw new System.ArgumentNullException(); } //Remove the item from style style.RemoveItem(itemToRemove); })); }
//symbol search #region How to search for a specific item in a style public Task <SymbolStyleItem> GetSymbolFromStyleAsync(StyleProjectItem style, string key) { return(QueuedTask.Run(() => { if (style == null) { throw new System.ArgumentNullException(); } //Search for a specific point symbol in style SymbolStyleItem item = (SymbolStyleItem)style.LookupItem(StyleItemType.PointSymbol, key); return item; })); }
static public Dictionary <string, StyleItem> ReadSymbolItems(StyleProjectItem style, StyleItemType itemType) { Dictionary <string, StyleItem> items = new Dictionary <string, StyleItem>(); IList <SymbolStyleItem> pointItems = style.SearchSymbols(itemType, ""); foreach (var item in pointItems) { if (!items.ContainsKey(item.Key)) { items.Add(item.Key, item); } } return(items); }
private async Task _UpdateColorLocking(StyleProjectItem style) { _updatedSymbols = 0; await QueuedTask.Run(() => { UpdateColorLocking(style, StyleItemType.PointSymbol); UpdateColorLocking(style, StyleItemType.LineSymbol); UpdateColorLocking(style, StyleItemType.PolygonSymbol); }); ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show( "Merge Complete: " + style + "\nNumber of Symbols Updated: " + _updatedSymbols, "Set Color Override", MessageBoxButton.OK, MessageBoxImage.Exclamation); }
static public async Task RemoveStyleItem(string styleFileFullPath) { await QueuedTask.Run(() => { var styles = Project.Current.GetItems <StyleProjectItem>(); //Get the style in the project StyleProjectItem style = styles.FirstOrDefault(x => x.Path == styleFileFullPath); if (style != null) { // remove it, if it was found Project.Current.RemoveStyle(styleFileFullPath); } }); }
//Pass in the full path to the style file on disk public async Task <bool> UpgradeStyleAsync(string stylePath) { bool success = false; //Add the style to the current project await QueuedTask.Run(() => StyleHelper.AddStyle(Project.Current, stylePath)); StyleProjectItem style = Project.Current.GetItems <StyleProjectItem>().First(x => x.Path == stylePath); //Verify that style can be upgraded if (style.CanUpgrade) { success = await QueuedTask.Run(() => StyleHelper.UpgradeStyle(style)); } //return true if style was upgraded return(success); }
/// <summary> /// Adds a styleitem to a style. /// </summary> /// <param name="styleProjectItem"></param> /// <param name="cimSymbolStyleItem"></param> /// <returns></returns> private Task AddStyleItemToStyle(StyleProjectItem styleProjectItem, SymbolStyleItem cimSymbolStyleItem) { return(QueuedTask.Run(() => { if (styleProjectItem == null || cimSymbolStyleItem == null) { return; } try { styleProjectItem.AddItem(cimSymbolStyleItem); } catch (Exception ex) { } })); }
protected override Task InitializeAsync() { return(QueuedTask.Run(() => { //Search for symbols in the selected style StyleProjectItem si = Project.Current.GetItems <StyleProjectItem>().FirstOrDefault(); if (si != null) { var lstStyleItems = si.SearchSymbols(StyleItemType.PointSymbol, string.Empty).Select((s) => s as StyleItem); RunOnUIThread(() => { _pickerStyleItems = new ObservableCollection <StyleItem>(); _pickerStyleItems.AddRange(lstStyleItems); NotifyPropertyChanged(() => PickerStyleItems); }); } })); }
/// <summary> /// Adds a styleitem to a style. /// </summary> /// <param name="styleProjectItem"></param> /// <param name="cimSymbolStyleItem"></param> /// <returns></returns> private Task AddStyleItemToStyle(StyleProjectItem styleProjectItem, SymbolStyleItem cimSymbolStyleItem) { return(QueuedTask.Run(() => { if (styleProjectItem == null || cimSymbolStyleItem == null) { return; } try { styleProjectItem.AddItem(cimSymbolStyleItem); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine($@"Error in AddStyleItemToStyle: {ex.ToString()}"); } })); }
/// <summary> /// Adds a styleitem to a style. /// </summary> /// <param name="styleProjectItem"></param> /// <param name="cimSymbolStyleItem"></param> /// <returns></returns> private Task AddStyleItemToStyle(StyleProjectItem styleProjectItem, SymbolStyleItem cimSymbolStyleItem) { return(QueuedTask.Run(() => { if (styleProjectItem == null || cimSymbolStyleItem == null || styleProjectItem.IsReadOnly) { return; } try { styleProjectItem.AddItem(cimSymbolStyleItem); } catch (Exception ex) { MessageBox.Show($"{ex.Message}. Unable to add {cimSymbolStyleItem.Name}. Key is {cimSymbolStyleItem.Key}"); } })); }
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)); }); }
private async void SearchStylesAsync(object parameter) { //Make sure that military style is in project if (!IsStyleInProject() || _militaryStyleItem == null) { //Add military style to project Task<StyleProjectItem> getMilitaryStyle = GetMilitaryStyleAsync(); _militaryStyleItem = await getMilitaryStyle; } //Clear for new search if (_styleItems.Count != 0) _styleItems.Clear(); ResultCount = "---"; _progressDialog.Show(); await SearchSymbols(); //Check for Schema again Task<bool> isEnabledMethod = ProSymbolEditorModule.Current.MilitaryOverlaySchema.ShouldAddInBeEnabledAsync(); bool enabled = await isEnabledMethod; NotifyPropertyChanged(() => StyleItems); }
protected MilitarySymbolDockpaneViewModel() { //Get Military Symbol Style Install Path string installPath = (string)Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\ESRI\ArcGISPro\", "InstallDir", null); if (installPath == null || installPath == "") { //Try to get the install path from current user instead of local machine installPath = (string)Registry.GetValue(@"HKEY_CURRENT_USER\SOFTWARE\ESRI\ArcGISPro\", "InstallDir", null); } if (installPath != null) { _mil2525dStyleFullFilePath = Path.Combine(installPath, _mil2525dRelativePath); } ArcGIS.Desktop.Core.Events.ProjectOpenedEvent.Subscribe(async (args) => { //Add military style to project Task<StyleProjectItem> getMilitaryStyle = GetMilitaryStyleAsync(); _militaryStyleItem = await getMilitaryStyle; //Reset things this.SelectedStyleItem = null; this.IsStyleItemSelected = false; this.IsFavoriteItemSelected = false; this.StyleItems.Clear(); this.SelectedTabIndex = 0; this.ResultCount = "---"; this.SearchString = ""; _symbolAttributeSet.ResetAttributes(); SelectedStyleTags.Clear(); }); ArcGIS.Desktop.Framework.Events.ActiveToolChangedEvent.Subscribe(OnActiveToolChanged); ArcGIS.Desktop.Mapping.Events.MapSelectionChangedEvent.Subscribe(OnMapSelectionChanged); //Create locks for variables that are updated in worker threads BindingOperations.EnableCollectionSynchronization(MilitaryFieldsInspectorModel.IdentityDomainValues, _lock); BindingOperations.EnableCollectionSynchronization(MilitaryFieldsInspectorModel.EcholonDomainValues, _lock); BindingOperations.EnableCollectionSynchronization(MilitaryFieldsInspectorModel.StatusDomainValues, _lock); BindingOperations.EnableCollectionSynchronization(MilitaryFieldsInspectorModel.OperationalConditionAmplifierDomainValues, _lock); BindingOperations.EnableCollectionSynchronization(MilitaryFieldsInspectorModel.MobilityDomainValues, _lock); BindingOperations.EnableCollectionSynchronization(MilitaryFieldsInspectorModel.TfFdHqDomainValues, _lock); BindingOperations.EnableCollectionSynchronization(MilitaryFieldsInspectorModel.ContextDomainValues, _lock); BindingOperations.EnableCollectionSynchronization(MilitaryFieldsInspectorModel.Modifier1DomainValues, _lock); BindingOperations.EnableCollectionSynchronization(MilitaryFieldsInspectorModel.Modifier2DomainValues, _lock); BindingOperations.EnableCollectionSynchronization(MilitaryFieldsInspectorModel.ReinforcedDomainValues, _lock); BindingOperations.EnableCollectionSynchronization(MilitaryFieldsInspectorModel.ReliabilityDomainValues, _lock); BindingOperations.EnableCollectionSynchronization(MilitaryFieldsInspectorModel.CredibilityDomainValues, _lock); BindingOperations.EnableCollectionSynchronization(MilitaryFieldsInspectorModel.CountryCodeDomainValues, _lock); //Set up Commands SearchResultCommand = new RelayCommand(SearchStylesAsync, param => true); GoToTabCommand = new RelayCommand(GoToTab, param => true); //ActivateMapToolCommand = new RelayCommand(ActivateCoordinateMapTool, param => true); AddCoordinateToMapCommand = new RelayCommand(CreateNewFeatureAsync, CanCreatePolyFeatureFromCoordinates); ActivateAddToMapToolCommand = new RelayCommand(ActivateDrawFeatureSketchTool, param => true); SaveEditsCommand = new RelayCommand(SaveEdits, param => true); CopyImageToClipboardCommand = new RelayCommand(CopyImageToClipboard, param => true); SaveImageToCommand = new RelayCommand(SaveImageAs, param => true); SaveSymbolFileCommand = new RelayCommand(SaveSymbolAsFavorite, param => true); DeleteFavoriteSymbolCommand = new RelayCommand(DeleteFavoriteSymbol, param => true); SaveFavoritesFileAsCommand = new RelayCommand(SaveFavoritesAsToFile, param => true); ImportFavoritesFileCommand = new RelayCommand(ImportFavoritesFile, param => true); SelectToolCommand = new RelayCommand(ActivateSelectTool, param => true); ShowAboutWindowCommand = new RelayCommand(ShowAboutWindow, param => true); _symbolAttributeSet.LabelAttributes.DateTimeValid = null; _symbolAttributeSet.LabelAttributes.DateTimeExpired = null; IsStyleItemSelected = false; PolyCoordinates = new ObservableCollection<CoordinateObject>(); Favorites = new ObservableCollection<SymbolAttributeSet>(); SelectedStyleTags = new ObservableCollection<string>(); SelectedFavoriteStyleTags = new ObservableCollection<string>(); SelectedFeaturesCollection = new ObservableCollection<SelectedFeature>(); BindingOperations.EnableCollectionSynchronization(SelectedFeaturesCollection, _lock); _progressDialog = new ProgressDialog("Loading..."); _symbolAttributeSet.StandardVersion = "2525D"; //Load saved favorites _favoritesFilePath = System.IO.Path.Combine(ProSymbolUtilities.AddinAssemblyLocation(), "SymbolFavorites.json"); LoadAllFavoritesFromFile(); }