Develop your first map app with Gradle

Use the steps below to create a basic mapping app using the Gradle build tool. The steps use the Eclipse IDE, but other IDEs have Gradle support too.

Make sure your development machine meets the System requirements for 100.1.

Create a Gradle project in Eclipse

  1. In Eclipse, click File > New > Project in the menu bar. In the New Project dialog, select the Gradle folder and click Gradle Project. Click Next.

    Eclipse new project wizard dialog with Gradle Project selected
  2. In the Project name field, enter app and click Finish.

    In the Package Explorer, your new project structure should appear as follows:

    Package explorer with default gradle project structure
  3. Remove the automatically generated files. Delete the Library.java file in src/main/java and the LibraryTest.java file in src/test/java.

Add SDK dependencies to your buildscript

  1. In the Package Explorer, double-click the build.gradle file. Replace the contents with the following:

    apply plugin: 'eclipse'
    apply plugin: 'application'
    //apply the ArcGIS Java SDK Plug-in for Gradle With_3D-Add_Graphics-Surface_Placement
    apply plugin: 'com.esri.arcgisruntime.java'
    
    buildscript {
      repositories { maven { url 'https://esri.bintray.com/arcgis' } }
      dependencies { classpath 'com.esri.arcgisruntime:gradle-arcgis-java-plugin:1.0.0' }
    }
    
    arcgis.version = '100.1.0'
    
    // download javadoc
    eclipse.classpath.downloadJavadoc = true

  2. Save the file. In the Package Explorer, right-click the app project and select Gradle > Refresh Gradle Project to apply the changes to the buildscript.

    The ArcGIS Java SDK Plug-in for Gradle will download the SDK's native libraries to the user's home directory.

    Note:

    It may take a minute to download the native libraries depending on your network speed, but this will only happen the first time you use the SDK.

Develop a JavaFX map app

  1. Under the project's src/main/java source directory, create the package structure com.mycompany.app. In the app package, create a new class called MyMapApp.

    Package explorer showing class MyMapApp in package com.mycompany.app
  2. Double-click the class file in the Package Explorer and replace the code with the following JavaFX application:

    package com.mycompany.app;
    
    import javafx.application.Application;
    import javafx.scene.Scene;
    import javafx.scene.layout.StackPane;
    import javafx.stage.Stage;
    
    public class MyMapApp extends Application {
    
      @Override
      public void start(Stage stage) throws Exception {
    
        // 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 Map Sample");
        stage.setWidth(800);
        stage.setHeight(700);
        stage.setScene(scene);
        stage.show();
      }
    
      /**
       * Opens and runs application.
       *
       * @param args arguments passed to this application
       */
      public static void main(String[] args) {
    
        Application.launch(args);
      }
    }

  3. Right-click the code in the editor and choose Run As > Java Application. The app will open to show a empty window with titled "Display Map Sample".
  4. Following imports are for adding a basemap to a map and displaying that map to the map view.

    import com.esri.arcgisruntime.mapping.ArcGISMap;
    import com.esri.arcgisruntime.mapping.Basemap;
    import com.esri.arcgisruntime.mapping.view.MapView;

  5. After the class definition, a private variable for map view is added so it can be dispose of when application is finished.

    public class MyMapApp extends Application {
    
      private MapView mapView;

  6. In the start function, after the stage.show() line the following tasks:
    1. Creates an ArcGISMap class, which defines the content of the map.
    2. Adds a basemap to the ArcGISMap class showing Imagery mapping.
    3. Creates a MapView JavaFX visual component that's linked to the Map class.
    4. Adds MapView to JavaFX application using the StackPane layout.

    // create a ArcGISMap with the a Basemap instance with an Imagery base layer
    ArcGISMap map = new ArcGISMap(Basemap.createImagery());
    
    // set the map to be displayed in this view
    mapView = new MapView();
    mapView.setMap(map);
    
    // add the map view to stack pane
    stackPane.getChildren().addAll(mapView);

  7. Overrides the stop method to dispose of application resources when the app closes.

    /**
     * Stops and releases all resources used in application.
     */
    @Override
    public void stop() throws Exception {
    
      if (mapView != null) {
        mapView.dispose();
      }
    }

  8. Example of what the map should look like. You can use the mouse to zoom and pan the map.