protected override async void OnClick() { MapView mapvView = MapView.Active; if (mapvView == null) { return; } // get the Fire Stations layer FeatureLayer layer = mapvView.Map.GetLayersAsFlattenedList(). OfType <FeatureLayer>().FirstOrDefault(l => l.Name == "Fire Stations"); if (layer == null) { return; } await QueuedTask.Run(() => { //get the CIM layer definition var layerDef = layer.GetDefinition() as CIMFeatureLayer; //set new template values var myTemplateDef = new CIMFeatureTemplate(); myTemplateDef.Name = "My CIM template"; myTemplateDef.Description = "some description"; myTemplateDef.WriteTags(new[] { "Point", "TesterTag" }); // set some default attributes myTemplateDef.DefaultValues = new Dictionary <string, object>(); myTemplateDef.DefaultValues.Add("City", "Portland"); // set the default construction tool myTemplateDef.SetDefaultToolDamlID("esri_editing_SketchPointTool"); // remove construction tools from being available with this template List <string> filter = new List <string>(); // guid = esri_editing_ConstructPointsAlongLineCommand filter.Add("BCCF295A-9C64-4ADC-903E-62D827C10EF7"); myTemplateDef.ToolFilter = filter.ToArray(); //get all templates on this layer // NOTE - layerDef.FeatureTemplates could be null // if Create Features window hasn't been opened var layerTemplates = layerDef.FeatureTemplates?.ToList(); if (layerTemplates == null) { layerTemplates = new List <CIMEditingTemplate>(); } //add the new template to the layer template list layerTemplates.Add(myTemplateDef); //update the layerdefinition with the templates layerDef.FeatureTemplates = layerTemplates.ToArray(); // check the AutoGenerateFeatureTemplates flag, // set to false so our changes will stick if (layerDef.AutoGenerateFeatureTemplates) { layerDef.AutoGenerateFeatureTemplates = false; } //and commit layer.SetDefinition(layerDef); }); }
protected async override void OnClick() { CIMFeatureTemplate cimFT; List <CIMFeatureTemplate> list = new List <CIMFeatureTemplate>(); var ps = new ArcGIS.Desktop.Framework.Threading.Tasks.CancelableProgressorSource("Importing feature templates", "Canceled"); await QueuedTask.Run(() => { InitializeLibrarian(); // browse file dialog var ofd = new OpenFileDialog { Filter = "xml files (*.xml)|*.xml", RestoreDirectory = true, Multiselect = false }; if (ofd.ShowDialog() == true) { var doc = XDocument.Load(ofd.FileName); var elements = from el in doc.Descendants("Children").Descendants("Children").Where(node => node.Elements("Name").Any()) select new { eName = el.Element("Name").Value, eSIC = el.Element("SIC").Value }; foreach (var item in elements) { var s = _librarian.MakeSymbol("2525C", item.eSIC); cimFT = new CIMFeatureTemplate(); switch (s.GeometryType) { case JointMilitarySymbologyLibrary.GeometryType.POINT: cimFT.Tags = "Point"; cimFT.ToolProgID = "2a8b3331-5238-4025-972e-452a69535b06"; break; case JointMilitarySymbologyLibrary.GeometryType.LINE: // JointMilitarySymbologyLibrary only works with points cimFT.Tags = "Line"; break; case JointMilitarySymbologyLibrary.GeometryType.AREA: // JointMilitarySymbologyLibrary only work with points cimFT.Tags = "Polygon"; break; default: break; } cimFT.Name = item.eName; cimFT.DefaultValues = new Dictionary <string, object> { { "identity", s.SIDC.PartAString.Substring(2, 2) }, { "context", s.SIDC.PartAString.Substring(6, 1) }, { "symbolset", s.SIDC.PartAString.Substring(4, 2) }, { "entity", s.SIDC.PartBString.Substring(0, 6) } }; list.Add(cimFT); } } }); if (MapView.Active != null && list.Any()) { // get toc highlighted layers var selLayers = MapView.Active.GetSelectedLayers(); // retrieve the first one Layer layer = selLayers.FirstOrDefault(); if (layer != null) { // find the CIM and serialize it await QueuedTask.Run(() => { if (layer is FeatureLayer) { AddMatchingSymbolSetsToLayer(layer, list); } else if (layer is GroupLayer) { var gl = layer as GroupLayer; var layerList = gl.GetLayersAsFlattenedList(); foreach (var layerItem in layerList) { if (layerItem is FeatureLayer) { AddMatchingSymbolSetsToLayer(layerItem, list); } } } }, ps.Progressor); } } }
protected async override void OnClick() { CIMFeatureTemplate cimFT; List<CIMFeatureTemplate> list = new List<CIMFeatureTemplate>(); var ps = new ArcGIS.Desktop.Framework.Threading.Tasks.CancelableProgressorSource("Importing feature templates", "Canceled"); await QueuedTask.Run(() => { InitializeLibrarian(); // browse file dialog var ofd = new OpenFileDialog { Filter = "xml files (*.xml)|*.xml", RestoreDirectory = true, Multiselect = false }; if (ofd.ShowDialog() == true) { var doc = XDocument.Load(ofd.FileName); var elements = from el in doc.Descendants("Children").Descendants("Children").Where(node => node.Elements("Name").Any()) select new { eName = el.Element("Name").Value, eSIC = el.Element("SIC").Value }; foreach (var item in elements) { var s = _librarian.MakeSymbol("2525C", item.eSIC); cimFT = new CIMFeatureTemplate(); switch(s.GeometryType) { case JointMilitarySymbologyLibrary.GeometryType.POINT: cimFT.Tags = "Point"; cimFT.ToolProgID = "2a8b3331-5238-4025-972e-452a69535b06"; break; case JointMilitarySymbologyLibrary.GeometryType.LINE: // JointMilitarySymbologyLibrary only works with points cimFT.Tags = "Line"; break; case JointMilitarySymbologyLibrary.GeometryType.AREA: // JointMilitarySymbologyLibrary only work with points cimFT.Tags = "Polygon"; break; default: break; } cimFT.Name = item.eName; cimFT.DefaultValues = new Dictionary<string, object> { {"identity",s.SIDC.PartAString.Substring(2,2)}, {"context", s.SIDC.PartAString.Substring(6,1)}, {"symbolset", s.SIDC.PartAString.Substring(4,2)}, {"entity", s.SIDC.PartBString.Substring(0,6)} }; list.Add(cimFT); } } }); if (MapView.Active != null && list.Any()) { // get toc highlighted layers var selLayers = MapView.Active.GetSelectedLayers(); // retrieve the first one Layer layer = selLayers.FirstOrDefault(); if (layer != null) { // find the CIM and serialize it await QueuedTask.Run(() => { if (layer is FeatureLayer) { AddMatchingSymbolSetsToLayer(layer, list); } else if (layer is GroupLayer) { var gl = layer as GroupLayer; var layerList = gl.GetLayersAsFlattenedList(); foreach (var layerItem in layerList) { if (layerItem is FeatureLayer) { AddMatchingSymbolSetsToLayer(layerItem, list); } } } }, ps.Progressor); } } }