Display Layer View State Status

Demonstrates how to get the view status of layers in a ArcGISMap.

How it works

To use the MapView's DrawStatus:

  1. Create an ArcGISMap.
  2. Set the map to the MapView, MapView.setMap().
  3. Add the MapView.addLayerViewStateChangedListener() property and listen for when the Layer.getLayerViewStatus()changes.


 * Copyright 2017 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.mapview.display_layer_view_state_status;

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

import com.esri.arcgisruntime.data.ServiceFeatureTable;
import com.esri.arcgisruntime.geometry.Point;
import com.esri.arcgisruntime.geometry.SpatialReferences;
import com.esri.arcgisruntime.layers.ArcGISMapImageLayer;
import com.esri.arcgisruntime.layers.ArcGISTiledLayer;
import com.esri.arcgisruntime.layers.FeatureLayer;
import com.esri.arcgisruntime.layers.Layer;
import com.esri.arcgisruntime.mapping.ArcGISMap;
import com.esri.arcgisruntime.mapping.Viewpoint;
import com.esri.arcgisruntime.mapping.view.MapView;

public class DisplayLayerViewStateStatusSample extends Application {

  private MapView mapView;

  private static final int MIN_SCALE = 40000000;
  private static final int TILED_LAYER = 0;
  private static final int IMAGE_LAYER = 1;
  private static final int FEATURE_LAYER = 2;

  private static final String SERVICE_TIME_ZONES =
  private static final String SERVICE_CENSUS =
  private static final String SERVICE_RECREATION =

  public void start(Stage stage) throws Exception {

    try {
      // create stack pane and application scene
      StackPane stackPane = new StackPane();
      Scene scene = new Scene(stackPane);

      // set title, size, and add scene to stage
      stage.setTitle("Display Layer View State Status Sample");

      // create a control panel
      VBox vBoxControl = new VBox(6);
      vBoxControl.setMaxSize(220, 90);

      // create labels to display the view status of each layer
      Label worldTimeZonesLabel = new Label("World Time Zones: ");
      Label censusLabel = new Label("Census: ");
      Label facilitiesLabel = new Label("Facilities: ");


      // add labels to the control panel
      vBoxControl.getChildren().addAll(worldTimeZonesLabel, censusLabel, facilitiesLabel);

      // create three layers to add to the ArcGISMap
      final ArcGISTiledLayer tiledLayer = new ArcGISTiledLayer(SERVICE_TIME_ZONES);

      // this layer will be OUT_OF_SCALE outside of its set min/max scales
      final ArcGISMapImageLayer imageLayer = new ArcGISMapImageLayer(SERVICE_CENSUS);
      imageLayer.setMaxScale(MIN_SCALE / 10);

      // creating a layer from a service feature table
      final ServiceFeatureTable featureTable = new ServiceFeatureTable(SERVICE_RECREATION);
      final FeatureLayer featureLayer = new FeatureLayer(featureTable);

      // adding layers to the ArcGISMaps' layer list
      final ArcGISMap map = new ArcGISMap();

      // create a view and set ArcGISMap to it
      mapView = new MapView();

      // set viewpoint
      mapView.setViewpoint(new Viewpoint(new Point(-11e6, 45e5, SpatialReferences.getWebMercator()), MIN_SCALE));

      // fires every time a layers' view status has changed
      mapView.addLayerViewStateChangedListener(e -> {
        // holds the label that needs to be changed
        Layer layer = e.getLayer();

        String viewStatus = e.getLayerViewStatus().iterator().next().toString();
        final int layerIndex = map.getOperationalLayers().indexOf(layer);

        // finding and updating label that needs to be changed
        switch (layerIndex) {
          case TILED_LAYER:
            worldTimeZonesLabel.setText("World Time Zones: " + viewStatus);
          case IMAGE_LAYER:
            censusLabel.setText("Census: " + viewStatus);
          case FEATURE_LAYER:
            facilitiesLabel.setText("Facilities: " + viewStatus);

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

   * Stops and releases all resources used in application.
  public void stop() throws Exception {

    if (mapView != null) {

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



In this topic
  1. How it works
  2. Code