Feature layer rendering mode (scene)

View on GitHub
Sample viewer app

Render features in a scene statically or dynamically by setting the feature layer rendering mode.

Feature layer rendering mode (scene)

Use case

In dynamic rendering mode, features and graphics are stored on the GPU. As a result, dynamic rendering mode is good for moving objects and for maintaining graphical fidelity during extent changes, since individual graphic changes can be efficiently applied directly to the GPU state. This gives the map or scene a seamless look and feel when interacting with it. The number of features and graphics has a direct impact on GPU resources, so large numbers of features or graphics can affect the responsiveness of maps or scenes to user interaction. Ultimately, the number and complexity of features and graphics that can be rendered in dynamic rendering mode is dependent on the power and memory of the device's GPU.

In static rendering mode, features and graphics are rendered only when needed (for example, after an extent change) and offloads a significant portion of the graphical processing onto the CPU. As a result, less work is required by the GPU to draw the graphics, and the GPU can spend its resources on keeping the UI interactive. Use this mode for stationary graphics, complex geometries, and very large numbers of features or graphics. The number of features and graphics has little impact on frame render time, meaning it scales well, and pushes a constant GPU payload. However, rendering updates is CPU and system memory intensive, which can have an impact on device battery life.

How to use the sample

Use the "Zoom In" button to trigger the same zoom animation on both static and dynamically rendered scenes.

How it works

  1. Create an AGSSceneView for each static and dynamic mode and create an AGSScene for each.
  2. Create AGSServiceFeatureTables using point, polyline, and polygon services.
  3. Create an AGSFeatureLayer for each of the feature tables and a copy of each feature layer.
  4. Set each feature layer's renderingMode to dynamic and static appropriately.
  5. Add all of the feature layers to the scene's operationalLayers.

Relevant API

  • AGSFeatureLayer
  • AGSFeatureLayer.renderingMode
  • AGSScene
  • AGSSceneView

Tags

3D, dynamic, feature layer, features, rendering, static

Sample Code

FeatureLayerRenderingModeSceneViewController.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// 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 FeatureLayerRenderingModeSceneViewController: UIViewController {
    @IBOutlet private weak var dynamicSceneView: AGSSceneView!
    @IBOutlet private weak var staticSceneView: AGSSceneView!

    private let zoomedOutCamera = AGSCamera(lookAt: AGSPoint(x: -118.37, y: 34.46, spatialReference: .wgs84()), distance: 42000, heading: 0, pitch: 0, roll: 0)
    private let zoomedInCamera = AGSCamera(lookAt: AGSPoint(x: -118.45, y: 34.395, spatialReference: .wgs84()), distance: 2500, heading: 90, pitch: 75, roll: 0)

    /// The length of one animation, zooming in or out.
    private let animationDurationInSeconds = 5.0

    /// The flag indicating the zoom state of the view.
    private var zoomedIn = false

    override func viewDidLoad() {
        super.viewDidLoad()

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

        for view in [staticSceneView, dynamicSceneView] {
            // create and assign scenes to the scene views
            view?.scene = AGSScene()
            // set the initial viewpoint cameras with the zoomed out camera
            view?.setViewpointCamera(zoomedOutCamera)
            // disable user interaction to prevent the viewpoints from getting out of sync
            view?.isUserInteractionEnabled = false
        }

        // create service feature tables using point, polygon, and polyline services
        let pointTable = AGSServiceFeatureTable(url: URL(string: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/Energy/Geology/FeatureServer/0")!)
        let polylineTable = AGSServiceFeatureTable(url: URL(string: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/Energy/Geology/FeatureServer/8")!)
        let polygonTable = AGSServiceFeatureTable(url: URL(string: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/Energy/Geology/FeatureServer/9")!)

        // loop through all the tables in the order we want to add them, bottom to top
        for featureTable in [polygonTable, polylineTable, pointTable] {
            // create a feature layer for the table
            let dynamicFeatureLayer = AGSFeatureLayer(featureTable: featureTable)
            // create a second, identical feature layer from the first
            let staticFeatureLayer = dynamicFeatureLayer.copy() as! AGSFeatureLayer

            // set the rendering modes for each layer
            dynamicFeatureLayer.renderingMode = .dynamic
            staticFeatureLayer.renderingMode = .static

            // add the layers to their corresponding scenes
            dynamicSceneView.scene?.operationalLayers.add(dynamicFeatureLayer)
            staticSceneView.scene?.operationalLayers.add(staticFeatureLayer)
        }
    }

    @IBAction func animateZoomAction(_ sender: UIBarButtonItem) {
        // disable the button during the animation
        sender.isEnabled = false

        /// The title for the bar button following the animation.
        let targetTitle = zoomedIn ? "Zoom In" : "Zoom Out"

        // toggle between the zoomed in and zoomed out cameras
        let targetCamera = zoomedIn ? zoomedOutCamera : zoomedInCamera

        // start the animation to the opposite viewpoint in both scenes
        dynamicSceneView.setViewpointCamera(targetCamera, duration: animationDurationInSeconds)
        staticSceneView.setViewpointCamera(targetCamera, duration: animationDurationInSeconds) { [weak self] _ in
            // we only need to run the completion handler for one view

            // update the title for the new state
            sender.title = targetTitle
            // re-enable the button
            sender.isEnabled = true
            // update the model
            self?.zoomedIn.toggle()
        }
    }
}

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