Bookmark

Synthèse

Provides access to bookmark methods and properties.

Discussion

Bookmarks in an ArcGIS Pro project are associated and managed with the map for which they were created. They are referenced using the listBookmarks method on the Map object. To search all bookmarks in a project, you must iterate through all the maps. Bookmarks can be used to update the camera settings for a MapFrame on a page layout or a MapView using the zoomToBookmark method.

Despite the fact that a bookmark is associated with a specific map, a bookmark can be used on map frames or map views that are associated with different maps. Bookmarks created using a 2D map can be used with 3D maps and vice versa. It is at the time of bookmark creation that the current Camera properties are set based on the type of map. If a 2D bookmark is used for either a local or global scene, the result will be a planimetric view of the area of interest. If a 3D bookmark is used with a 2D map frame type, the 3D camera properties are approximated to provide a planimetric extent.

The createBookmark method on the MapFrame or MapView object creates a bookmark for their associated map using their current camera settings. The copyBookmark method on the Map object copies an existing bookmark into a referenced map. Both of these methods allow you to modify the name of the new or copied bookmark. Bookmarks in the same map cannot have the same name and if a new name is not provided, the name could be sequenced automatically, for example, Bookmark, Bookmark [1], Bookmark [2], and so on.

The exportBookmarks and importBookmarks methods on the Map object are an efficient way to transfer all bookmarks from one map to another map in the same project or between maps in different projects. Both methods use bookmark files (*.bkmx) as the interchange file. You export the bookmarks from one map to a bookmark file and import that same file into another map. If you import more bookmarks than you need, you can call the removeBookmark method. If you don't want to export all bookmarks at once, you can use the copyBookmark method to copy one bookmark at a time from one map to another map and bookmarks across projects.

There are a couple of scenarios in which a bookmark's thumbnail image will need to be updated. First, bookmarks imported from map (.mxd), globe (.3dd), or scene (.sxd) documents don't automatically have their thumbnails updated due to a performance hit—it could take a long time for the application to automate this process because each bookmark area of interest would need to be generated and layers fully drawn before a thumbnail could be created. Second, the data in a map, for example, a basemap, may get changed and you may want the thumbnails to get updated appropriately. The updateThumbnail method provides a solution for these two scenarios. The hasThumbnail property allows you to determine which bookmarks may have been imported and don't currently have a thumbnail image.

Remarque :

When working with bookmarks in a MapView, the code must be run within the application because map views are not supported with stand-alone scripts. This includes using methods such as updateThumbnail and zoomToBookmark. These methods will work with a MapFrame with stand-alone scripts run outside of the application.

The Layout object also has a createBookmarkMapSeries method allowing you to create map series from a set of provided bookmarks. Refer to the BookmarkMapSeries help topic for more information and code samples.

Propriétés

PropriétéExplicationType de données
description
(Lecture et écriture)

The description of the bookmark.

String
hasThumbnail
(Lecture seule)

Returns True, if a thumbnail image is associated with a bookmark. To update the image, use the updateThumbnail method.

Boolean
map
(Lecture seule)

The Map that the bookmark is associated with.

Map
name
(Lecture et écriture)

The name of the bookmark.

String

Vue d’ensemble des méthodes

MéthodeExplication
updateThumbnail ()

Updates a bookmark's thumbnail image.

Méthodes

updateThumbnail ()

Updates a bookmark's thumbnail image. To determine if a thumbnail exists for a bookmark, check the hasThumbnail property.

Exemple de code

Bookmark example 1

The following script will update a map frame's area of interest by zooming to each bookmark that belongs to a map named Yosemite National Park and export the result to individual PDF documents:

import arcpy, os
aprx = arcpy.mp.ArcGISProject(r"C:\Projects\YosemiteNP\Yosemite.aprx")

lyt = aprx.listLayouts("Main Attractions*")[0]
mf = lyt.listElements("MAPFRAME_ELEMENT", "Yosemite National Park*")[0]

bkmks = mf.map.listBookmarks()
for bkmk in bkmks:
  mf.zoomToBookmark(bkmk)
  lyt.exportToPDF(os.path.join(r"C:\Projects\YosemiteNP", f"{bkmk.name}.pdf"))
del aprx
Bookmark example 2

The following script will iterate through all the bookmarks in a project and update the thumbnail image if it is missing:

import arcpy
aprx = arcpy.mp.ArcGISProject(r"C:\Projects\YosemiteNP\Yosemite.aprx")
for m in aprx.listMaps():
  for bkmk in m.listBookmarks():
    if bkmk.hasThumbnail == False:
      bkmk.updateThumbnail()
aprx.save()
del aprx
Bookmark example 3

The following script will create a bookmark in a new map and also copy a bookmark from another project into the new map:

#Create a new map and bookmark
p = arcpy.mp.ArcGISProject("CURRENT")
m = p.createMap("New Map", "MAP")
mv = m.openView()
mv.createBookmark("Default Extent", "The map's default extent")

#Reference a bookmark in a different project
p2 = arcpy.mp.ArcGISProject(r"C:\Projects\YosemiteNP\Yosemite.aprx")
m2 = p2.listMaps("Yosemite National Park")[0]
bkmk = m2.listBookmarks("Park Boundary")[0]

#Copy the referened bookmark into the new map
copyBkmk = m.copyBookmark(bkmk, "Yosemite National Park")
copyBkmk.updateThumbnail()
mv.zoomToBookmark(copyBkmk)
Bookmark example 4

The following script will export all bookmarks from a map in one project and import them into a newly created map in a new, blank project:

import arcpy, os, sys
relpath = os.path.dirname(sys.argv[0])

#Export the bookmarks from one map in a project
p1 = arcpy.mp.ArcGISProject(os.path.join(relpath, "Bookmarks.aprx"))
m1 = p1.listMaps('Great Lakes')[0]
m1.exportBookmarks(r"C:\Temp\test.bkmx")

#Import bkmks into a new, blank project after creating a new map
p2 = arcpy.mp.ArcGISProject(os.path.join(relpath, "Blank.aprx"))
m2 = p2.createMap('New Map')
m2.importBookmarks(r"C:\Temp\test.bkmx")
p2.saveACopy(os.path.join(relpath, "Blank_OUT.aprx"))
os.startfile(os.path.join(relpath, "Blank_OUT.aprx"))
Bookmark example 5

The following script will use Python CIM Access to alphabetize all bookmarks in a map based on the bookmark name:

p = arcpy.mp.ArcGISProject('current')
for m in  p.listMaps():
    cim = m.getDefinition('V3') #Get the CIM definition
    #The following line alphabetizes the CIM bookmark list based on name
    newList = sorted(cim.bookmarks, key=lambda Bookmark: Bookmark.name)
    cim.bookmarks = newList
    m.setDefinition(cim) #Set the CIM changes back to the map