Display dimensions

View inQMLC++
View on GitHub
Sample viewer app

Display dimension features from a mobile map package.

screenshot

Use case

Dimensions show specific lengths or distances on a map. A dimension may indicate the length of a side of a building or land parcel, or the distance between two features, such as a fire hydrant and the corner of a building.

How to use the sample

When the sample loads, it will automatically display the map containing dimension features from the mobile map package. The name of the dimension layer containing the dimension features is displayed in the controls box. Control the visibility of the dimension layer with the "Dimension Layer visibility" check box, and apply a definition expression to show dimensions greater than or equal to 450m in length using the "Definition Expression" check box.

Note: the minimum scale range of the sample is set to 1:35000 to maintain readability of the dimension features.

How it works

  1. Declare a MobileMapPackage specifying the path to the .mmpk file.
  2. Load the mobile map package with mmpk.load() when the MapView component has been instantiated.
  3. After the mmpk successfully loads, get the map from the mmpk and add it to the map view: mapView.map = mmpk.maps[0];.
  4. Loop through the map's layers to find the DimensionLayer and assign the index of the dimension layer to indexOfDimensionLayer.
  5. Set the title of the controls box using mmpk.maps[0].operationalLayers.get(counter).name.
  6. Control the dimension layer's visibility with mmpk.maps[0].operationalLayers.get(indexOfDimensionLayer).visible and set a definition expression with mmpk.maps[0].operationalLayers.get(indexOfDimensionLayer).definitionExpression.

Relevant API

  • DimensionLayer
  • MobileMapPackage

About the data

This sample shows a subset of the network of pylons, substations, and power lines around Edinburgh, Scotland within an Edinburgh Pylon Dimensions mobile map package. The data was digitised from satellite imagery and is intended to be used for illustrative purposes only.

Additional information

Dimension layers can be taken offline from a feature service hosted on ArcGIS Enterprise 10.9 or later, using the GeodatabaseSyncTask. Dimension layers are also supported in mobile map packages or mobile geodatabases created in ArcGIS Pro 2.9 or later.

Tags

definition expression, dimension, distance, layer, length, mmpk, mobile map package, utility

Sample Code

DisplayDimensions.qml
Use dark colors for code blocks
                                                                                                                                                  
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// [WriteFile Name=DisplayDimensions, Category=Layers]
// [Legal]
// Copyright 2021 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.12
import QtQuick.Controls 2.12
import Esri.ArcGISRuntime 100.14
import Esri.ArcGISExtras 1.1
import QtQuick.Layouts 1.12
import QtQuick.Dialogs 1.2

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

    readonly property url dataPath: System.userHomePath + "/ArcGIS/Runtime/Data/mmpk/"
    property string errorMessage: ""
    property int indexOfDimensionLayer: 0

    MapView {
        id: mapView
        anchors.fill: parent

        Component.onCompleted: {
            // Set and keep the focus on MapView to enable keyboard navigation
            forceActiveFocus();
        }

        Control {
            id: toggleControl
            anchors {
                top: mapView.top
                topMargin: 10
                left: mapView.left
                leftMargin: 10
            }
            background: Rectangle {
                color: "white"
                border.color: "black"
            }
            padding: 5

            contentItem: GridLayout {
                columns: 1
                Text {
                    id: toggleBoxTitle
                }
                CheckBox {
                    id: visibilityToggle
                    text: "Dimension Layer visibility"
                    checked: true
                    onCheckStateChanged: mmpk.maps[0].operationalLayers.get(indexOfDimensionLayer).visible = visibilityToggle.checkState;
                    enabled: mmpk.loadStatus === Enums.LoadStatusLoaded ? true : false
                }
                CheckBox {
                    id: definitionExpressionToggle
                    text: "Definition Expression: \nDimensions >= 450m"
                    checked: false
                    onCheckStateChanged: {
                        if (definitionExpressionToggle.checkState === Qt.Checked) {
                            mmpk.maps[0].operationalLayers.get(indexOfDimensionLayer).definitionExpression = "DIMLENGTH >= 450";
                        }
                        else {
                            mmpk.maps[0].operationalLayers.get(indexOfDimensionLayer).definitionExpression = "";
                        }
                    }
                    enabled: mmpk.loadStatus === Enums.LoadStatusLoaded && visibilityToggle.checked ? true : false
                }
            }
        }

        // Pop-up error message box
        MessageDialog {
            id: errorMessageBox
            title: "Error message!"
            text: errorMessage
            icon: StandardIcon.Warning
            visible: errorMessage === "" ? false : true;
            onAccepted: errorMessage = "";
        }
    }

    Component.onCompleted: mmpk.load();

    MobileMapPackage {
        id: mmpk
        path: dataPath + "Edinburgh_Pylon_Dimensions.mmpk"

        onLoadStatusChanged: {
            // If an error occurred during loading, pass the error onto the handleError function.
            if (loadStatus === Enums.LoadStatusFailedToLoad) {
                handleError(mmpk.loadError);
            }

            // If the mmpk has not loaded, return.
            if (loadStatus !== Enums.LoadStatusLoaded) {
                return;
            }

            // If there is more than one map, return.
            if (mmpk.maps.length > 1) {
                return;
            }

            // Set the map view's map to the first map in the mobile map package
            mapView.map = mmpk.maps[0];
            // Set the minimum scale as 1:35000 to prevent zooming out too far.
            mapView.map.minScale = 35000;

            // Loop through all layers in the mmpk and find the dimension layer.
            for (let counter = 0; counter < mmpk.maps[0].operationalLayers.count; counter++) {
                // Check each layer to see if it is a DimensionLayer.
                if (mmpk.maps[0].operationalLayers.get(counter).layerType === Enums.LayerTypeDimensionLayer) {
                    // Save the index of the DimensionLayer - it is used to control layer visibility and definition expressions.
                    indexOfDimensionLayer = counter;
                    // Use the name of the DimensionLayer to define the title of the UI controls.
                    toggleBoxTitle.text = mmpk.maps[0].operationalLayers.get(counter).name;
                    // There is only one Dimension Layer, so we can break out of the loop.
                    break;
                }
            }

        }
    }

    function handleError(error) {
        if (!error.additionalMessage)
            errorMessage = error.message;
        else
            errorMessage = error.message + "\n" + error.additionalMessage;
    }
}

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