Skip to content

Commit f7c66cf

Browse files
committed
Merge branch 'dev' into 100.10.0
2 parents 26a54ae + aea5574 commit f7c66cf

File tree

281 files changed

+5085
-1296
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

281 files changed

+5085
-1296
lines changed

README.md

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,46 @@
11
# ArcGIS Runtime Java SDK Samples
22

3+
![Gradle build](https://github.com/Esri/arcgis-runtime-samples-java/workflows/Java%20CI%20with%20Gradle/badge.svg)
4+
35
This repo contains a set of sample projects demonstrating how to accomplish various mapping and GIS tasks with the ArcGIS Runtime SDK for Java.
46

57
Browse the category directories to explore the samples. Each sample is an individual [Gradle](https://docs.gradle.org/current/userguide/userguide.html) project that can be run standalone. The Gradle buildscripts have tasks for running the application, building a jar, and distributing the app as a zip.
68

79
Installing Gradle is not necessary since each sample includes the Gradle wrapper.
810

11+
Accessing Esri location services, including basemaps, routing, and geocoding, requires authentication using either an ArcGIS identity or an API Key:
12+
1. ArcGIS identity: An ArcGIS named user account that is a member of an organization in ArcGIS Online or ArcGIS Enterprise.
13+
2. API key: A permanent key that gives your application access to Esri location services. Visit your [ArcGIS Developers Dashboard](https://developers.arcgis.com/dashboard) to create a new API key or access an existing API key.
14+
15+
Note: *in the following instructions for setting the API key, if a `gradle.properties` file does not already exist in the `/.gradle` folder within your home directory, a Gradle task in the samples build.gradle file will generate one for you.*
16+
917
## Instructions
1018

1119
### IntelliJ IDEA
1220

1321
1. Open IntelliJ IDEA and select _File > Open..._.
1422
2. Choose one of the sample project directories (not the category folder) and click _OK_.
1523
3. Select _File > Project Structure..._ and ensure that the Project SDK and language level are set to use Java 11.
16-
4. Open the Gradle view with _View > Tool Windows > Gradle_.
17-
5. In the Gradle view, double-click the `run` task under _Tasks > application_ to run the app.
24+
4. Set your API key in the `gradle.properties` file located in the `/.gradle` folder within your home directory.
25+
5. Open the Gradle view with _View > Tool Windows > Gradle_.
26+
6. In the Gradle view, double-click the `run` task under _Tasks > application_ to run the app.
1827

1928
### Eclipse
2029

2130
1. Open Eclipse and select _File > Import_.
2231
2. In the import wizard, choose _Gradle > Existing Gradle Project_, then click _Next_.
2332
3. Choose one of the sample project directories (not the category folder) as the project root directory.
2433
4. Click _Finish_ to complete the import.
25-
5. Open the Gradle Tasks view with _Window > Show View > Other... > Gradle > Gradle Tasks_.
26-
6. In the Gradle Tasks view, double-click the `run` task under _{project_name} > application_ to run the app.
34+
5. Set your API key in the `gradle.properties` file located in the `/.gradle` folder within your home directory.
35+
6. Open the Gradle Tasks view with _Window > Show View > Other... > Gradle > Gradle Tasks_.
36+
7. In the Gradle Tasks view, double-click the `run` task under _{project_name} > application_ to run the app.
2737

2838
### Terminal
2939

3040
1. `cd` into one of the sample project directories (not the category folder).
31-
2. Run `./gradlew run` on Linux/Mac or `gradlew.bat run` on Windows to run the app.
41+
2. Run `gradle wrapper` to create the Gradle Wrapper
42+
3. Set your API key in the `gradle.properties` file located in the `/.gradle` folder within your home directory.
43+
4. Run `./gradlew run` on Linux/Mac or `gradlew.bat run` on Windows to run the app.
3244

3345
### Java 11
3446
Java 11 users may find exceptions when running the project if their library path is still set for Oracle JDK 1.8 (see the [OpenJavaFX docs](https://openjfx.io/openjfx-docs/) for more information). A workaround for this is to add the following argument in the `run` task of the Gradle buildscript:

analysis/analyze-hotspots/build.gradle

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66
group = 'com.esri.samples'
77

88
ext {
9-
arcgisVersion = '100.9.0'
9+
arcgisVersion = '100.10.0-2992'
1010
}
1111

1212
javafx {
@@ -36,6 +36,17 @@ dependencies {
3636
natives "com.esri.arcgisruntime:arcgis-java-resources:$arcgisVersion"
3737
}
3838

39+
task createGradlePropertiesAndWriteApiKey {
40+
description = "Creates a new gradle.properties file with an empty API key variable in the user home ./gradle folder, if the file doesn't already exist."
41+
group = "build"
42+
def propertiesFile = new File("${System.properties.getProperty("user.home")}/.gradle/gradle.properties")
43+
if (!propertiesFile.exists()) {
44+
print("Go to " + new URL("https://developers.arcgis.com/dashboard") + " to get an API key.")
45+
print(" Add your API key to ${System.properties.getProperty("user.home")}\\.gradle\\gradle.properties.")
46+
propertiesFile.write("apiKey = ")
47+
}
48+
}
49+
3950
task copyNatives(type: Copy) {
4051
description = "Copies the arcgis native libraries into the project build directory for development."
4152
group = "build"
@@ -47,6 +58,10 @@ task copyNatives(type: Copy) {
4758
}
4859

4960
run {
61+
doFirst {
62+
// sets the API key from the gradle.properties file as a Java system property
63+
systemProperty 'apiKey', apiKey
64+
}
5065
dependsOn copyNatives
5166
mainClassName = 'com.esri.samples.analyze_hotspots.AnalyzeHotspotsLauncher'
5267
}

analysis/analyze-hotspots/src/main/java/com/esri/samples/analyze_hotspots/AnalyzeHotspotsSample.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,15 @@
3737
import javafx.scene.paint.Paint;
3838
import javafx.stage.Stage;
3939

40+
import com.esri.arcgisruntime.ArcGISRuntimeEnvironment;
4041
import com.esri.arcgisruntime.concurrent.Job;
4142
import com.esri.arcgisruntime.concurrent.ListenableFuture;
4243
import com.esri.arcgisruntime.geometry.Point;
43-
import com.esri.arcgisruntime.geometry.SpatialReference;
44+
import com.esri.arcgisruntime.geometry.SpatialReferences;
4445
import com.esri.arcgisruntime.layers.ArcGISMapImageLayer;
4546
import com.esri.arcgisruntime.loadable.LoadStatus;
4647
import com.esri.arcgisruntime.mapping.ArcGISMap;
47-
import com.esri.arcgisruntime.mapping.Basemap;
48+
import com.esri.arcgisruntime.mapping.BasemapStyle;
4849
import com.esri.arcgisruntime.mapping.Viewpoint;
4950
import com.esri.arcgisruntime.mapping.view.MapView;
5051
import com.esri.arcgisruntime.tasks.geoprocessing.GeoprocessingJob;
@@ -74,12 +75,20 @@ public void start(Stage stage) {
7475
stage.setScene(scene);
7576
stage.show();
7677

77-
// create a view with a map and topographic basemap
78-
ArcGISMap map = new ArcGISMap(Basemap.createTopographic());
79-
map.setInitialViewpoint(new Viewpoint(new Point(-13671170, 5693633, SpatialReference.create(3857)), 57779));
78+
// authentication with an API key or named user is required to access basemaps and other location services
79+
String yourAPIKey = System.getProperty("apiKey");
80+
ArcGISRuntimeEnvironment.setApiKey(yourAPIKey);
81+
82+
// create a map with the topographic basemap style
83+
ArcGISMap map = new ArcGISMap(BasemapStyle.ARCGIS_TOPOGRAPHIC);
84+
85+
// create a map view and set the map to it
8086
mapView = new MapView();
8187
mapView.setMap(map);
8288

89+
// set a viewpoint on the map view
90+
mapView.setViewpoint(new Viewpoint(new Point(-13671170, 5693633, SpatialReferences.getWebMercator()), 57779));
91+
8392
// show progress indicator when geoprocessing task is loading or geoprocessing job is running
8493
ProgressIndicator progress = new ProgressIndicator(ProgressIndicator.INDETERMINATE_PROGRESS);
8594
progress.setMaxWidth(30);
@@ -104,7 +113,7 @@ public void start(Stage stage) {
104113
controlsVBox.setMaxSize(180, 110);
105114
controlsVBox.getChildren().addAll(begDatePicker, endDatePicker, analyzeButton);
106115

107-
// and the mapView, controls, and progress indicator to the stack pane
116+
// add the map view, controls, and progress indicator to the stack pane
108117
stackPane.getChildren().addAll(mapView, controlsVBox, progress);
109118
StackPane.setAlignment(progress, Pos.CENTER);
110119
StackPane.setAlignment(controlsVBox, Pos.TOP_LEFT);

analysis/viewshed-geoprocessing/build.gradle

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66
group = 'com.esri.samples'
77

88
ext {
9-
arcgisVersion = '100.9.0'
9+
arcgisVersion = '100.10.0-2992'
1010
}
1111

1212
javafx {
@@ -36,6 +36,17 @@ dependencies {
3636
natives "com.esri.arcgisruntime:arcgis-java-resources:$arcgisVersion"
3737
}
3838

39+
task createGradlePropertiesAndWriteApiKey {
40+
description = "Creates a new gradle.properties file with an empty API key variable in the user home ./gradle folder, if the file doesn't already exist."
41+
group = "build"
42+
def propertiesFile = new File("${System.properties.getProperty("user.home")}/.gradle/gradle.properties")
43+
if (!propertiesFile.exists()) {
44+
print("Go to " + new URL("https://developers.arcgis.com/dashboard") + " to get an API key.")
45+
print(" Add your API key to ${System.properties.getProperty("user.home")}\\.gradle\\gradle.properties.")
46+
propertiesFile.write("apiKey = ")
47+
}
48+
}
49+
3950
task copyNatives(type: Copy) {
4051
description = "Copies the arcgis native libraries into the project build directory for development."
4152
group = "build"
@@ -47,6 +58,10 @@ task copyNatives(type: Copy) {
4758
}
4859

4960
run {
61+
doFirst {
62+
// sets the API key from the gradle.properties file as a Java system property
63+
systemProperty 'apiKey', apiKey
64+
}
5065
dependsOn copyNatives
5166
mainClassName = 'com.esri.samples.viewshed_geoprocessing.ViewshedGeoprocessingLauncher'
5267
}

analysis/viewshed-geoprocessing/src/main/java/com/esri/samples/viewshed_geoprocessing/ViewshedGeoprocessingSample.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import javafx.scene.paint.Color;
3434
import javafx.stage.Stage;
3535

36+
import com.esri.arcgisruntime.ArcGISRuntimeEnvironment;
3637
import com.esri.arcgisruntime.concurrent.Job;
3738
import com.esri.arcgisruntime.concurrent.ListenableFuture;
3839
import com.esri.arcgisruntime.data.Feature;
@@ -43,7 +44,8 @@
4344
import com.esri.arcgisruntime.geometry.Point;
4445
import com.esri.arcgisruntime.loadable.LoadStatus;
4546
import com.esri.arcgisruntime.mapping.ArcGISMap;
46-
import com.esri.arcgisruntime.mapping.Basemap;
47+
import com.esri.arcgisruntime.mapping.BasemapStyle;
48+
import com.esri.arcgisruntime.mapping.Viewpoint;
4749
import com.esri.arcgisruntime.mapping.view.Graphic;
4850
import com.esri.arcgisruntime.mapping.view.GraphicsOverlay;
4951
import com.esri.arcgisruntime.mapping.view.MapView;
@@ -81,11 +83,20 @@ public void start(Stage stage) {
8183
stage.setScene(scene);
8284
stage.show();
8385

84-
// create a view with a map and topographic basemap
85-
ArcGISMap map = new ArcGISMap(Basemap.Type.TOPOGRAPHIC, 45.3790902612337, 6.84905317262762, 12);
86+
// authentication with an API key or named user is required to access basemaps and other location services
87+
String yourAPIKey = System.getProperty("apiKey");
88+
ArcGISRuntimeEnvironment.setApiKey(yourAPIKey);
89+
90+
// create a map with the topographic basemap style
91+
ArcGISMap map = new ArcGISMap(BasemapStyle.ARCGIS_TOPOGRAPHIC);
92+
93+
// create a map view and set the map to it
8694
mapView = new MapView();
8795
mapView.setMap(map);
8896

97+
// set a viewpoint on the map view
98+
mapView.setViewpoint(new Viewpoint(45.3790902612337, 6.84905317262762, 144447));
99+
89100
// create an input graphics overlay to show red point markers where the user clicks
90101
SimpleMarkerSymbol pointSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.CIRCLE, 0xFFFF0000, 10);
91102
SimpleRenderer renderer = new SimpleRenderer(pointSymbol);

display_information/add-graphics-with-renderer/build.gradle

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66
group = 'com.esri.samples'
77

88
ext {
9-
arcgisVersion = '100.9.0'
9+
arcgisVersion = '100.10.0-2992'
1010
}
1111

1212
javafx {
@@ -36,6 +36,17 @@ dependencies {
3636
natives "com.esri.arcgisruntime:arcgis-java-resources:$arcgisVersion"
3737
}
3838

39+
task createGradlePropertiesAndWriteApiKey {
40+
description = "Creates a new gradle.properties file with an empty API key variable in the user home ./gradle folder, if the file doesn't already exist."
41+
group = "build"
42+
def propertiesFile = new File("${System.properties.getProperty("user.home")}/.gradle/gradle.properties")
43+
if (!propertiesFile.exists()) {
44+
print("Go to " + new URL("https://developers.arcgis.com/dashboard") + " to get an API key.")
45+
print(" Add your API key to ${System.properties.getProperty("user.home")}\\.gradle\\gradle.properties.")
46+
propertiesFile.write("apiKey = ")
47+
}
48+
}
49+
3950
task copyNatives(type: Copy) {
4051
description = "Copies the arcgis native libraries into the project build directory for development."
4152
group = "build"
@@ -47,6 +58,10 @@ task copyNatives(type: Copy) {
4758
}
4859

4960
run {
61+
doFirst {
62+
// sets the API key from the gradle.properties file as a Java system property
63+
systemProperty 'apiKey', apiKey
64+
}
5065
dependsOn copyNatives
5166
mainClassName = 'com.esri.samples.add_graphics_with_renderer.AddGraphicsWithRendererLauncher'
5267
}

display_information/add-graphics-with-renderer/src/main/java/com/esri/samples/add_graphics_with_renderer/AddGraphicsWithRendererSample.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@
2121
import javafx.scene.layout.StackPane;
2222
import javafx.stage.Stage;
2323

24+
import com.esri.arcgisruntime.ArcGISRuntimeEnvironment;
2425
import com.esri.arcgisruntime.geometry.Point;
2526
import com.esri.arcgisruntime.geometry.PolygonBuilder;
2627
import com.esri.arcgisruntime.geometry.PolylineBuilder;
2728
import com.esri.arcgisruntime.geometry.SpatialReferences;
2829
import com.esri.arcgisruntime.mapping.ArcGISMap;
29-
import com.esri.arcgisruntime.mapping.Basemap;
30+
import com.esri.arcgisruntime.mapping.BasemapStyle;
31+
import com.esri.arcgisruntime.mapping.Viewpoint;
3032
import com.esri.arcgisruntime.mapping.view.Graphic;
3133
import com.esri.arcgisruntime.mapping.view.GraphicsOverlay;
3234
import com.esri.arcgisruntime.mapping.view.MapView;
@@ -54,13 +56,20 @@ public void start(Stage stage) {
5456
stage.setScene(scene);
5557
stage.show();
5658

57-
// create a map with topographic basemap
58-
ArcGISMap map = new ArcGISMap(Basemap.Type.TOPOGRAPHIC, 15.169193, 16.333479, 2);
59+
// authentication with an API key or named user is required to access basemaps and other location services
60+
String yourAPIKey = System.getProperty("apiKey");
61+
ArcGISRuntimeEnvironment.setApiKey(yourAPIKey);
5962

60-
// set the map to the view
63+
// create a map with the topographic basemap style
64+
ArcGISMap map = new ArcGISMap(BasemapStyle.ARCGIS_TOPOGRAPHIC);
65+
66+
// create a map view and set the map to it
6167
mapView = new MapView();
6268
mapView.setMap(map);
6369

70+
// set a viewpoint on the map view
71+
mapView.setViewpoint(new Viewpoint(15.169193, 16.333479, 1479143818));
72+
6473
// create a graphics overlay for displaying point graphic
6574
GraphicsOverlay pointGraphicOverlay = new GraphicsOverlay();
6675
// create point geometry

display_information/add-graphics-with-symbols/build.gradle

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66
group = 'com.esri.samples'
77

88
ext {
9-
arcgisVersion = '100.9.0'
9+
arcgisVersion = '100.10.0-2992'
1010
}
1111

1212
javafx {
@@ -36,6 +36,17 @@ dependencies {
3636
natives "com.esri.arcgisruntime:arcgis-java-resources:$arcgisVersion"
3737
}
3838

39+
task createGradlePropertiesAndWriteApiKey {
40+
description = "Creates a new gradle.properties file with an empty API key variable in the user home ./gradle folder, if the file doesn't already exist."
41+
group = "build"
42+
def propertiesFile = new File("${System.properties.getProperty("user.home")}/.gradle/gradle.properties")
43+
if (!propertiesFile.exists()) {
44+
print("Go to " + new URL("https://developers.arcgis.com/dashboard") + " to get an API key.")
45+
print(" Add your API key to ${System.properties.getProperty("user.home")}\\.gradle\\gradle.properties.")
46+
propertiesFile.write("apiKey = ")
47+
}
48+
}
49+
3950
task copyNatives(type: Copy) {
4051
description = "Copies the arcgis native libraries into the project build directory for development."
4152
group = "build"
@@ -47,6 +58,10 @@ task copyNatives(type: Copy) {
4758
}
4859

4960
run {
61+
doFirst {
62+
// sets the API key from the gradle.properties file as a Java system property
63+
systemProperty 'apiKey', apiKey
64+
}
5065
dependsOn copyNatives
5166
mainClassName = 'com.esri.samples.add_graphics_with_symbols.AddGraphicsWithSymbolsLauncher'
5267
}

display_information/add-graphics-with-symbols/src/main/java/com/esri/samples/add_graphics_with_symbols/AddGraphicsWithSymbolsSample.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,16 @@
2121
import javafx.scene.layout.StackPane;
2222
import javafx.stage.Stage;
2323

24+
import com.esri.arcgisruntime.ArcGISRuntimeEnvironment;
2425
import com.esri.arcgisruntime.geometry.Point;
2526
import com.esri.arcgisruntime.geometry.PointCollection;
2627
import com.esri.arcgisruntime.geometry.Polygon;
2728
import com.esri.arcgisruntime.geometry.Polyline;
2829
import com.esri.arcgisruntime.geometry.SpatialReference;
2930
import com.esri.arcgisruntime.geometry.SpatialReferences;
3031
import com.esri.arcgisruntime.mapping.ArcGISMap;
31-
import com.esri.arcgisruntime.mapping.Basemap;
32+
import com.esri.arcgisruntime.mapping.BasemapStyle;
33+
import com.esri.arcgisruntime.mapping.Viewpoint;
3234
import com.esri.arcgisruntime.mapping.view.Graphic;
3335
import com.esri.arcgisruntime.mapping.view.GraphicsOverlay;
3436
import com.esri.arcgisruntime.mapping.view.MapView;
@@ -63,16 +65,23 @@ public void start(Stage stage) {
6365
stage.setScene(scene);
6466
stage.show();
6567

66-
// create the graphics overlay
67-
graphicsOverlay = new GraphicsOverlay();
68+
// authentication with an API key or named user is required to access basemaps and other location services
69+
String yourAPIKey = System.getProperty("apiKey");
70+
ArcGISRuntimeEnvironment.setApiKey(yourAPIKey);
6871

69-
// create a ArcGISMap with a topographic basemap
70-
final ArcGISMap map = new ArcGISMap(Basemap.Type.OCEANS, 56.075844, -2.681572, 13);
72+
// create a map with the oceans basemap style
73+
final ArcGISMap map = new ArcGISMap(BasemapStyle.ARCGIS_OCEANS);
7174

72-
// create a view for the ArcGISMap and set the ArcGISMap to it
75+
// create a map view and set the map to it
7376
mapView = new MapView();
7477
mapView.setMap(map);
7578

79+
// set a viewpoint on the map view
80+
mapView.setViewpoint(new Viewpoint(56.075844, -2.681572, 72223));
81+
82+
// create the graphics overlay
83+
graphicsOverlay = new GraphicsOverlay();
84+
7685
// add the graphic overlay to the map view
7786
mapView.getGraphicsOverlays().add(graphicsOverlay);
7887

0 commit comments

Comments
 (0)