protected override async void OnClick() { Project project = ProjectModule.CurrentProject; StringBuilder sb = new StringBuilder(); sb.AppendLine("Unable to determine Bookmark count"); MapProjectItem mapItem = project.GetMaps().FirstOrDefault(pi => pi.Name == Module1.MapSelected); if (mapItem != null) { var map = MappingModule.FindMap(mapItem.Path); if (map == null) //map has not been loaded yet { return; } var bmks = await map.QueryBookmarksAsync(); //get the bookmarks for each map. if (bmks != null) { sb.Clear(); sb.AppendLine(mapItem.Name + " map has " + bmks.Count + " bookmarks\n"); } } System.Windows.MessageBox.Show(sb.ToString(), "Bookmark Count"); }
/// <summary> /// Creates a new mapviewpane (and a map as well if need-be) or closes the mapviewpane if it already exists /// </summary> /// <param name="selectedMapview"></param> private async void CreateAndViewMapPane(MapviewItem selectedMapview) { try { System.Diagnostics.Debug.WriteLine("CreateAndViewMapPane start"); var newMapName = selectedMapview.MapviewName; { var mapPanes = ProApp.Panes.OfType <IMapPane>(); foreach (Pane pane in mapPanes) { if (pane.Caption == newMapName) { ProApp.Panes.ClosePane(pane.InstanceID); UpdateHasMapView(selectedMapview.MapName, false); return; } } } var newExtent = selectedMapview.Extent; // we need to find or create a map with a given selectedMapview.MapviewName // 1: does the map already exist? MapProjectItem mapProjItem = Project.Current.GetItems <MapProjectItem>().FirstOrDefault(item => item.Name.Equals(newMapName)); if (mapProjItem != null) { // we found the existing MapProjectItem var mapPanes = ProApp.Panes.OfType <IMapPane>(); foreach (Pane pane in mapPanes) { if (pane.Caption == newMapName) { ProApp.Panes.ClosePane(pane.InstanceID); UpdateHasMapView(selectedMapview.MapName, false); return; } } //Opening the map in a mapview await QueuedTask.Run(async() => { await ProApp.Panes.CreateMapPaneAsync(mapProjItem.GetMap()); }); UpdateHasMapView(selectedMapview.MapName, true); } else { await CreateMapThruCopy(newMapName, newExtent); UpdateHasMapView(selectedMapview.MapName, true); } } catch (Exception ex) { MessageBox.Show($@"An error occurred in CreateAndViewMapPane: {ex.ToString()}"); } finally { System.Diagnostics.Debug.WriteLine("CreateAndViewMapPane end"); } }
protected override void OnClick() { // get the first map item MapProjectItem item = ProjectModule.CurrentProject.GetMaps().FirstOrDefault(); if (item == null) { return; } // fimd the map Map map = MappingModule.FindMap(item.Path); if (map == null) { return; } bool bAlreadyOpen = false; // see if its already open //IList<IMapPane> mapPanes = MappingModule.GetMapPanes(map); //if ((mapPanes != null) && (mapPanes.Count > 0)) // bAlreadyOpen = true; if (!bAlreadyOpen) { var mapPane = MappingModule.OpenMapView(item.Path, item.ViewingMode); } }
// Step 2 OnProjectCollectionChanged event /// <summary> /// Project item changed event. Fired when a project item is added or removed from the project. /// </summary> /// <param name="args"></param> private void OnProjectCollectionChanged(ArcGISProjectItemsChangedEventArgs args) { if (args == null) { return; } if (_allMaps == null) { return; } // don't assume already on the dispatch thread... System.Windows.Application.Current.Dispatcher.BeginInvoke((Action)(() => { // new project item was added if (args.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add) { // only care about map project item if (args.ProjectItem is MapProjectItem) { // projectItem.Path contains the URI of the item. Our list of views has this attribute so try and match the new addition. // does a map with the uri already exist? MapProjectItem map = _allMaps.FirstOrDefault(m => m.Url == args.ProjectItem.Path); // one cannot be found; so add it to our list if (map == null) { _allMaps.Add(args.ProjectItem as MapProjectItem); NotifyPropertyChanged(() => AllMaps); } } } // project item was removed else if (args.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Remove) { // only care about map project item if (args.ProjectItem is MapProjectItem) { // does a map with the same uri and type already exist in our list MapProjectItem map = _allMaps.FirstOrDefault(m => m.Url == args.ProjectItem.Path); // found a match; so remove it from our list if (map != null) { _allMaps.Remove(args.ProjectItem as MapProjectItem); NotifyPropertyChanged(() => AllMaps); } } } })); }
/// <summary> /// Takes a map as a template and makes a copy of that map with a given new map name and extent /// </summary> /// <param name="newMapName"></param> /// <param name="newExtent"></param> /// <returns></returns> private async Task CreateMapThruCopy(string newMapName, Envelope newExtent) { // we have to create a new Map from any existing Map and then // add it as MapProjectItem item MapProjectItem mapTemplateProjItem = Project.Current.GetItems <MapProjectItem>().FirstOrDefault(); var newMapPane = await QueuedTask.Run(async() => { var mapTemplate = mapTemplateProjItem.GetMap(); var theNewMap = MapFactory.Instance.CopyMap(mapTemplate); var defMap = theNewMap.GetDefinition(); defMap.DefaultExtent = newExtent; defMap.Name = newMapName; theNewMap.SetDefinition(defMap); return(await ProApp.Panes.CreateMapPaneAsync(theNewMap)); }); }
public static async Task AddMapToNewLayout(Layout layout) { await QueuedTask.Run(() => { //Build 2D envelope geometry Coordinate2D mf_ll = new Coordinate2D(1, 3.5); Coordinate2D mf_ur = new Coordinate2D(7.5, 9.5); Envelope mf_env = EnvelopeBuilder.CreateEnvelope(mf_ll, mf_ur); //Reference map, create MF and add to layout MapProjectItem mapPrjItem = Project.Current.GetItems <MapProjectItem>().FirstOrDefault(item => item.Name.Equals("Map")); Map mfMap = mapPrjItem.GetMap(); MapFrame mfElm = LayoutElementFactory.Instance.CreateMapFrame(layout, mf_env, mfMap); mfElm.SetName("My New Map Frame"); }); }
/// <summary> /// utility function to open and activate a map given the map url. /// </summary> /// <param name="url">unique map identifier</param> internal static async void OpenAndActivateMap(string url) { // find the map; returns null if map has never been opened in the Pro session Map map = MappingModule.FindMap(url); // default viewing mode MapViewingMode mode = MapViewingMode.Item2D; bool bAlreadyOpen = false; // if returns null - it has never been opened if (map == null) { // find the map mode (2d / 3d from the project items) MapProjectItem mapPI = ProjectModule.CurrentProject.GetMaps().FirstOrDefault(m => m.Path == url); if (mapPI != null) { mode = mapPI.ViewingMode; } } else { mode = map.ViewingMode; // see if its already open IList <IMapPane> mapPanes = MappingModule.GetMapPanes(map); if ((mapPanes != null) && (mapPanes.Count > 0)) { bAlreadyOpen = true; // activate the first one Pane pane = mapPanes[0] as Pane; if (pane != FrameworkApplication.Panes.ActivePane) { pane.Activate(); } } } // open it with the correct mode if (!bAlreadyOpen) { var mapPane = MappingModule.OpenMapView(url, mode); await Utils.BlockUntil(() => mapPane.MapView != null && mapPane.MapView.ViewerID >= 0); } }
public static async Task <Map> FindOpenExistingMapAsync(string mapName) { return(await QueuedTask.Run(async() => { Map map = null; Project proj = Project.Current; //Finding the first project item with name matches with mapName MapProjectItem mpi = proj.GetItems <MapProjectItem>() .FirstOrDefault(m => m.Name.Equals(mapName, StringComparison.CurrentCultureIgnoreCase)); if (mpi != null) { map = mpi.GetMap(); //Opening the map in a mapview await ProApp.Panes.CreateMapPaneAsync(map); } return map; })); }
protected override async void OnClick() { // get the map container var container = ProjectModule.CurrentProject.GetProjectItemContainer <MapContainer>("Map"); if (container == null) { return; } // get the first item MapProjectItem item = container.GetProjectItems().FirstOrDefault(); if (item == null) { return; } // fimd the map Map map = MappingModule.FindMap(item.Path); if (map == null) { return; } // close if already open IList <IMapPane> mapPanes = MappingModule.GetMapPanes(map); if ((mapPanes != null) && (mapPanes.Count > 0)) { for (int idx = mapPanes.Count - 1; idx >= 0; idx--) { Pane pane = mapPanes[idx] as Pane; pane.Close(); } } // remove it from project await(ProjectModule.CurrentProject as IInternalGISProjectItem).RemoveProjectItemAsync("Map", item.Path); }
/// <summary> /// Gets the map from a project that matches a map name. /// </summary> /// <param name="project">The project in which the map resides.</param> /// <param name="mapName">The map name to identify the map.</param> /// <returns>A Task representing the map.</returns> private static Task <Map> GetMapFromProject(Project project, string mapName) { // Return null if either of the two parameters are invalid. if (project == null || string.IsNullOrEmpty(mapName)) { return(null); } // Find the first project item with name matches with mapName MapProjectItem mapProjItem = project.GetItems <MapProjectItem>().FirstOrDefault(item => item.Name.Equals(mapName, StringComparison.CurrentCultureIgnoreCase)); if (mapProjItem != null) { return(QueuedTask.Run <Map>(() => { return mapProjItem.GetMap(); }, Progressor.None)); } else { return(null); } }
/// <summary> /// Gets all the bookmarks from a Map Porject item /// </summary> /// <param name="mpi"></param> /// <returns></returns> private static async Task <IList <Bookmark> > GetBookmarksAsync(MapProjectItem mpi) { Map map = null; //use the map path to get the actual map (related to the item) map = MappingModule.FindMap(mpi.Path); if (map == null) { return(null); } //get the bookmarks associated with the map var bookmarks = await map.QueryBookmarksAsync(); if (bookmarks == null) { return(null); } else { return(bookmarks); } }
public static async Task <Map> SetDefaultMapNameAsync(string mapName) { return(await QueuedTask.Run(async() => { Map map = null; Project proj = Project.Current; //Finding the first project item with name matches with mapName MapProjectItem mpi = proj.GetItems <MapProjectItem>() .FirstOrDefault(m => m.Name.Equals(mapName, StringComparison.CurrentCultureIgnoreCase)); if (mpi != null) { map = mpi.GetMap(); } else { map = MapFactory.Instance.CreateMap(mapName, basemap: Basemap.None); await ProApp.Panes.CreateMapPaneAsync(map); } return map; })); }
protected override async void OnClick() { // find the first map item MapProjectItem item = ProjectModule.CurrentProject.GetMaps().FirstOrDefault(); if (item == null) { return; } // alternate example - find the map item using Name //IEnumerable<MapProjectItem> maps = ProjectModule.CurrentProject.GetMaps(); //item = ProjectModule.CurrentProject.GetMaps().FirstOrDefault(m => m.Name == "Layers"); // fimd the map Map map = MappingModule.FindMap(item.Path); if (map == null) { return; } // close if already open IList <IMapPane> mapPanes = MappingModule.GetMapPanes(map); if ((mapPanes != null) && (mapPanes.Count > 0)) { for (int idx = mapPanes.Count - 1; idx >= 0; idx--) { Pane pane = mapPanes[idx] as Pane; pane.Close(); } } // remove it from project await(ProjectModule.CurrentProject as IInternalGISProjectItem).RemoveProjectItemAsync("Map", item.Path); }
public void snippets_CreateLayoutElements() { LayoutView layoutView = LayoutView.Active; Layout layout = layoutView.Layout; #region Create point graphic with symbology //Create a simple 2D point graphic and apply an existing point style item as the symbology. //An alternative simple symbol is also provided below. This would completely elminate the 4 lines of code that reference a style. QueuedTask.Run(() => { //Build 2D point geometry Coordinate2D coord2D = new Coordinate2D(2.0, 10.0); //Reference a point symbol in a style StyleProjectItem ptStylePrjItm = Project.Current.GetItems <StyleProjectItem>().FirstOrDefault(item => item.Name == "ArcGIS 2D"); SymbolStyleItem ptSymStyleItm = ptStylePrjItm.SearchSymbols(StyleItemType.PointSymbol, "City Hall")[0]; CIMPointSymbol pointSym = ptSymStyleItm.Symbol as CIMPointSymbol; pointSym.SetSize(50); //Set symbolology, create and add element to layout //CIMPointSymbol pointSym = SymbolFactory.Instance.ConstructPointSymbol(ColorFactory.Instance.RedRGB, 25.0, SimpleMarkerStyle.Star); //Alternative simple symbol GraphicElement ptElm = LayoutElementFactory.Instance.CreatePointGraphicElement(layout, coord2D, pointSym); ptElm.SetName("New Point"); }); #endregion #region Create line graphic with symbology //Create a simple 2D line graphic and apply an existing line style item as the symbology. //An alternative simple symbol is also provided below. This would completely elminate the 4 lines of code that reference a style. QueuedTask.Run(() => { //Build 2d line geometry List <Coordinate2D> plCoords = new List <Coordinate2D>(); plCoords.Add(new Coordinate2D(1, 8.5)); plCoords.Add(new Coordinate2D(1.66, 9)); plCoords.Add(new Coordinate2D(2.33, 8.1)); plCoords.Add(new Coordinate2D(3, 8.5)); Polyline linePl = PolylineBuilder.CreatePolyline(plCoords); //Reference a line symbol in a style StyleProjectItem lnStylePrjItm = Project.Current.GetItems <StyleProjectItem>().FirstOrDefault(item => item.Name == "ArcGIS 2D"); SymbolStyleItem lnSymStyleItm = lnStylePrjItm.SearchSymbols(StyleItemType.LineSymbol, "Line with 2 Markers")[0]; CIMLineSymbol lineSym = lnSymStyleItm.Symbol as CIMLineSymbol; lineSym.SetSize(20); //Set symbolology, create and add element to layout //CIMLineSymbol lineSym = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlueRGB, 4.0, SimpleLineStyle.Solid); //Alternative simple symbol GraphicElement lineElm = LayoutElementFactory.Instance.CreateLineGraphicElement(layout, linePl, lineSym); lineElm.SetName("New Line"); }); #endregion #region Create rectangle graphic with simple symbology //Create a simple 2D rectangle graphic and apply simple fill and outline symbols. QueuedTask.Run(() => { //Build 2D envelope geometry Coordinate2D rec_ll = new Coordinate2D(1.0, 4.75); Coordinate2D rec_ur = new Coordinate2D(3.0, 5.75); Envelope rec_env = EnvelopeBuilder.CreateEnvelope(rec_ll, rec_ur); //Set symbolology, create and add element to layout CIMStroke outline = SymbolFactory.Instance.ConstructStroke(ColorFactory.Instance.BlackRGB, 5.0, SimpleLineStyle.Solid); CIMPolygonSymbol polySym = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.GreenRGB, SimpleFillStyle.DiagonalCross, outline); GraphicElement recElm = LayoutElementFactory.Instance.CreateRectangleGraphicElement(layout, rec_env, polySym); recElm.SetName("New Rectangle"); }); #endregion #region Create text element with basic font properties //Create a simple point text element and assign basic symbology as well as basic text settings. QueuedTask.Run(() => { //Build 2D point geometry Coordinate2D coord2D = new Coordinate2D(3.5, 10); //Set symbolology, create and add element to layout CIMTextSymbol sym = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.RedRGB, 32, "Arial", "Regular"); string textString = "Point text"; GraphicElement ptTxtElm = LayoutElementFactory.Instance.CreatePointTextGraphicElement(layout, coord2D, textString, sym); ptTxtElm.SetName("New Point Text"); //Change additional text properties ptTxtElm.SetAnchor(Anchor.CenterPoint); ptTxtElm.SetX(4.5); ptTxtElm.SetY(9.5); ptTxtElm.SetRotation(45); }); #endregion #region Create rectangle text with more advanced symbol settings //Create rectangle text with background and border symbology. Also notice how formatting tags are using within the text string. QueuedTask.Run(() => { //Build 2D polygon geometry List <Coordinate2D> plyCoords = new List <Coordinate2D>(); plyCoords.Add(new Coordinate2D(3.5, 7)); plyCoords.Add(new Coordinate2D(4.5, 7)); plyCoords.Add(new Coordinate2D(4.5, 6.7)); plyCoords.Add(new Coordinate2D(5.5, 6.7)); plyCoords.Add(new Coordinate2D(5.5, 6.1)); plyCoords.Add(new Coordinate2D(3.5, 6.1)); Polygon poly = PolygonBuilder.CreatePolygon(plyCoords); //Set symbolology, create and add element to layout CIMTextSymbol sym = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.GreyRGB, 10, "Arial", "Regular"); string text = "Some Text String that is really long and is <BOL>forced to wrap to other lines</BOL> so that we can see the effects." as String; GraphicElement polyTxtElm = LayoutElementFactory.Instance.CreatePolygonParagraphGraphicElement(layout, poly, text, sym); polyTxtElm.SetName("New Polygon Text"); //(Optionally) Modify paragraph border CIMGraphic polyTxtGra = polyTxtElm.Graphic; CIMParagraphTextGraphic cimPolyTxtGra = polyTxtGra as CIMParagraphTextGraphic; cimPolyTxtGra.Frame.BorderSymbol = new CIMSymbolReference(); cimPolyTxtGra.Frame.BorderSymbol.Symbol = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.GreyRGB, 1.0, SimpleLineStyle.Solid); polyTxtElm.SetGraphic(polyTxtGra); }); #endregion #region Create a new picture element with advanced symbol settings //Create a picture element and also set background and border symbology. QueuedTask.Run(() => { //Build 2D envelope geometry Coordinate2D pic_ll = new Coordinate2D(6, 1); Coordinate2D pic_ur = new Coordinate2D(8, 2); Envelope env = EnvelopeBuilder.CreateEnvelope(pic_ll, pic_ur); //Create and add element to layout string picPath = @"C:\Temp\WhitePass.jpg"; GraphicElement picElm = LayoutElementFactory.Instance.CreatePictureGraphicElement(layout, env, picPath); picElm.SetName("New Picture"); //(Optionally) Modify the border and shadow CIMGraphic picGra = picElm.Graphic; CIMPictureGraphic cimPicGra = picGra as CIMPictureGraphic; cimPicGra.Frame.BorderSymbol = new CIMSymbolReference(); cimPicGra.Frame.BorderSymbol.Symbol = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlueRGB, 2.0, SimpleLineStyle.Solid); cimPicGra.Frame.ShadowSymbol = new CIMSymbolReference(); cimPicGra.Frame.ShadowSymbol.Symbol = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.BlackRGB, SimpleFillStyle.Solid); picElm.SetGraphic(picGra); }); #endregion #region Create a map frame and zoom to a bookmark //Create a map frame and also sets its extent by zooming the the extent of an existing bookmark. QueuedTask.Run(() => { //Build 2D envelope geometry Coordinate2D mf_ll = new Coordinate2D(6.0, 8.5); Coordinate2D mf_ur = new Coordinate2D(8.0, 10.5); Envelope mf_env = EnvelopeBuilder.CreateEnvelope(mf_ll, mf_ur); //Reference map, create MF and add to layout MapProjectItem mapPrjItem = Project.Current.GetItems <MapProjectItem>().FirstOrDefault(item => item.Name.Equals("Map")); Map mfMap = mapPrjItem.GetMap(); MapFrame mfElm = LayoutElementFactory.Instance.CreateMapFrame(layout, mf_env, mfMap); mfElm.SetName("New Map Frame"); //Zoom to bookmark Bookmark bookmark = mfElm.Map.GetBookmarks().FirstOrDefault(b => b.Name == "Great Lakes"); mfElm.SetCamera(bookmark); }); #endregion #region Create a legend for a specifc map frame //Create a legend for an associated map frame. QueuedTask.Run(() => { //Build 2D envelope geometry Coordinate2D leg_ll = new Coordinate2D(6, 2.5); Coordinate2D leg_ur = new Coordinate2D(8, 4.5); Envelope leg_env = EnvelopeBuilder.CreateEnvelope(leg_ll, leg_ur); //Reference MF, create legend and add to layout MapFrame mapFrame = layout.FindElement("New Map Frame") as MapFrame; if (mapFrame == null) { ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Map frame not found", "WARNING"); return; } Legend legendElm = LayoutElementFactory.Instance.CreateLegend(layout, leg_env, mapFrame); legendElm.SetName("New Legend"); }); #endregion #region Creating group elements //Create an empty group element at the root level of the contents pane //Note: call within QueuedTask.Run() GroupElement grp1 = LayoutElementFactory.Instance.CreateGroupElement(layout); grp1.SetName("Group"); //Create a group element inside another group element //Note: call within QueuedTask.Run() GroupElement grp2 = LayoutElementFactory.Instance.CreateGroupElement(grp1); grp2.SetName("Group in Group"); #endregion Creating group elements { #region Create scale bar Coordinate2D llScalebar = new Coordinate2D(6, 2.5); MapFrame mapframe = layout.FindElement("New Map Frame") as MapFrame; //Note: call within QueuedTask.Run() LayoutElementFactory.Instance.CreateScaleBar(layout, llScalebar, mapframe); #endregion } #region How to search for scale bars in a style var arcgis_2d = Project.Current.GetItems <StyleProjectItem>().First(si => si.Name == "ArcGIS 2D"); QueuedTask.Run(() => { var scaleBarItems = arcgis_2d.SearchScaleBars("Double Alternating Scale Bar"); }); #endregion #region How to add a scale bar from a style to a layout var arcgis_2dStyle = Project.Current.GetItems <StyleProjectItem>().First(si => si.Name == "ArcGIS 2D"); QueuedTask.Run(() => { //Imperial Double Alternating Scale Bar //Metric Double Alternating Scale Bar //or just use empty string to list them all... var scaleBarItem = arcgis_2d.SearchScaleBars("Double Alternating Scale Bar").FirstOrDefault(); Coordinate2D coord2D = new Coordinate2D(10.0, 7.0); MapFrame myMapFrame = layout.FindElement("Map Frame") as MapFrame; LayoutElementFactory.Instance.CreateScaleBar(layout, coord2D, myMapFrame, scaleBarItem); }); #endregion #region Create NorthArrow Coordinate2D llNorthArrow = new Coordinate2D(6, 2.5); MapFrame mf = layout.FindElement("New Map Frame") as MapFrame; //Note: call within QueuedTask.Run() var northArrow = LayoutElementFactory.Instance.CreateNorthArrow(layout, llNorthArrow, mf); #endregion #region How to search for North Arrows in a style var arcgis_2dStyles = Project.Current.GetItems <StyleProjectItem>().First(si => si.Name == "ArcGIS 2D"); QueuedTask.Run(() => { var scaleBarItems = arcgis_2dStyles.SearchNorthArrows("ArcGIS North 13"); }); #endregion #region How to add a North Arrow from a style to a layout var arcgis2dStyles = Project.Current.GetItems <StyleProjectItem>().First(si => si.Name == "ArcGIS 2D"); QueuedTask.Run(() => { var northArrowStyleItem = arcgis2dStyles.SearchNorthArrows("ArcGIS North 13").FirstOrDefault(); Coordinate2D nArrow = new Coordinate2D(6, 2.5); MapFrame newFrame = layout.FindElement("New Map Frame") as MapFrame; //Note: call within QueuedTask.Run() var newNorthArrow = LayoutElementFactory.Instance.CreateNorthArrow(layout, nArrow, newFrame, northArrowStyleItem); }); #endregion #region Create dynamic text var title = @"<dyn type = ""page"" property = ""name"" />"; Coordinate2D llTitle = new Coordinate2D(6, 2.5); //Note: call within QueuedTask.Run() var titleGraphics = LayoutElementFactory.Instance.CreatePointTextGraphicElement(layout, llTitle, null) as TextElement; titleGraphics.SetTextProperties(new TextProperties(title, "Arial", 24, "Bold")); #endregion #region Create dynamic table QueuedTask.Run(() => { //Build 2D envelope geometry Coordinate2D tab_ll = new Coordinate2D(6, 2.5); Coordinate2D tab_ur = new Coordinate2D(12, 6.5); Envelope tab_env = EnvelopeBuilder.CreateEnvelope(tab_ll, tab_ur); MapFrame mapFrame = layout.FindElement("New Map Frame") as MapFrame; // get the layer MapProjectItem mapPrjItem = Project.Current.GetItems <MapProjectItem>().FirstOrDefault(item => item.Name.Equals("Map")); Map theMap = mapPrjItem?.GetMap(); var lyrs = theMap?.FindLayers("Inspection Point Layer", true); if (lyrs?.Count > 0) { Layer lyr = lyrs[0]; var table1 = LayoutElementFactory.Instance.CreateTableFrame(layout, tab_env, mapFrame, lyr, new string[] { "No", "Type", "Description" }); } }); #endregion }
public async void ContentSnippets2() { #region Create new project using Pro's default settings //Get Pro's default project settings. var defaultProjectSettings = Project.GetDefaultProjectSettings(); //Create a new project using the default project settings await Project.CreateAsync(defaultProjectSettings); #endregion #region New project using a custom template file //Settings used to create a new project CreateProjectSettings projectSettings = new CreateProjectSettings() { //Sets the project's name Name = "New Project", //Path where new project will be stored in LocationPath = @"C:\Data\NewProject", //Sets the project template that will be used to create the new project TemplatePath = @"C:\Data\MyProject1\CustomTemplate.aptx" }; //Create the new project await Project.CreateAsync(projectSettings); #endregion #region Create project using template available with ArcGIS Pro //Settings used to create a new project CreateProjectSettings proTemplateSettings = new CreateProjectSettings() { //Sets the project's name Name = "New Project", //Path where new project will be stored in LocationPath = @"C:\Data\NewProject", //Select which Pro template you like to use TemplateType = TemplateType.Catalog //TemplateType = TemplateType.LocalScene //TemplateType = TemplateType.GlobalScene //TemplateType = TemplateType.Map }; //Create the new project await Project.CreateAsync(proTemplateSettings); #endregion #region Open project //Opens an existing project or project package await Project.OpenAsync(@"C:\Data\MyProject1\MyProject1.aprx"); #endregion #region Current project //Gets the current project var project = Project.Current; #endregion #region Get location of current project //Gets the location of the current project; that is, the path to the current project file (*.aprx) string projectPath = Project.Current.URI; #endregion #region Get the project's default gdb path var projGDBPath = Project.Current.DefaultGeodatabasePath; #endregion #region Save project //Saves the project await Project.Current.SaveAsync(); #endregion #region SaveAs project //Saves a copy of the current project file (*.aprx) to the specified location with the specified file name, //then opens the new project file await Project.Current.SaveAsAsync(@"C:\Data\MyProject1\MyNewProject1.aprx"); #endregion #region Close project //A project cannot be closed using the ArcGIS Pro API. //A project is only closed when another project is opened, a new one is created, or the application is shutdown. #endregion #region Adds item to the current project //Adding a folder connection string folderPath = "@C:\\myDataFolder"; var folder = await QueuedTask.Run(() => { //Create the folder connection project item var item = ItemFactory.Instance.Create(folderPath) as IProjectItem; //If it is succesfully added to the project, return it otherwise null return(Project.Current.AddItem(item) ? item as FolderConnectionProjectItem : null); }); //Adding a Geodatabase: string gdbPath = "@C:\\myDataFolder\\myData.gdb"; var newlyAddedGDB = await QueuedTask.Run(() => { //Create the File GDB project item var item = ItemFactory.Instance.Create(gdbPath) as IProjectItem; //If it is succesfully added to the project, return it otherwise null return(Project.Current.AddItem(item) ? item as GDBProjectItem : null); }); #endregion #region How to add a new map to a project await QueuedTask.Run(() => { //Note: see also MapFactory in ArcGIS.Desktop.Mapping var map = MapFactory.Instance.CreateMap("New Map", MapType.Map, MapViewingMode.Map, Basemap.Oceans); ProApp.Panes.CreateMapPaneAsync(map); }); #endregion #region Check if project needs to be saved //The project's dirty state indicates changes made to the project have not yet been saved. bool isProjectDirty = Project.Current.IsDirty; #endregion #region Get all the project items IEnumerable <Item> allProjectItems = Project.Current.GetItems <Item>(); foreach (var pi in allProjectItems) { //Do Something } #endregion #region Gets all the "MapProjectItems" IEnumerable <MapProjectItem> newMapItemsContainer = project.GetItems <MapProjectItem>(); await QueuedTask.Run(() => { foreach (var mp in newMapItemsContainer) { //Do Something with the map. For Example: Map myMap = mp.GetMap(); } }); #endregion #region Gets a specific "MapProjectItem" MapProjectItem mapProjItem = Project.Current.GetItems <MapProjectItem>().FirstOrDefault(item => item.Name.Equals("EuropeMap")); #endregion #region Gets all the "StyleProjectItems" IEnumerable <StyleProjectItem> newStyleItemsContainer = null; newStyleItemsContainer = Project.Current.GetItems <StyleProjectItem>(); foreach (var styleItem in newStyleItemsContainer) { //Do Something with the style. } #endregion #region Gets a specific "StyleProjectItem" var container = Project.Current.GetItems <StyleProjectItem>(); StyleProjectItem testStyle = container.FirstOrDefault(style => (style.Name == "ArcGIS 3D")); StyleItem cone = null; if (testStyle != null) { cone = testStyle.LookupItem(StyleItemType.PointSymbol, "Cone_Volume_3"); } #endregion #region Gets all the "GDBProjectItems" IEnumerable <GDBProjectItem> newGDBItemsContainer = null; newGDBItemsContainer = Project.Current.GetItems <GDBProjectItem>(); foreach (var GDBItem in newGDBItemsContainer) { //Do Something with the GDB. } #endregion #region Gets a specific "GDBProjectItem" GDBProjectItem GDBProjItem = Project.Current.GetItems <GDBProjectItem>().FirstOrDefault(item => item.Name.Equals("myGDB")); #endregion #region Gets all the "ServerConnectionProjectItem" IEnumerable <ServerConnectionProjectItem> newServerConnections = null; newServerConnections = project.GetItems <ServerConnectionProjectItem>(); foreach (var serverItem in newServerConnections) { //Do Something with the server connection. } #endregion #region Gets a specific "ServerConnectionProjectItem" ServerConnectionProjectItem serverProjItem = Project.Current.GetItems <ServerConnectionProjectItem>().FirstOrDefault(item => item.Name.Equals("myServer")); #endregion #region Gets all folder connections in a project //Gets all the folder connections in the current project var projectFolders = Project.Current.GetItems <FolderConnectionProjectItem>(); foreach (var FolderItem in projectFolders) { //Do Something with the Folder connection. } #endregion #region Gets a specific folder connection //Gets a specific folder connection in the current project FolderConnectionProjectItem myProjectFolder = Project.Current.GetItems <FolderConnectionProjectItem>().FirstOrDefault(folderPI => folderPI.Name.Equals("myDataFolder")); #endregion #region Remove a specific folder connection // Remove a folder connection from a project; the folder stored on the local disk or the network is not deleted FolderConnectionProjectItem folderToRemove = Project.Current.GetItems <FolderConnectionProjectItem>().FirstOrDefault(myfolder => myfolder.Name.Equals("PlantSpecies")); if (folderToRemove != null) { Project.Current.RemoveItem(folderToRemove as IProjectItem); } #endregion #region Gets a specific "LayoutProjectItem" LayoutProjectItem layoutProjItem = Project.Current.GetItems <LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals("myLayout")); #endregion #region Gets all layouts in a project: //Gets all the layouts in the current project var projectLayouts = Project.Current.GetItems <LayoutProjectItem>(); foreach (var layoutItem in projectLayouts) { //Do Something with the layout } #endregion #region Gets a specific "GeoprocessingProjectItem" GeoprocessingProjectItem GPProjItem = Project.Current.GetItems <GeoprocessingProjectItem>().FirstOrDefault(item => item.Name.Equals("myToolbox")); #endregion #region Gets all GeoprocessingProjectItems in a project: //Gets all the GeoprocessingProjectItem in the current project var GPItems = Project.Current.GetItems <GeoprocessingProjectItem>(); foreach (var tbx in GPItems) { //Do Something with the toolbox } #endregion #region Search project for a specific item List <Item> _mxd = new List <Item>(); //Gets all the folder connections in the current project var allFoldersItem = Project.Current.GetItems <FolderConnectionProjectItem>(); if (allFoldersItem != null) { //iterate through all the FolderConnectionProjectItems found foreach (var folderItem in allFoldersItem) { //Search for mxd files in that folder connection and add it to the List<T> //Note:ArcGIS Pro automatically creates and dynamically updates a searchable index as you build and work with projects. //Items are indexed when they are added to a project. //The first time a folder or database is indexed, indexing may take a while if it contains a large number of items. //While the index is being created, searches will not return any results. _mxd.AddRange(folderItem.GetItems()); } } #endregion #region Get the Default Project Folder var defaultProjectPath = System.IO.Path.Combine( System.Environment.GetFolderPath( Environment.SpecialFolder.MyDocuments), @"ArcGIS\Projects"); #endregion }
async public static void CreateElementSnippets() { //There are already many Create element snippets in the PRO snippets section. This section will only contain examples that are NOT in the Pro snippets section //Pro snippets region names includes: // Create point graphic with symbology // Create line graphic with symbology // Create rectangle graphic with simple symbology // Create text element with basic font properties // Create rectangle text with more advanced symbol settings // Create a new picture element with advanced symbol settings // Create a map frame and zoom to a bookmark // Create a legend for a specifc map frame // Creating group elements LayoutView lytView = LayoutView.Active; Layout layout = lytView.Layout; #region Create_BeizierCurve await QueuedTask.Run(() => { //Build geometry Coordinate2D pt1 = new Coordinate2D(1, 7.5); Coordinate2D pt2 = new Coordinate2D(1.66, 8); Coordinate2D pt3 = new Coordinate2D(2.33, 7.1); Coordinate2D pt4 = new Coordinate2D(3, 7.5); CubicBezierBuilder bez = new CubicBezierBuilder(pt1, pt2, pt3, pt4); CubicBezierSegment bezSeg = bez.ToSegment(); Polyline bezPl = PolylineBuilder.CreatePolyline(bezSeg); //Set symbology, create and add element to layout CIMLineSymbol lineSym = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.RedRGB, 4.0, SimpleLineStyle.DashDot); GraphicElement bezElm = LayoutElementFactory.Instance.CreateLineGraphicElement(layout, bezPl, lineSym); bezElm.SetName("New Bezier Curve"); }); #endregion Create_BeizierCurve #region Create_freehand await QueuedTask.Run(() => { //Build geometry List <Coordinate2D> plCoords = new List <Coordinate2D>(); plCoords.Add(new Coordinate2D(1.5, 10.5)); plCoords.Add(new Coordinate2D(1.25, 9.5)); plCoords.Add(new Coordinate2D(1, 10.5)); plCoords.Add(new Coordinate2D(0.75, 9.5)); plCoords.Add(new Coordinate2D(0.5, 10.5)); plCoords.Add(new Coordinate2D(0.5, 1)); plCoords.Add(new Coordinate2D(0.75, 2)); plCoords.Add(new Coordinate2D(1, 1)); Polyline linePl = PolylineBuilder.CreatePolyline(plCoords); //Set symbolology, create and add element to layout CIMLineSymbol lineSym = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlackRGB, 2.0, SimpleLineStyle.Solid); GraphicElement lineElm = LayoutElementFactory.Instance.CreateLineGraphicElement(layout, linePl, lineSym); lineElm.SetName("New Freehand"); }); #endregion Create_freehand #region Create_polygon await QueuedTask.Run(() => { //Build geometry List <Coordinate2D> plyCoords = new List <Coordinate2D>(); plyCoords.Add(new Coordinate2D(1, 7)); plyCoords.Add(new Coordinate2D(2, 7)); plyCoords.Add(new Coordinate2D(2, 6.7)); plyCoords.Add(new Coordinate2D(3, 6.7)); plyCoords.Add(new Coordinate2D(3, 6.1)); plyCoords.Add(new Coordinate2D(1, 6.1)); Polygon poly = PolygonBuilder.CreatePolygon(plyCoords); //Set symbolology, create and add element to layout CIMStroke outline = SymbolFactory.Instance.ConstructStroke(ColorFactory.Instance.BlueRGB, 2.0, SimpleLineStyle.DashDotDot); CIMPolygonSymbol polySym = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.RedRGB, SimpleFillStyle.ForwardDiagonal, outline); GraphicElement polyElm = LayoutElementFactory.Instance.CreatePolygonGraphicElement(layout, poly, polySym); polyElm.SetName("New Polygon"); }); #endregion Create_polygon #region Create_circle await QueuedTask.Run(() => { //Build geometry Coordinate2D center = new Coordinate2D(2, 4); EllipticArcBuilder eabCir = new EllipticArcBuilder(center, 0.5, esriArcOrientation.esriArcClockwise); EllipticArcSegment cir = eabCir.ToSegment(); //Set symbolology, create and add element to layout CIMStroke outline = SymbolFactory.Instance.ConstructStroke(ColorFactory.Instance.BlackRGB, 2.0, SimpleLineStyle.Dash); CIMPolygonSymbol circleSym = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.RedRGB, SimpleFillStyle.Solid, outline); GraphicElement cirElm = LayoutElementFactory.Instance.CreateCircleGraphicElement(layout, cir, circleSym); cirElm.SetName("New Circle"); }); #endregion Create_circle #region Create_ellipse await QueuedTask.Run(() => { //Build geometry Coordinate2D center = new Coordinate2D(2, 2.75); EllipticArcBuilder eabElp = new EllipticArcBuilder(center, 0, 1, 0.45, esriArcOrientation.esriArcClockwise); EllipticArcSegment ellipse = eabElp.ToSegment(); //Set symbolology, create and add element to layout CIMStroke outline = SymbolFactory.Instance.ConstructStroke(ColorFactory.Instance.GreenRGB, 2.0, SimpleLineStyle.Dot); CIMPolygonSymbol ellipseSym = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.GreyRGB, SimpleFillStyle.Vertical, outline); GraphicElement elpElm = LayoutElementFactory.Instance.CreateEllipseGraphicElement(layout, ellipse, ellipseSym); elpElm.SetName("New Ellipse"); }); #endregion Create_ellipse #region Create_lasso await QueuedTask.Run(() => { //Build geometry List <Coordinate2D> plyCoords = new List <Coordinate2D>(); plyCoords.Add(new Coordinate2D(1, 1)); plyCoords.Add(new Coordinate2D(1.25, 2)); plyCoords.Add(new Coordinate2D(1.5, 1.1)); plyCoords.Add(new Coordinate2D(1.75, 2)); plyCoords.Add(new Coordinate2D(2, 1.1)); plyCoords.Add(new Coordinate2D(2.25, 2)); plyCoords.Add(new Coordinate2D(2.5, 1.1)); plyCoords.Add(new Coordinate2D(2.75, 2)); plyCoords.Add(new Coordinate2D(3, 1)); Polygon poly = PolygonBuilder.CreatePolygon(plyCoords); //Set symbolology, create and add element to layout CIMStroke outline = SymbolFactory.Instance.ConstructStroke(ColorFactory.Instance.BlackRGB, 2.0, SimpleLineStyle.Solid); CIMPolygonSymbol polySym = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.RedRGB, SimpleFillStyle.ForwardDiagonal, outline); GraphicElement polyElm = LayoutElementFactory.Instance.CreatePolygonGraphicElement(layout, poly, polySym); polyElm.SetName("New Lasso"); }); #endregion Create_lasso #region Create_CurveText await QueuedTask.Run(() => { //Build geometry Coordinate2D pt1 = new Coordinate2D(3.6, 7.5); Coordinate2D pt2 = new Coordinate2D(4.26, 8); Coordinate2D pt3 = new Coordinate2D(4.93, 7.1); Coordinate2D pt4 = new Coordinate2D(5.6, 7.5); CubicBezierBuilder bez = new CubicBezierBuilder(pt1, pt2, pt3, pt4); CubicBezierSegment bezSeg = bez.ToSegment(); Polyline bezPl = PolylineBuilder.CreatePolyline(bezSeg); //Set symbolology, create and add element to layout CIMTextSymbol sym = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 24, "Comic Sans MS", "Regular"); GraphicElement bezTxtElm = LayoutElementFactory.Instance.CreateCurvedTextGraphicElement(layout, bezPl, "Curved Text", sym); bezTxtElm.SetName("New Splinned Text"); }); #endregion Create_CurveText #region Create_PolygonText await QueuedTask.Run(() => { //Build geometry List <Coordinate2D> plyCoords = new List <Coordinate2D>(); plyCoords.Add(new Coordinate2D(3.5, 7)); plyCoords.Add(new Coordinate2D(4.5, 7)); plyCoords.Add(new Coordinate2D(4.5, 6.7)); plyCoords.Add(new Coordinate2D(5.5, 6.7)); plyCoords.Add(new Coordinate2D(5.5, 6.1)); plyCoords.Add(new Coordinate2D(3.5, 6.1)); Polygon poly = PolygonBuilder.CreatePolygon(plyCoords); //Set symbolology, create and add element to layout CIMTextSymbol sym = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.GreyRGB, 10, "Arial", "Regular"); string text = "Some Text String that is really long and is <BOL>forced to wrap to other lines</BOL> so that we can see the effects." as String; GraphicElement polyTxtElm = LayoutElementFactory.Instance.CreatePolygonParagraphGraphicElement(layout, poly, text, sym); polyTxtElm.SetName("New Polygon Text"); //(Optionally) Modify paragraph border CIMGraphic polyTxtGra = polyTxtElm.Graphic; CIMParagraphTextGraphic cimPolyTxtGra = polyTxtGra as CIMParagraphTextGraphic; cimPolyTxtGra.Frame.BorderSymbol = new CIMSymbolReference(); cimPolyTxtGra.Frame.BorderSymbol.Symbol = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.GreyRGB, 1.0, SimpleLineStyle.Solid); polyTxtElm.SetGraphic(polyTxtGra); }); #endregion Create_PolygonText #region Create_CircleText await QueuedTask.Run(() => { //Build geometry Coordinate2D center = new Coordinate2D(4.5, 4); EllipticArcBuilder eabCir = new EllipticArcBuilder(center, 0.5, esriArcOrientation.esriArcClockwise); EllipticArcSegment cir = eabCir.ToSegment(); //Set symbolology, create and add element to layout CIMTextSymbol sym = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.GreenRGB, 10, "Arial", "Regular"); string text = "Circle, circle, circle, circle, circle, circle, circle, circle, circle, circle, circle"; GraphicElement cirTxtElm = LayoutElementFactory.Instance.CreateCircleParagraphGraphicElement(layout, cir, text, sym); cirTxtElm.SetName("New Circle Text"); //(Optionally) Modify paragraph border CIMGraphic cirTxtGra = cirTxtElm.Graphic; CIMParagraphTextGraphic cimCirTxtGra = cirTxtGra as CIMParagraphTextGraphic; cimCirTxtGra.Frame.BorderSymbol = new CIMSymbolReference(); cimCirTxtGra.Frame.BorderSymbol.Symbol = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.GreyRGB, 1.0, SimpleLineStyle.Solid); cirTxtElm.SetGraphic(cirTxtGra); }); #endregion Create_CircleText #region Create_EllipseText await QueuedTask.Run(() => { //Build geometry Coordinate2D center = new Coordinate2D(4.5, 2.75); EllipticArcBuilder eabElp = new EllipticArcBuilder(center, 0, 1, 0.45, esriArcOrientation.esriArcClockwise); EllipticArcSegment ellipse = eabElp.ToSegment(); //Set symbolology, create and add element to layout CIMTextSymbol sym = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlueRGB, 10, "Arial", "Regular"); string text = "Ellipse, ellipse, ellipse, ellipse, ellipse, ellipse, ellipse, ellipse, ellipse, ellipse, ellipse, ellipse"; GraphicElement elpTxtElm = LayoutElementFactory.Instance.CreateEllipseParagraphGraphicElement(layout, ellipse, text, sym); elpTxtElm.SetName("New Ellipse Text"); //(Optionally) Modify paragraph border CIMGraphic elpTxtGra = elpTxtElm.Graphic; CIMParagraphTextGraphic cimElpTxtGra = elpTxtGra as CIMParagraphTextGraphic; cimElpTxtGra.Frame.BorderSymbol = new CIMSymbolReference(); cimElpTxtGra.Frame.BorderSymbol.Symbol = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.GreyRGB, 1.0, SimpleLineStyle.Solid); elpTxtElm.SetGraphic(elpTxtGra); }); #endregion Create_EllipseText MapFrame mfElm = null; #region Create_MapFrame //This example creates a new map frame and changes the camera scale. await QueuedTask.Run(() => { //Build geometry Coordinate2D ll = new Coordinate2D(6.0, 8.5); Coordinate2D ur = new Coordinate2D(8.0, 10.5); Envelope env = EnvelopeBuilder.CreateEnvelope(ll, ur); //Reference map, create MF and add to layout MapProjectItem mapPrjItem = Project.Current.GetItems <MapProjectItem>().FirstOrDefault(item => item.Name.Equals("Map")); Map mfMap = mapPrjItem.GetMap(); mfElm = LayoutElementFactory.Instance.CreateMapFrame(layout, env, mfMap); mfElm.SetName("New Map Frame"); //Set the camera Camera camera = mfElm.Camera; camera.Scale = 24000; mfElm.SetCamera(camera); }); #endregion Create_MapFrame #region Create_ScaleBar await QueuedTask.Run(() => { //Reference a North Arrow in a style StyleProjectItem stylePrjItm = Project.Current.GetItems <StyleProjectItem>().FirstOrDefault(item => item.Name == "ArcGIS 2D"); ScaleBarStyleItem sbStyleItm = stylePrjItm.SearchScaleBars("Double Alternating Scale Bar 1")[0]; //Build geometry Coordinate2D center = new Coordinate2D(7, 8); //Reference MF, create north arrow and add to layout MapFrame mf = layout.FindElement("New Map Frame") as MapFrame; if (mf == null) { ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Map frame not found", "WARNING"); return; } ScaleBar sbElm = LayoutElementFactory.Instance.CreateScaleBar(layout, center, mf, sbStyleItm); sbElm.SetName("New Scale Bar"); sbElm.SetWidth(2); sbElm.SetX(6); sbElm.SetY(7.5); }); #endregion Create_ScaleBar #region Create_NorthArrow await QueuedTask.Run(() => { //Reference a North Arrow in a style StyleProjectItem stylePrjItm = Project.Current.GetItems <StyleProjectItem>().FirstOrDefault(item => item.Name == "ArcGIS 2D"); NorthArrowStyleItem naStyleItm = stylePrjItm.SearchNorthArrows("ArcGIS North 10")[0]; //Build geometry Coordinate2D center = new Coordinate2D(7, 5.5); //Reference MF, create north arrow and add to layout MapFrame mf = layout.FindElement("New Map Frame") as MapFrame; if (mf == null) { ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Map frame not found", "WARNING"); return; } NorthArrow arrowElm = LayoutElementFactory.Instance.CreateNorthArrow(layout, center, mf, naStyleItm); arrowElm.SetName("New North Arrow"); arrowElm.SetHeight(1.75); arrowElm.SetX(7); arrowElm.SetY(6); }); #endregion Create_NorthArrow }