OpenStreetMap layer

View on GitHub
Sample viewer app

Add OpenStreetMap as a basemap layer.

OpenStreetMap layer sample

Use case

You may want to create a map with an OpenStreetMap; which is a free community-edited basemap.

How to use the sample

When the sample opens, it will automatically display the map with the OpenStreetMap basemap. Pan and zoom to observe the basemap.

How it works

  1. Create an AGSMap with osmStandard as the basemapStyle and specify the other properties.
  2. Apply the AGSMap to the AGSMapView.

Relevant API

  • AGSBasemapStyle
  • AGSMap
  • AGSMapView
  • AGSOpenStreetMapLayer

Additional information

The attribution text will be set to the required OpenStreetMap attribution automatically.

Apps that expect to make many requests to OpenStreetMap should consider using an alternative tile server via the AGSWebTiledLayer class.

Esri now hosts an OpenStreetMap vector layer on ArcGIS Online that uses recent OpenStreetMap data in conjunction with a style matching the default OpenStreetMap style. This layer is not subject to the tile access restrictions that apply to tiles fetched from OpenStreetMap.org.

Tags

basemap, layers, map, open, OpenStreetMap, OSM, street

Sample Code

OpenStreetMapLayerViewController.swift
                                  
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
// 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 OpenStreetMapLayerViewController: UIViewController {
    @IBOutlet private weak var mapView: AGSMapView!

    override func viewDidLoad() {
        super.viewDidLoad()

        // initialize map with an OpenStreetMap standard basemap
        let map = AGSMap(basemapStyle: .osmStandard)

        // assign the map to the map view
        mapView.map = map
        mapView.setViewpoint(AGSViewpoint(latitude: 34.056295, longitude: -117.195800, scale: 577790.554289))

        // add the source code button item to the right of navigation bar
        (navigationItem.rightBarButtonItem as! SourceCodeBarButtonItem).filenames = ["OpenStreetMapLayerViewController"]
    }
}

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