ArcGIS Runtime SDK for Java

Map Image Layer Sublayer Visibility



 * 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
 * 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.imagelayers.map_image_layer_sublayer_visibility;

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.CheckBox;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.CornerRadii;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Paint;
import javafx.stage.Stage;

import com.esri.arcgisruntime.layers.ArcGISMapImageLayer;
import com.esri.arcgisruntime.layers.SublayerList;
import com.esri.arcgisruntime.mapping.ArcGISMap;
import com.esri.arcgisruntime.mapping.Basemap;
import com.esri.arcgisruntime.mapping.view.MapView;

public class MapImageLayerSublayerVisibilitySample extends Application {

  private MapView mapView;

  // World Topo Map Service URL
  private static final String WORLD_CITIES_SERVICE =

  public void start(Stage stage) {

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

      // size the stage and add a title
      stage.setTitle("Map Image Layer Sublayer Visibility Sample");

      // create a control panel
      VBox controlsVBox = new VBox(6);
      controlsVBox.setBackground(new Background(new BackgroundFill(Paint.valueOf("rgba(0,0,0,0.3)"), CornerRadii.EMPTY,
      controlsVBox.setPadding(new Insets(10.0));
      controlsVBox.setMaxSize(180, 130);

      // create checkboxes for each sublayer
      CheckBox citiesBox = new CheckBox("Cities");
      CheckBox continentsBox = new CheckBox("Continents");
      CheckBox worldBox = new CheckBox("World");

      controlsVBox.getChildren().addAll(citiesBox, continentsBox, worldBox);
      controlsVBox.getChildren().forEach(c -> ((CheckBox) c).setSelected(true));

      // create a ArcGISMap with the a BasemapType Topographic
      ArcGISMap map = new ArcGISMap(Basemap.Type.TOPOGRAPHIC, 48.354406, -99.998267, 2);

      // create a Image Layer with dynamically generated ArcGISMap images
      ArcGISMapImageLayer imageLayer = new ArcGISMapImageLayer(WORLD_CITIES_SERVICE);

      // add world cities layers as ArcGISMap operational layer

      // set the ArcGISMap to be displayed in this view
      mapView = new MapView();

      // get the layers from the ArcGISMap image layer
      SublayerList layers = imageLayer.getSublayers();

      // handle sub layer selection
      citiesBox.selectedProperty().addListener(e -> layers.get(0).setVisible(citiesBox.isSelected()));
      continentsBox.selectedProperty().addListener(e -> layers.get(1).setVisible(continentsBox.isSelected()));
      worldBox.selectedProperty().addListener(e -> layers.get(2).setVisible(worldBox.isSelected()));

      // add the MapView and checkboxes
      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.

  public void stop() {

    // releases resources when the application closes
    if (mapView != null) {

   * Starting point of this application.
   * @param args arguments to this application.
  public static void main(String[] args) {


In this topic
  1. Code