Display dimensions

View inMAUIWPFWinUIView 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 "Dimension Layer visibility" check box, 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. Load a MobileMapPackage that contains DimensionLayer
  2. After it successfully loads, get the map from the mmpk and add it to the map view: mobileMapPackage.Maps.First().
  3. Get the DimensionLayer from the map view and set the name of the layer to the UI with dimensionLayer.Name.
  4. Control the dimension layer's visibility with dimensionLayer.IsVisible and set a definition expression with dimensionLayer.DefinitionExpression.

Relevant API

  • DimensionLayer
  • MobileMapPackage

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

DisplayDimensions.xaml.csDisplayDimensions.xaml.csDisplayDimensions.xaml
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
// 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.

using ArcGIS.Samples.Managers;
using Esri.ArcGISRuntime.Mapping;
using System;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;

namespace ArcGIS.WPF.Samples.DisplayDimensions
{
    [ArcGIS.Samples.Shared.Attributes.Sample(
        name: "Display dimensions",
        category: "Layers",
        description: "Display dimension features from a mobile map package.",
        instructions: "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 of greater than or equal to 450m in length using the \"Definition Expression\" checkbox.",
        tags: new[] { "dimension", "layer", "mmpk", "mobile map package", "utility" })]
    [ArcGIS.Samples.Shared.Attributes.OfflineData("f5ff6f5556a945bca87ca513b8729a1e")]
    public partial class DisplayDimensions
    {
        // Hold a reference to the Dimension layer for use in event handlers
        private DimensionLayer _dimensionLayer;

        public DisplayDimensions()
        {
            InitializeComponent();
            _ = Initialize();
        }

        private async Task Initialize()
        {
            try
            {
                // Get the path to the map package. DataManager is a sample viewer tool, not part of ArcGIS Maps SDK for .NET.
                var dataPath = DataManager.GetDataFolder("f5ff6f5556a945bca87ca513b8729a1e", "Edinburgh_Pylon_Dimensions.mmpk");

                // Load the mobile map package.
                MobileMapPackage mobileMapPackage = new MobileMapPackage(dataPath);
                await mobileMapPackage.LoadAsync();

                // Set the mapview to display the map from the package.
                MyMapView.Map = mobileMapPackage.Maps.First();

                // Set the minimum scale range of the sample to maintain readability of dimension features.
                MyMapView.Map.MinScale = 35000;

                // Get the dimension layer from the MapView operational layers.
                _dimensionLayer = MyMapView.Map.OperationalLayers.OfType<DimensionLayer>().First();

                // Enable the check boxes.
                DimensionLayerCheckBox.IsEnabled = true;
                DefinitionExpressionCheckBox.IsEnabled = true;

                // Set the label content.
                PylonLabel.Content = _dimensionLayer.Name;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.GetType().Name, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }

        private void DimensionLayerCheckBoxChanged(object sender, System.Windows.RoutedEventArgs e)
        {
            // Check if dimension layer has been instantiated.
            if (_dimensionLayer != null)
            {
                // Set the visibility of the dimension layer.
                _dimensionLayer.IsVisible = DimensionLayerCheckBox.IsChecked == true;
            }
        }

        private void DefinitionExpressionCheckBoxChanged(object sender, System.Windows.RoutedEventArgs e)
        {
            // Create 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.
            string definitionExpression = DefinitionExpressionCheckBox.IsChecked == true ? "DIMLENGTH >= 450" : "";

            // Check if dimension layer has been instantiated.
            if (_dimensionLayer != null)
            {
                // Set the definition expression of the dimension layer.
                _dimensionLayer.DefinitionExpression = definitionExpression;
            }
        }
    }
}

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