Bookmarks are used for easily storing and accessing saved locations on the map. Bookmarks are of interest in educational apps (e.g. touring historical sites) or more specifically, for a land management company wishing to visually monitor flood levels over time at a particular location. These locations can be saved as bookmarks and revisited easily each time their basemap data has been updated (e.g. working with up to date satellite imagery to monitor water levels).
How to use the sample
The map in the sample comes pre-populated with a set of bookmarks. To access a bookmark and move to that location, click on a bookmark's name from the list. To add a bookmark, pan and/or zoom to a new location and click on the '+' in the bottom corner. Enter a unique name for the bookmark and click ok, and the bookmark will be added to the list
How it works
Create a new Map object and create a list of bookmarks: map.bookmarks.append(bookmark).
To create a new bookmark and add it to the bookmark list:
Create a new Bookmark object passing in text (the name of the bookmark) and a Viewpoint as parameters.
Relevant API
Bookmark
BookmarkListModel
Viewpoint
Tags
bookmark, extent, location, zoom
Sample Code
ManageBookmarks.qml
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
// [WriteFile Name=ManageBookmarks, Category=Maps]// [Legal]// Copyright 2016 Esri.// Licensed under the Apache License, Version 2.0 (the "License");// you may not use this file except in compliance with the License.// You may obtain a copy of the License at// http://www.apache.org/licenses/LICENSE-2.0// Unless required by applicable law or agreed to in writing, software// distributed under the License is distributed on an "AS IS" BASIS,// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.// See the License for the specific language governing permissions and// limitations under the License.// [Legal]import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import Esri.ArcGISRuntime
Rectangle {
id: rootRectanglewidth: 800height: 600// Create MapView that contains a MapMapView {
id: mapViewanchors.fill: parentComponent.onCompleted: {
// Set the focus on MapView to initially enable keyboard navigation forceActiveFocus();
}
Map {
id: map// Set the initial basemap to Imagery with LabelsBasemap {
initStyle: Enums.BasemapStyleArcGISImagery
}
onLoadStatusChanged: {
// Once the map is loaded, add in the initial bookmarksif (loadStatus === Enums.LoadStatusLoaded) {
createBookmark("Mysterious Desert Pattern", desertViewpoint);
createBookmark("Strange Symbol", symbolViewpoint);
createBookmark("Guitar Shaped Forest", guitarViewpoint);
createBookmark("Grand Prismatic Spring", springViewpoint);
bookmarks.currentIndex = 0;
}
}
// helper function for creating bookmarksfunctioncreateBookmark(bookmarkName,bookmarkViewpoint) {
// create a bookmark object and assign the name and viewpointconst bookmark = ArcGISRuntimeEnvironment.createObject("Bookmark");
bookmark.name = bookmarkName;
bookmark.viewpoint = bookmarkViewpoint;
// append the bookmark to the map's BookmarkListModel map.bookmarks.append(bookmark);
}
}
// Create the add button so new bookmarks can be addedRectangle {
id: addButtonproperty bool pressed: falseanchors {
right: parent.right
bottom: mapView.attributionTop
rightMargin: 20bottomMargin: 20 }
width: childrenRect.width
height: childrenRect.height
color: pressed ? "#959595" : "#D6D6D6"radius: 100border {
color: "#585858"width: 1 }
Image {
rotation: 45width: 32height: width
source: "qrc:/Samples/Maps/ManageBookmarks/add.png" }
MouseArea {
anchors.fill: parentonPressed: addButton.pressed = trueonReleased: addButton.pressed = falseonClicked: {
// Show the add window when it is clicked addWindow.visible = true;
}
}
}
}
// Create Viewpoints for the 4 initial bookmarksViewpointExtent {
id: desertViewpointextent: Envelope {
xMin: 3742993.127298778xMax: 3744795.1333054285yMin: 3170396.4675719286yMax: 3171745.88077spatialReference: SpatialReference { wkid: 102100 }
}
}
ViewpointExtent {
id: symbolViewpointextent: Envelope {
xMin: -13009913.860076642xMax: -13009442.089218518yMin: 4495026.9307899885yMax: 4495404.031910696spatialReference: SpatialReference { wkid: 102100 }
}
}
ViewpointExtent {
id: guitarViewpointextent: Envelope {
xMin: -7124497.45137465xMax: -7121131.417429369yMin: -4012221.6124684606yMax: -4009697.0870095spatialReference: SpatialReference { wkid: 102100 }
}
}
ViewpointExtent {
id: springViewpointextent: Envelope {
xMin: -12338668.348591767xMax: -12338247.594362013yMin: 5546908.424239618yMax: 5547223.989911933spatialReference: SpatialReference { wkid: 102100 }
}
}
// Create a combo box that allows for switching between bookmarksComboBox {
id: bookmarksanchors {
left: parent.left
top: parent.top
margins: 5 }
// Add a background to the ComboBoxRectangle {
anchors.fill: parentradius: 10// Make the rectangle visible if a dropdown indicator exists// An indicator only exists if a theme is setvisible: parent.indicator
border.width: 1 }
property int modelWidth: 0width: modelWidth + rightPadding + leftPadding + (indicator ? indicator.width : 10)
model: map.bookmarks
Connections {
target: bookmarks.model
functiononCountChanged() {
const model = bookmarks.model;
if (model) {
for (let i = 0; i < model.count; ++i) {
metrics.text = model.get(i).name;
bookmarks.modelWidth = Math.max(bookmarks.modelWidth,
metrics.width);
}
}
}
}
onCurrentIndexChanged: {
if (currentIndex >= 0) {
const bookmark = map.bookmarks.get(currentIndex);
if (bookmark) {
mapView.setViewpoint(
map.bookmarks.get(currentIndex).viewpoint);
}
}
}
TextMetrics {
id: metricsfont: bookmarks.font
}
}
// Create a window so names for new bookmarks can be specifiedRectangle {
id: addWindowanchors.centerIn: parentwidth: childrenRect.width
height: childrenRect.height
visible: falseenabled: visible
color: "lightgrey"opacity: .9radius: 5border {
color: "#4D4D4D"width: 1 }
MouseArea {
anchors.fill: parentonClicked: mouse => mouse.accepted = true;
}
GridLayout {
columns: 2Text {
text: qsTr("Provide the bookmark name")
font.pixelSize: 12Layout.columnSpan: 2Layout.margins: 5 }
TextField {
id: textFieldplaceholderText: qsTr("ex: Grand Canyon")
selectByMouse: trueLayout.columnSpan: 2Layout.margins: 5Layout.fillWidth: true }
Button {
text: "Cancel"onClicked: addWindow.visible = false;
Layout.margins: 5 }
Button {
text: qsTr("Done")
Layout.margins: 5Layout.alignment: Qt.AlignRight
onClicked: {
// Create the new bookmark by getting the current viewpoint and using the// user's input bookmark nameconst viewpoint = mapView.currentViewpointExtent;
map.createBookmark(textField.text,viewpoint);
bookmarks.currentIndex = map.bookmarks.count -1;
textField.text = "";
addWindow.visible = false;
}
}
}
}
}