Sync map and scene views

View inC++QMLView on GitHubSample viewer app

Keep the viewpoints of two views (e.g. MapView and SceneView) synchronized with each other.

screenshot

Use case

You might need to synchronize GeoView viewpoints if you had two map views in one application - a main map and an inset. An inset map view could display all the layers at their full extent and contain a hollow rectangular graphic that represents the visible extent of the main map view. As you zoom or pan in the main map view, the extent graphic in the inset map would adjust accordingly.

How to use the sample

Interact with the MapView or SceneView by zooming or panning. The other MapView or SceneView will automatically focus on the same viewpoint.

How it works

  1. Wire up both MapView.viewpointChanged and SceneView.viewpointChanged signals for both geo views.
  2. In each slot, get the current viewpoint from the geo view that is being interacted with and then set the viewpoint of the other geo view to the same value.
  3. Note: The reason for setting the viewpoints in multiple slots is to account for different types of interactions that can occur (ie. single click pan -vs- continuous pan, single click zoom in -vs- mouse scroll wheel zoom, etc.).

Relevant API

  • currentViewpointCenter
  • GeoView
  • MapView
  • SceneView
  • setViewpoint
  • viewpointChanged

About the data

This application provides two different perspectives of the Imagery basemap. A 2D MapView as well as a 3D SceneView, displayed side by side.

Tags

3D, automatic refresh, event, event handler, events, extent, interaction, interactions, pan, sync, synchronize, zoom

Sample Code

SyncMapViewSceneView.qml
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// [WriteFile Name=SyncMapViewSceneView, Category=Scenes]
// [Legal]
// 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.
// [Legal]

import QtQuick 2.6
import QtQuick.Layouts 1.2
import Esri.ArcGISRuntime 100.15

Rectangle {
    id: rootRectangle
    clip: true
    width: 800
    height: 600

    states: [
        State {
            name: "orientHorizontal"
            when: width > height
            PropertyChanges {
                target: layout
                flow: GridLayout.LeftToRight
            }
        },
        State {
            name: "orientVertical"
            when: width <= height
            PropertyChanges {
                target: layout
                flow: GridLayout.TopToBottom
            }
        }
    ]

    GridLayout {
        id: layout
        anchors.fill: parent
        SceneView {
            id: sceneView
            Layout.fillWidth: true
            Layout.fillHeight: true

            Component.onCompleted: {
                // Set the focus on SceneView to initially enable keyboard navigation
                forceActiveFocus();
            }

            Scene {
                id: scene
                Basemap {
                    initStyle: Enums.BasemapStyleArcGISImageryStandard
                }
            }

            onViewpointChanged: {
                if (navigating) {
                    mapView.setViewpointAndSeconds(currentViewpointCenter, 0);
                }
            }
        }
        MapView {
            id: mapView
            Layout.fillWidth: true
            Layout.fillHeight: true
            rotationByPinchingEnabled: true

            Map {
                id: map
                Basemap {
                    initStyle: Enums.BasemapStyleArcGISImageryStandard
                }
            }

            onViewpointChanged: {
                if (navigating) {
                    sceneView.setViewpointAndSeconds(currentViewpointCenter, 0);
                }
            }
        }
    }
}

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