Scene layer selection

View on GitHub
Sample viewer app

Identify features in a scene to select.

Scene Layer Selection sample

Use case

You can select features to visually distinguish them with a selection color or highlighting. This can be useful to demonstrate the physical extent or associated attributes of a feature, or to initiate another action such as centering that feature in the scene view.

How to use the sample

Tap on a building in the scene layer to select it. Deselect buildings by tapping away from the buildings.

How it works

  1. Create an AGSArcGISSceneLayer passing in the URL to a scene layer service.
  2. Use the AGSGeoViewTouchDelegate to get the screen tapped location.
  3. Use AGSGeoView.identifyLayer(_:screenPoint:tolerance:returnPopupsOnly:completion:) to identify features in the scene.
  4. From the resulting AGSIdentifyLayerResult, get the list of identified AGSGeoElements.
  5. Get the first AGSFeature in the list and use AGSArcGISSceneLayer.select(_:) to select it.

Relevant API

  • AGSArcGISSceneLayer
  • AGSGeoViewTouchDelegate
  • AGSScene
  • AGSSceneView

About the data

This sample shows a Brest, France Scene hosted on ArcGIS Online.

Tags

3D, buildings, identify, model, query, search, select

Sample Code

SceneLayerSelectionViewController.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
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
69
70
71
72
73
//
// 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

/// A view controller that manages the interface of the Scene Layer Selection
/// sample.
class SceneLayerSelectionViewController: UIViewController {
    /// The scene displayed in the scene view.
    let scene: AGSScene
    let buildingsLayer: AGSArcGISSceneLayer

    required init?(coder: NSCoder) {
        scene = AGSScene(basemap: .topographic())

        // Create a surface set it as the base surface of the scene.
        let surface = AGSSurface()
        /// The url of the Terrain 3D ArcGIS REST Service.
        let worldElevationServiceURL = URL(string: "https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer")!
        surface.elevationSources = [AGSArcGISTiledElevationSource(url: worldElevationServiceURL)]
        scene.baseSurface = surface

        /// The url of the scene service for buildings in Brest, France.
        let brestBuildingsServiceURL = URL(string: "https://tiles.arcgis.com/tiles/P3ePLMYs2RVChkJx/arcgis/rest/services/Buildings_Brest/SceneServer/layers/0")!
        buildingsLayer = AGSArcGISSceneLayer(url: brestBuildingsServiceURL)
        scene.operationalLayers.add(buildingsLayer)

        super.init(coder: coder)
    }

    /// The scene view managed by the view controller.
    @IBOutlet weak var sceneView: AGSSceneView!

    override func viewDidLoad() {
        super.viewDidLoad()

        // Assign the scene to the scene view.
        sceneView.scene = scene

        let camera = AGSCamera(latitude: 48.378, longitude: -4.494, altitude: 200, heading: 345, pitch: 65, roll: 0)
        sceneView.setViewpointCamera(camera)
        sceneView.touchDelegate = self

        (navigationItem.rightBarButtonItem as! SourceCodeBarButtonItem).filenames = ["SceneLayerSelectionViewController"]
    }
}

extension SceneLayerSelectionViewController: AGSGeoViewTouchDelegate {
    func geoView(_ geoView: AGSGeoView, didTapAtScreenPoint screenPoint: CGPoint, mapPoint: AGSPoint) {
        buildingsLayer.clearSelection()
        sceneView.identifyLayer(buildingsLayer, screenPoint: screenPoint, tolerance: 10, returnPopupsOnly: false) { [weak self] (result) in
            if let error = result.error {
                print("\(result.layerContent.name) identify failed: \(error)")
            } else if let feature = result.geoElements.first as? AGSFeature {
                self?.buildingsLayer.select(feature)
            }
        }
    }
}

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