Open map (URL)

View on GitHubSample viewer app

Display a web map.

Image of open map URL

Use case

For displaying web maps stored on ArcGIS Online.

How to use the sample

Tap the button to see a list of other web maps. Upon selection, the web map displays in the map view.

How it works

  1. Create an AGSPortal object.
  2. Create an AGSPortalItem using the portal and the web map ID.
  3. Create an AGSMap using the portal item.
  4. Set the map to the AGSMapView.

Relevant API

  • AGSMap
  • AGSMapView
  • AGSPortal
  • AGSPortalItem

About the data

The web maps accessed by this sample show Geology for United States, Terrestrial Ecosystems of the World and Recent Hurricanes, Cyclones and Typhoons.

Tags

portal item, web map

Sample Code

OpenMapURLSettingsViewController.swiftOpenMapURLSettingsViewController.swiftOpenMapURLViewController.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
59
60
61
62
63
64
65
66
67
68
// Copyright 2018 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 OpenMapURLSettingsViewController: UITableViewController {
    var mapOptions: [OpenMapURLViewController.MapAtURL] = []
    var initialSelectedID: String?
    var onChange: ((URL) -> Void)?

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)

        let selectedMapIndex = mapOptions.firstIndex { (mapAtURL) -> Bool in
            mapAtURL.portalID == initialSelectedID
        }
        if let selectedMapIndex = selectedMapIndex {
            let selectedIndexPath = IndexPath(row: selectedMapIndex, section: 0)
            tableView.selectRow(at: selectedIndexPath, animated: false, scrollPosition: .none)
            tableView.cellForRow(at: selectedIndexPath)?.accessoryType = .checkmark
        }
    }

    // MARK: - UITableViewDataSource

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

    // MARK: - UITableViewDelegate

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "MapAtURLCell", for: indexPath)

        let mapOption = mapOptions[indexPath.row]

        cell.textLabel?.text = mapOption.title

        cell.imageView?.image = mapOption.thumbnailImage
        cell.imageView?.contentMode = .scaleAspectFill
        cell.imageView?.clipsToBounds = true

        return cell
    }

    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        if let url = mapOptions[indexPath.row].url {
            onChange?(url)
        }
        tableView.cellForRow(at: indexPath)?.accessoryType = .checkmark
    }

    override func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
        tableView.cellForRow(at: indexPath)?.accessoryType = .none
    }
}

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