Display dimensions

View on GitHub

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

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

How it works

  1. Create a MobileMapPackage specifying the path to the .mmpk file.
  2. Load the mobile map package (mmpk) with mmpk.load().
  3. After the mmpk successfully loads, get the map from the mmpk map = mmpk.maps.first.
  4. Loop through the map's layers to find the DimensionLayer and get the layer name to display on the UI with DimensionLayer.name.
  5. Add the map to the map view: mapViewController.arcGISMap = map
  6. Control the dimension layer's visibility with DimensionLayer.isVisible = <bool> and set a definition expression with DimensionLayer.definitionExpression = <String>.

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 a 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

display_dimensions.dart
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
// Copyright 2024 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
//
//   https://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 'dart:io';

import 'package:arcgis_maps/arcgis_maps.dart';
import 'package:flutter/material.dart';
import 'package:path_provider/path_provider.dart';

import '../../utils/sample_data.dart';
import '../../utils/sample_state_support.dart';

class DisplayDimensions extends StatefulWidget {
  const DisplayDimensions({super.key});

  @override
  State<DisplayDimensions> createState() => _DisplayDimensionsState();
}

class _DisplayDimensionsState extends State<DisplayDimensions>
    with SampleStateSupport {
  // Create a controller for the map view.
  final _mapViewController = ArcGISMapView.createController();

  // A flag for when the map view is ready and controls can be used.
  var _ready = false;

  // The DimensionLayer showing the dimensions on the map.
  late final DimensionLayer _dimensionLayer;

  // The state variable to show the name of the dimension layer.
  var _dimensionLayerName = '';

  // Switch states for the dimension layer and definition expression.
  var _showDimensionLayer = true;
  var _isDefinitionExpressionApplied = false;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        top: false,
        child: Stack(
          children: [
            Column(
              children: [
                Expanded(
                  // Add a map view to the widget tree and set a controller.
                  child: ArcGISMapView(
                    controllerProvider: () => _mapViewController,
                    onMapViewReady: onMapViewReady,
                  ),
                ),
                Container(
                  margin: const EdgeInsets.fromLTRB(15, 0, 15, 0),
                  child: Column(
                    children: [
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          const Text('Dimension layer name: '),
                          Text(_dimensionLayerName),
                        ],
                      ),
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          const Text('Dimension layer'),
                          Switch(
                            value: _showDimensionLayer,
                            onChanged: showDimensionLayer,
                          ),
                        ],
                      ),
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          const Text(
                            'Definition Expression: Dimensions >= 450m',
                          ),
                          Switch(
                            value: _isDefinitionExpressionApplied,
                            onChanged: applyDefinitionExpression,
                          ),
                        ],
                      ),
                    ],
                  ),
                ),
              ],
            ),
            // Display a progress indicator and prevent interaction until state is ready.
            Visibility(
              visible: !_ready,
              child: const SizedBox.expand(
                child: ColoredBox(
                  color: Colors.white30,
                  child: Center(child: CircularProgressIndicator()),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }

  void onMapViewReady() async {
    // Download the mobile map package.
    await downloadSampleData(['f5ff6f5556a945bca87ca513b8729a1e']);

    // Load the local mobile map package.
    final appDir = await getApplicationDocumentsDirectory();
    final mmpkFile =
        File('${appDir.absolute.path}/Edinburgh_Pylon_Dimensions.mmpk');
    final mmpk = MobileMapPackage.withFileUri(mmpkFile.uri);
    await mmpk.load();

    if (mmpk.maps.isNotEmpty) {
      // Get the first map in the mobile map package and set to the map view.
      final map = mmpk.maps.first;

      // Get the dimension layer from the map's operational layers.
      _dimensionLayer = map.operationalLayers.whereType<DimensionLayer>().first;

      // Set an initial viewpoint for the map.
      map.initialViewpoint = Viewpoint.fromCenter(
        ArcGISPoint(
          x: -368015.99460377498,
          y: 7540290.3376379032,
          spatialReference: SpatialReference.webMercator,
        ),
        scale: 30000,
      );

      // Set the map to the map view.
      _mapViewController.arcGISMap = map;
    }

    // Set the ready state variable to true to enable the sample UI.
    setState(() {
      _dimensionLayerName = _dimensionLayer.name;
      _ready = true;
    });
  }

  // Function that shows or hides the dimension layer on the map.
  void showDimensionLayer(bool show) {
    _dimensionLayer.isVisible = show;
    setState(() => _showDimensionLayer = show);
  }

  // Function that applies or removes the definition expression to the dimension layer.
  void applyDefinitionExpression(bool apply) {
    final definitionExpression = apply ? 'DIMLENGTH >= 450' : '';
    _dimensionLayer.definitionExpression = definitionExpression;
    setState(() => _isDefinitionExpressionApplied = apply);
  }
}

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