Access and create bookmarks on a map.
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
- Instantiate an
AGSMap
object. - 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 anAGSViewpoint
as parameters. - Add the new bookmark to the map's
bookmarks
array.
- Instantiate an
Relevant API
- AGSBookmark
- AGSViewpoint
Tags
bookmark, extent, location, zoom
Sample Code
// 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)
}
}