Display dimensions

View on GitHubSample viewer app

Display dimension features from a mobile map package.

Image showing the Display Dimensions sample

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 "Settings" button, and apply a definition expression to show dimensions of greater than or equal to 450m in length using the "Definition Expression" checkbox.

How it works

  1. Create a MobileMapPackage specifying the path to the .mmpk file.
  2. Load the mobile map package with mobileMapPackage.loadAsync().
  3. After it successfully loads, get the first map from the mmpk and set it to the map view: mapView.map = mobileMapPackage.maps[0].
  4. Loop through the map's layers to create a DimensionLayer.
  5. Control the dimension layer's visibility with dimensionLayer.isVisible and set a definition expression with dimensionLayer.definitionExpression.

Relevant API

  • DimensionLayer
  • MobileMapPackage

Offline data

  1. Download the data from ArcGIS Online.
  2. Open your command prompt and navigate to the folder where you extracted the contents of the data from step 1.
  3. Execute the following commands:

adb push Edinburgh_Pylon_Dimensions.mmpk /Android/data/com.esri.arcgisruntime.sample.displaydimensions/files/Edinburgh_Pylon_Dimensions.mmpk

Link Local Location
Edinburgh_Pylon_Dimensions.mmpk /Android/data/com.esri.arcgisruntime.sample.displaydimensions/cache/Edinburgh_Pylon_Dimensions.mmpk

About the data

This sample shows a subset of the Edinburgh, Scotland network of pylons, substations, and powerlines within an Edinburgh Pylon Dimensions mobile map package, digitized from satellite imagery. Note the data is intended as illustrative of the network 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

dimension, layer, mmpk, mobile map package, utility

Sample Code

MainActivity.kt
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
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
/* Copyright 2022 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.
 *
 */

package com.esri.arcgisruntime.sample.displaydimensions

import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.constraintlayout.widget.ConstraintLayout
import com.esri.arcgisruntime.layers.DimensionLayer
import com.esri.arcgisruntime.loadable.LoadStatus
import com.esri.arcgisruntime.mapping.MobileMapPackage
import com.esri.arcgisruntime.mapping.view.MapView
import com.esri.arcgisruntime.sample.displaydimensions.databinding.ActivityMainBinding
import com.esri.arcgisruntime.sample.displaydimensions.databinding.DimensionsDialogLayoutBinding


class MainActivity : AppCompatActivity() {

    private val TAG: String = MainActivity::class.java.simpleName

    private lateinit var dimensionLayer: DimensionLayer
    private var isDimensionLayerEnabled: Boolean = true
    private var isDefinitionEnabled: Boolean = false


    private val activityMainBinding by lazy {
        ActivityMainBinding.inflate(layoutInflater)
    }

    private val mapView: MapView by lazy {
        activityMainBinding.mapView
    }

    private val settingsButton: ConstraintLayout by lazy {
        activityMainBinding.settingsLayout
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(activityMainBinding.root)

        // create and load a mobile map package
        val mobileMapPackage =
            MobileMapPackage(getExternalFilesDir(null)?.path + "/Edinburgh_Pylon_Dimensions.mmpk")

        mobileMapPackage.addDoneLoadingListener {
            // check the mmpk has loaded successfully and that it contains a map
            if (mobileMapPackage.loadStatus == LoadStatus.LOADED && mobileMapPackage.maps.isNotEmpty()) {
                // add the map from the mobile map package to the map view, and set a min scale to maintain dimension readability
                mapView.map = mobileMapPackage.maps[0]
                mapView.map.minScale = 35000.0

                // find the dimension layer within the map
                dimensionLayer =
                    mapView.map.operationalLayers.firstOrNull { it is DimensionLayer } as DimensionLayer
            } else {
                val errorMessage =
                    "Failed to load the mobile map package: " + mobileMapPackage.loadError.message
                Log.e(TAG, errorMessage)
                Toast.makeText(
                    this,
                    errorMessage,
                    Toast.LENGTH_SHORT
                ).show()
            }
        }

        mobileMapPackage.loadAsync()

        settingsButton.setOnClickListener {
            // inflate the dialog layout and get references to each of its components
            val dialogBinding = DimensionsDialogLayoutBinding.inflate(LayoutInflater.from(this))
            val dimensionLayerSwitch = dialogBinding.dimensionLayerSwitch.apply {
                isChecked = isDimensionLayerEnabled
            }
            val definitionSwitch = dialogBinding.definitionSwitch.apply {
                isChecked = isDefinitionEnabled
            }

            // set up the dialog
            AlertDialog.Builder(this).apply {
                setView(dialogBinding.root)
                setTitle("Dimension options:")

                dimensionLayerSwitch.setOnCheckedChangeListener { _, isEnabled ->
                    // set the visibility of the dimension layer
                    dimensionLayer.isVisible = isEnabled
                    isDimensionLayerEnabled = isEnabled
                }


                definitionSwitch.setOnCheckedChangeListener { _, isEnabled ->
                    // set a definition expression to show dimension lengths of
                    // greater than or equal to 450m when the checkbox is selected,
                    // or to reset the definition expression to show all
                    // dimension lengths when unselected
                    val defExpression =
                        if (isEnabled) "DIMLENGTH >= 450" else ""
                    dimensionLayer.definitionExpression = defExpression
                    isDefinitionEnabled = isEnabled

                }

            }.show()
        }
    }

    override fun onPause() {
        mapView.pause()
        super.onPause()
    }

    override fun onResume() {
        super.onResume()
        mapView.resume()
    }

    override fun onDestroy() {
        mapView.dispose()
        super.onDestroy()
    }
}

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