Set initial map area

View on GitHubSample viewer app

Display the map at an initial viewpoint representing a bounding geometry.

Image of set initial map area

Use case

Setting the initial viewpoint is useful when a user wishes to first load the map at a particular area of interest.

How to use the sample

When the sample loads, note the map is opened at the initial view point that is set to it.

How it works

  1. Instantiate an AGSMap object.
  2. Instantiate an AGSViewpoint object using an AGSEnvelope object.
  3. Set the starting location to the initialViewpoint property of the map.
  4. Set the map to an AGSMapView object.

Relevant API

  • AGSEnvelope
  • AGSMap
  • AGSMapView
  • AGSViewpoint

Tags

envelope, extent, initial viewpoint, zoom

Sample Code

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

    override func viewDidLoad() {
        super.viewDidLoad()

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

        // Initialize the map with imagery basemap.
        let map = AGSMap(basemapStyle: .arcGISImageryStandard)

        // Assign the map to the map view.
        mapView.map = map

        // Set the map view's viewpoint.
        let envelope = AGSEnvelope(xMin: -12211308.778729, yMin: 4645116.003309, xMax: -12208257.879667, yMax: 4650542.535773, spatialReference: .webMercator())
        mapView.setViewpoint(AGSViewpoint(targetExtent: envelope))
    }
}

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