Skip to content

Display dimensions

View on GitHubSample 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. Create a MobileMapPackage specifying the path to the .mmpk file.
  2. Load the mobile map package.
  3. After the mmpk successfully loads, get the map from the mmpk m_map = m_mmpk->maps().at(0) and add it to the map view: m_mapView->setMap(m_map).
  4. Loop through the map's layers to find the DimensionLayer and assign it to m_dimensionLayer.
  5. Set the title of the controls box using m_dimensionLayer->name().
  6. Control the dimension layer's visibility with m_dimensionLayer->setVisible(boolean) and set a definition expression with m_dimensionLayer->setDefinitionExpression(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 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.cppDisplayDimensions.cppDisplayDimensions.hDisplayDimensions.qml
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 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 // [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]  #ifdef PCH_BUILD #include "pch.hpp" #endif // PCH_BUILD  // sample headers #include "DisplayDimensions.h"  // ArcGIS Maps SDK headers #include "DimensionLayer.h" #include "Error.h" #include "LayerListModel.h" #include "Map.h" #include "MapQuickView.h" #include "MapTypes.h" #include "MobileMapPackage.h"  // Qt headers #include <QStandardPaths>  using namespace Esri::ArcGISRuntime;  namespace {  // Helper method to get cross platform data path.  QString defaultDataPath()  {  QString dataPath;   #ifdef Q_OS_IOS  dataPath = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);  #else  dataPath = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);  #endif   return dataPath;  }   // Sample MMPK location.  const QString edinburghPylonFilePath {"/ArcGIS/Runtime/Data/mmpk/Edinburgh_Pylon_Dimensions.mmpk"}; }  DisplayDimensions::DisplayDimensions(QObject* parent /* = nullptr */):  QObject(parent) {  QString mapPackagePath = defaultDataPath() + edinburghPylonFilePath;  m_mmpk = new MobileMapPackage(mapPackagePath, this);   // Make connections between the mmpk's doneLoading and errorOccurred signal and the addMapToMapView and handleError methods respectively.  connect(m_mmpk, &MobileMapPackage::doneLoading, this, &DisplayDimensions::addMapToMapView);  connect(m_mmpk, &MobileMapPackage::errorOccurred, this, &DisplayDimensions::handleError);   // Load the mmpk.  m_mmpk->load(); }  DisplayDimensions::~DisplayDimensions() = default;  void DisplayDimensions::init() {  // Register the map view for QML  qmlRegisterType<MapQuickView>("Esri.Samples", 1, 0, "MapView");  qmlRegisterType<DisplayDimensions>("Esri.Samples", 1, 0, "DisplayDimensionsSample"); }  void DisplayDimensions::addMapToMapView(const Error& error) {  // If no errors have occurred, the mmpk is loaded, and there is only one map in the mmpk, the map  // in the mmpk can be assigned to the MapView. Any errors will be managed by the handleError method.  if (error.isEmpty() && m_mmpk->loadStatus() == LoadStatus::Loaded && m_mmpk->maps().count() > 0)  {  // Enable the checkboxes.  setDimensionsAvailable(true);   // Assign the map in the mmpk to m_map.  m_map = m_mmpk->maps().at(0);   // Set the minimum scale to prevent zooming out too far.  m_map->setMinScale(35000);   // Check to ensure that m_mapView has been initialised properly.  if (m_mapView != nullptr)  {  // Set m_map as the MapView's map.  m_mapView->setMap(m_map);  }   // From the map's layers, find the Dimension Layer.  findDimensionLayer();  }  else  {  // If the map hasn't loaded or an error has occurred, disable the checkboxes in the UI.  setDimensionsAvailable(false);  } }  void DisplayDimensions::findDimensionLayer() {  LayerListModel* layers = m_mapView->map()->operationalLayers();   for (Layer* layer : *layers)  {  if (layer->layerType() == LayerType::DimensionLayer)  {  // The current layer, which is the DimensionLayer, has type Layer*. Ths needs to be converted to a DimensionLayer*.  m_dimensionLayer = static_cast<DimensionLayer*>(layer);  // Use the name of the Dimension Layer to define the title of the UI element.  setDimensionLayerName(m_dimensionLayer->name());  // There is only one Dimension Layer, so we can break out of the loop.  break;  }  } }  void DisplayDimensions::handleError(const Error& error) {  if (error.additionalMessage().isEmpty())  setErrorMessage(error.message());  else  setErrorMessage(error.message() + "\n" + error.additionalMessage()); }  MapQuickView* DisplayDimensions::mapView() const {  return m_mapView; }  // Set the view (created in QML) void DisplayDimensions::setMapView(MapQuickView* mapView) {  if (!mapView || mapView == m_mapView)  return;   m_mapView = mapView;   if (m_map)  m_mapView->setMap(m_map);   emit mapViewChanged(); }  QString DisplayDimensions::errorMessage() {  return m_errorMessage; }  void DisplayDimensions::setErrorMessage(const QString& message) {  m_errorMessage = message;  emit errorMessageChanged(); }  QString DisplayDimensions::dimensionLayerName() const {  return m_dimensionLayerName; }  void DisplayDimensions::setDimensionLayerName(const QString& name) {  m_dimensionLayerName = name;  emit dimensionLayerNameChanged(); }  bool DisplayDimensions::dimensionLayerVisible() const {  return m_dimensionLayer && m_dimensionLayer->isVisible(); }  void DisplayDimensions::setDimensionLayerVisible(bool visible) {  m_dimensionLayer->setVisible(visible); }  bool DisplayDimensions::useDefinitionExpression() const {  return m_dimensionLayer && !m_dimensionLayer->definitionExpression().isEmpty(); }  void DisplayDimensions::setUseDefinitionExpression(bool applied) {  if (applied)  m_dimensionLayer->setDefinitionExpression("DIMLENGTH >= 450");  else  m_dimensionLayer->setDefinitionExpression(""); }  bool DisplayDimensions::dimensionsAvailable() {  return m_dimensionsAvailable; }  void DisplayDimensions::setDimensionsAvailable(bool status) {  m_dimensionsAvailable = status;  emit dimensionsAvailableChanged(); }

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