ArcGIS Runtime SDK for Java

Open Map (URL)

Demonstrates how to open an existing web map.

How it works

To open an existing web map:

  1. Create a Portal from the ArcGIS url
  2. Create a PortalItem using the Portal and the web map id, WebMapEntry.getId().
  3. Create a ArcGISMap using the portal item.
  4. Set map to the MapView.


 * 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.


import java.util.List;

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.ComboBox;
import javafx.scene.control.ListCell;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javafx.util.StringConverter;

import com.esri.arcgisruntime.mapping.ArcGISMap;
import com.esri.arcgisruntime.mapping.view.MapView;
import com.esri.arcgisruntime.portal.Portal;
import com.esri.arcgisruntime.portal.PortalItem;

public class OpenMapURLSample extends Application {

  private MapView mapView;

  private static final String[] portalItemIDs = new String[] {
      "01f052c8995e4b9e889d73c3e210ebe3", "0edea1c7bbb84ba5842d20483af11679"

  public void start(Stage stage) {

    // 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("Open Map URL Sample");

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

    // create a combo box to list maps
    ComboBox<ArcGISMap> webMapComboBox = new ComboBox<>();

    // create maps using portal item IDs
    Portal portal = new Portal("");
    List<ArcGISMap> webMaps = Stream.of(portalItemIDs)
        .map(id -> new PortalItem(portal, id))

    // load maps and add to combo box
    webMaps.forEach(map -> {
      map.getItem().addDoneLoadingListener(() -> webMapComboBox.getItems().add(map));

    // listener to switch the map when the selected map changes
    webMapComboBox.getSelectionModel().selectedItemProperty().addListener(e -> {
      ArcGISMap webMap = webMapComboBox.getSelectionModel().getSelectedItem();

    // show the name of the map in the combo box
    webMapComboBox.setConverter(new StringConverter<ArcGISMap>() {

      public String toString(ArcGISMap map) {
        return map != null ? map.getItem().getTitle() : "";

      public ArcGISMap fromString(String string) {
        return null; //not needed

    webMapComboBox.setCellFactory(comboBox -> new ListCell<ArcGISMap>() {

      protected void updateItem(ArcGISMap map, boolean empty) {
        super.updateItem(map, empty);
        setText(empty ? "" : map.getItem().getTitle());

    // select the web map loaded first
    webMaps.get(0).getItem().addDoneLoadingListener(() -> webMapComboBox.getSelectionModel().select(0));

    // add the map view and flow panel to stack pane
    stackPane.getChildren().addAll(mapView, webMapComboBox);
    StackPane.setAlignment(webMapComboBox, Pos.TOP_LEFT);
    StackPane.setMargin(webMapComboBox, new Insets(10, 0, 0, 10));

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

    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