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 "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. Create a MobileMapPackage specifying the path to the .mmpk file.
  2. Load the mobile map package with mmpk.loadAsync().
  3. After it successfully loads, get the map from the mmpk and add it to the map view: mapView.setMap(mmpk.getMaps().get(0)).
  4. Loop through the map's layers to create a DimensionLayer and set the name of the layer to the UI with dimensionLayer.getName().
  5. Control the dimension layer's visibility with dimensionLayer.setVisible(boolean) and set a definition expression with dimensionLayer.setDefinitionExpression(String).

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

DisplayDimensionsSample.java
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
/*
 * 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.
 */

package com.esri.samples.display_dimensions;

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
import javafx.scene.layout.*;
import javafx.scene.paint.Paint;
import javafx.stage.Stage;

import com.esri.arcgisruntime.layers.DimensionLayer;
import com.esri.arcgisruntime.layers.Layer;
import com.esri.arcgisruntime.loadable.LoadStatus;
import com.esri.arcgisruntime.mapping.MobileMapPackage;
import com.esri.arcgisruntime.mapping.view.MapView;

import java.io.File;
import java.util.Objects;

public class DisplayDimensionsSample extends Application {

  private DimensionLayer dimensionLayer;
  private MapView mapView;
  private MobileMapPackage mobileMapPackage; // keep loadable in scope to avoid garbage collection

  @Override
  public void start(Stage stage) {
    try {
      // create stack pane and application scene
      StackPane stackPane = new StackPane();
      Scene scene = new Scene(stackPane);
      scene.getStylesheets().add(Objects.requireNonNull(getClass().getResource("/display_dimensions/style.css")).toExternalForm());

      // set title, size, and add scene to stage
      stage.setTitle("Display Dimensions Sample");
      stage.setWidth(800);
      stage.setHeight(700);
      stage.setScene(scene);
      stage.show();

      // set up display label for dimension layer name, and check boxes for controlling visibility and definition expression
      Label dimensionLayerName = new Label();
      CheckBox visibilityCheckBox = new CheckBox("Dimension Layer visibility");
      visibilityCheckBox.setSelected(true);
      CheckBox defExpressionCheckBox = new CheckBox("Definition Expression:" + "\n" + "Dimensions >= 450m");
      defExpressionCheckBox.setWrapText(true);

      // add the label and checkboxes to a JavaFX VBox
      VBox controlsVBox = new VBox(6);
      controlsVBox.setBackground(new Background(new BackgroundFill(Paint.valueOf("rgba(0,0,0,0.5)"), CornerRadii.EMPTY,
        Insets.EMPTY)));
      controlsVBox.setPadding(new Insets(10.0));
      controlsVBox.setMaxSize(220, 120);
      controlsVBox.getStyleClass().add("panel-region");
      controlsVBox.getChildren().addAll(dimensionLayerName, visibilityCheckBox, defExpressionCheckBox);
      controlsVBox.setDisable(true);

      // create a map view
      mapView = new MapView();

      // create and load a mobile map package
      final String mmpkPath = new File(System.getProperty("data.dir"), "./samples-data/mmpk/EdinburghPylonsDimensions.mmpk").getAbsolutePath();
      mobileMapPackage = new MobileMapPackage(mmpkPath);

      mobileMapPackage.addDoneLoadingListener(() -> {
        // check the mmpk has loaded successfully and that it contains a map
        if (mobileMapPackage.getLoadStatus() == LoadStatus.LOADED && !mobileMapPackage.getMaps().isEmpty()) {
          // add the map from the mobile map package to the map view, and set a min scale to maintain dimension readability
          mapView.setMap(mobileMapPackage.getMaps().get(0));
          mapView.getMap().setMinScale(35000);

          // find the dimension layer within the map
          for (Layer layer : mapView.getMap().getOperationalLayers()) {
            if (layer instanceof DimensionLayer) {
              dimensionLayer = (DimensionLayer) layer;
              // set the label to the name of the dimension layer
              dimensionLayerName.setText(dimensionLayer.getName());
              // enable the vbox for dimension layer controls
              controlsVBox.setDisable(false);
              visibilityCheckBox.setSelected(dimensionLayer.isVisible());
            }
          }
        } else {
          new Alert(Alert.AlertType.ERROR, "Failed to load the mobile map package").show();
        }
      });
      mobileMapPackage.loadAsync();

      // 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
      defExpressionCheckBox.setOnAction(e -> {
        String defExpression = defExpressionCheckBox.isSelected() ? "DIMLENGTH >= 450" : "";
        dimensionLayer.setDefinitionExpression(defExpression);
      });

      // set the visibility of the dimension layer
      visibilityCheckBox.setOnAction(e -> dimensionLayer.setVisible(visibilityCheckBox.isSelected()));

      // add the map view to stack pane
      stackPane.getChildren().addAll(mapView, controlsVBox);
      StackPane.setAlignment(controlsVBox, Pos.TOP_LEFT);
      StackPane.setMargin(controlsVBox, new Insets(10, 0, 0, 10));
    } catch(Exception e){
      // on any error, display the stack trace.
      e.printStackTrace();
    }
  }

  /**
   * Stops and releases all resources used in application.
   */
  @Override
  public void stop() {

    if (mapView != null) {
      mapView.dispose();
    }
  }

  /**
   * Opens and runs application.
   *
   * @param args arguments passed to this application
   */
  public static void main(String[] args) {

    Application.launch(args);
  }
}

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