Create and save map

View on GitHub
Sample viewer app

Create and save a map as an ArcGIS PortalItem (i.e. web map).

Image of create and save map

Use case

Maps can be created programmatically in code and then serialized and saved as an ArcGIS web map. A web map can be shared with others and opened in various applications and APIs throughout the platform, such as ArcGIS Pro, ArcGIS Online, the JavaScript API, Collector, and Explorer.

How to use the sample

This sample requires you to setup your own app on arcgis.com. See https://github.com/Esri/arcgis-runtime-samples-java/blob/master/OAuth.md for instructions.

Fill in your portal and registered app credentials in the starting dialog to authenticate. Then, choose the basemap and layers for your new map. To save the map, choose a title, tags and description (optional), and a folder on your portal (you will need to create one in your portal's My Content). Click the Save button to save the map to the chosen folder.

How it works

  1. An ArcGISMap is created with a Basemap and a few operational layers.
  2. A Portal object is created and loaded. This will issue an authentication challenge, prompting the user to provide credentials.
  3. Once the user is authenticated, Map.saveMapAsAsync() is called and a new ArcGISMap is saved with the specified title, tags, and folder.

Relevant API

  • ArcGISMap
  • Portal

Tags

ArcGIS Online, ArcGIS Pro, portal, publish, share, web map

Sample Code

AuthenticationDialog.javaCreateAndSaveMapController.javaCreateAndSaveMapSample.javaauth_dialog.fxmlmain.fxml
                                                                           
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
/*
 * 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.create_and_save_map;

import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.control.Alert;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Dialog;
import javafx.scene.control.TextField;

import com.esri.arcgisruntime.security.OAuthConfiguration;

/**
 * Custom dialog for getting an OAuthConfiguration.
 */
class AuthenticationDialog extends Dialog<OAuthConfiguration> {

  @FXML private TextField portalURL;
  @FXML private TextField clientID;
  @FXML private TextField redirectURI;
  @FXML private ButtonType cancelButton;
  @FXML private ButtonType continueButton;

  AuthenticationDialog() {
    FXMLLoader loader = new FXMLLoader(getClass().getResource("/create_and_save_map/auth_dialog.fxml"));
    loader.setRoot(this);
    loader.setController(this);

    setTitle("Authenticate");

    try {
      loader.load();
    } catch (Exception e) {
      e.printStackTrace();
    }

    setResultConverter(dialogButton -> {
      if (dialogButton == continueButton) {
        if (!portalURL.getText().equals("") && !clientID.getText().equals("") && !redirectURI.getText().equals("")) {
          try {
            return new OAuthConfiguration(portalURL.getText(), clientID.getText(), redirectURI.getText());
          } catch (Exception e) {
            showMessage(e.getMessage());
          }
        } else {
          showMessage("missing credentials");
        }
      }
      return null;
    });
  }

  private void showMessage(String message) {
    Alert alert = new Alert(Alert.AlertType.ERROR);
    alert.initOwner(this.getOwner());
    alert.setContentText(message);
    alert.show();
  }

}

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