ArcGIS Runtime SDK for Java

Scale Bar



 * Copyright 2018 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.mapview.scale_bar;

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.CornerRadii;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

import com.esri.arcgisruntime.UnitSystem;
import com.esri.arcgisruntime.mapping.ArcGISMap;
import com.esri.arcgisruntime.mapping.Basemap;
import com.esri.arcgisruntime.mapping.view.MapView;
import com.esri.arcgisruntime.toolkit.Scalebar;

public class ScaleBarSample extends Application {

  private MapView mapView;

  public void start(Stage stage) {

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

    // set title, size and scene to stage
    stage.setTitle("Scale Bar Sample");

    // create a map view
    mapView = new MapView();
    ArcGISMap map = new ArcGISMap(Basemap.Type.IMAGERY, 64.1405, -16.2426, 16);

    // create a scale bar for the map view
    Scalebar scaleBar = new Scalebar(mapView);

    // specify skin style for the scale bar

    // set the unit system (default is METRIC)

    // to enhance visibility of the scale bar, by making background transparent
    Color transparentWhite = new Color(1, 1, 1, 0.7);
    scaleBar.setBackground(new Background(new BackgroundFill(transparentWhite, new CornerRadii(5), Insets.EMPTY)));

    // add the map view and scale bar to stack pane
    stackPane.getChildren().addAll(mapView, scaleBar);

    // set position of scale bar
    StackPane.setAlignment(scaleBar, Pos.BOTTOM_CENTER);
    // give padding to scale bar
    StackPane.setMargin(scaleBar, new Insets(0, 0, 50, 0));

  // Stops and releases all resources used in application
  public void stop() {
    if (mapView != null) {

  // Opens and runs application
  public static void main(String[] args) {

In this topic
  1. Code