Display dimension features from a mobile map package.
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
- Create a
MobileMapPackage
specifying the path to the .mmpk file. - Load the mobile map package (mmpk) with
mmpk.load()
. - After the mmpk successfully loads, get the map from the mmpk
map = mmpk.maps.first
. - Loop through the map's layers to find the
DimensionLayer
and get the layer name to display on the UI withDimensionLayer.name
. - Add the map to the map view:
mapViewController.arcGISMap = map
- Control the dimension layer's visibility with
DimensionLayer.isVisible = <bool>
and set a definition expression withDimensionLayer.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
// 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);
}
}