Manage bookmarks

View on GitHubSample viewer app

Access and create bookmarks on a map.

Image of manage bookmarks 1 Image of manage bookmarks 2

Use case

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, tap on a bookmark's name from the list. To add a bookmark, pan and zoom to a new location and tap the "+" button. Enter a unique name for the bookmark, and the bookmark will be added to the list.

How it works

  1. Instantiate an AGSMap object.
  2. To create a new bookmark and add it to the bookmark list:
    • Instantiate an AGSBookmark object passing in text (the name of the bookmark) and an AGSViewpoint as parameters.
    • Add the new bookmark to the map's bookmarks array.

Relevant API

  • AGSBookmark
  • AGSViewpoint

Tags

bookmark, extent, location, zoom

Sample Code

BookmarksListViewController.swiftBookmarksListViewController.swiftBookmarksViewController.swift
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
// 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.

import UIKit
import ArcGIS

class BookmarksListViewController: UITableViewController {
    // list of bookmarks
    var bookmarks = [AGSBookmark]()

    // private property to store selection action for table cell
    private var selectAction: ((AGSViewpoint) -> Void)?

    // executed for tableview row selection
    func setSelectAction(_ action : @escaping ((AGSViewpoint) -> Void)) {
        self.selectAction = action
    }

    // MARK: - TableView data source

    override func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return bookmarks.count
    }

    // MARK: - TableView delegates

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "BookmarkCell", for: indexPath)
        // get the respective bookmark
        let bookmark = self.bookmarks[indexPath.row]
        // assign the bookmark's name as the title for the cell
        cell.textLabel?.text = bookmark.name

        return cell
    }

    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let bookmark = self.bookmarks[indexPath.row]
        // execute the closure if it exists
        selectAction?(bookmark.viewpoint!)
        tableView.deselectRow(at: indexPath, animated: true)
    }
}

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.