Skip to content

Commit e0a94c0

Browse files
authored
New Basemaps: Map Category - part 1 of 2 (#604)
* Update build.gradle * display map * Access load status * Change basemap * Create and save map * Update readme metadata files * Change basemap - set viewpoint on mapview * Access load status - amend comment * Change Basemap - variable naming * Create and save map - code review tidy ups * update build.gradle - versions * tidy comment and scale consistencies
1 parent 112223d commit e0a94c0

File tree

13 files changed

+88
-66
lines changed

13 files changed

+88
-66
lines changed

map/access-load-status/build.gradle

Lines changed: 1 addition & 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 {

map/access-load-status/src/main/java/com/esri/samples/access_load_status/AccessLoadStatusSample.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@
3232
import javafx.scene.paint.Paint;
3333
import javafx.stage.Stage;
3434

35+
import com.esri.arcgisruntime.ArcGISRuntimeEnvironment;
3536
import com.esri.arcgisruntime.mapping.ArcGISMap;
36-
import com.esri.arcgisruntime.mapping.Basemap;
37+
import com.esri.arcgisruntime.mapping.BasemapStyle;
3738
import com.esri.arcgisruntime.mapping.view.MapView;
3839

3940
public class AccessLoadStatusSample extends Application {
@@ -57,6 +58,10 @@ public void start(Stage stage) {
5758
stage.setScene(scene);
5859
stage.show();
5960

61+
// authentication with an API key or named user is required to access basemaps and other location services
62+
String yourAPIKey = System.getProperty("apiKey");
63+
ArcGISRuntimeEnvironment.setApiKey(yourAPIKey);
64+
6065
// create a control panel
6166
VBox controlsVBox = new VBox(6);
6267
controlsVBox.setBackground(new Background(new BackgroundFill(Paint.valueOf("rgba(0,0,0,0.3)"), CornerRadii.EMPTY,
@@ -74,12 +79,12 @@ public void start(Stage stage) {
7479
Button reloadMapButton = new Button("Reload ArcGISMap");
7580
reloadMapButton.setMaxWidth(Double.MAX_VALUE);
7681

77-
// reload ArcGISMap when button clicked
82+
// reload the map when the button is clicked
7883
reloadMapButton.setOnAction(event -> {
7984
loadStatusText.clear();
8085

81-
// reload the same ArcGISMap
82-
map = new ArcGISMap(Basemap.createImagery());
86+
// reload the map
87+
map = new ArcGISMap(BasemapStyle.ARCGIS_IMAGERY_STANDARD);
8388

8489
map.addLoadStatusChangedListener(e -> {
8590
String loadingStatus;
@@ -112,10 +117,10 @@ public void start(Stage stage) {
112117
// add label, text and button to the control panel
113118
controlsVBox.getChildren().addAll(loadStatusLabel, loadStatusText, reloadMapButton);
114119

115-
// create ArcGISMap with the imagery basemap
116-
map = new ArcGISMap(Basemap.createImagery());
120+
// create a map with the standard imagery basemap style
121+
map = new ArcGISMap(BasemapStyle.ARCGIS_IMAGERY_STANDARD);
117122

118-
// create a view for this ArcGISMap and set ArcGISMap to it
123+
// create a map view and set the map to it
119124
mapView = new MapView();
120125
mapView.setMap(map);
121126

map/change-basemap/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@ Change a map's basemap. A basemap is beneath all layers on an `ArcGISMap` and is
66

77
## Use case
88

9-
Basemaps should selected contextually, for example, in maritime applications, it would be more appropriate to use a basemap of the world's oceans as opposed to a basemap of the world's streets.
9+
Basemaps should be selected contextually, for example, in maritime applications, it would be more appropriate to use a basemap of the world's oceans as opposed to a basemap of the world's streets.
1010

1111
## How to use the sample
1212

13-
Select a basemap from the list of available basemaps to set it to the map.
13+
Select a basemap style from the list to set it to the map.
1414

1515
## How it works
1616

1717
1. Create an `ArcGISMap` object.
1818
2. Set the map to the `MapView` object.
19-
3. Choose a new basemap type with `Basemap.Type` and set it on the map.
19+
3. Choose a new basemap style with `BasemapStyle` and set it on the map.
2020

2121
## Relevant API
2222
* ArcGISMap
23-
* Basemap
23+
* BasemapStyle
2424
* MapView
2525

2626
## Tags

map/change-basemap/README.metadata.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
"basemap",
1010
"map",
1111
"ArcGISMap",
12-
"Basemap",
12+
"BasemapStyle",
1313
"MapView"
1414
],
1515
"redirect_from": [
1616
"/java/latest/sample-code/change-basemap.htm"
1717
],
1818
"relevant_apis": [
1919
"ArcGISMap",
20-
"Basemap",
20+
"BasemapStyle",
2121
"MapView"
2222
],
2323
"snippets": [

map/change-basemap/build.gradle

Lines changed: 1 addition & 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 {

map/change-basemap/src/main/java/com/esri/samples/change_basemap/ChangeBasemapSample.java

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,17 @@
2525
import javafx.scene.layout.StackPane;
2626
import javafx.stage.Stage;
2727

28+
import com.esri.arcgisruntime.ArcGISRuntimeEnvironment;
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.MapView;
3133

3234
public class ChangeBasemapSample extends Application {
3335

3436
private MapView mapView;
3537
private ArcGISMap map;
3638

37-
private static final double LATITUDE = 57.5000;
38-
private static final double LONGITUDE = -5.0000;
39-
private static final int LOD = 6;
40-
4139
@Override
4240
public void start(Stage stage) {
4341

@@ -53,27 +51,32 @@ public void start(Stage stage) {
5351
stage.setScene(scene);
5452
stage.show();
5553

54+
// authentication with an API key or named user is required to access basemaps and other location services
55+
String yourAPIKey = System.getProperty("apiKey");
56+
ArcGISRuntimeEnvironment.setApiKey(yourAPIKey);
57+
5658
// creates a map view
5759
mapView = new MapView();
5860

59-
// setup listview of basemaps
60-
ListView<Basemap.Type> basemapList = new ListView<>(FXCollections.observableArrayList(Basemap.Type.values()));
61-
basemapList.setMaxSize(250, 150);
61+
// setup a list view of basemap styles
62+
ListView<BasemapStyle> basemapStyleListView = new ListView<>(FXCollections.observableArrayList(BasemapStyle.values()));
63+
basemapStyleListView.setMaxSize(250, 150);
6264

63-
// change the basemap when list option is selected
64-
basemapList.getSelectionModel().selectedItemProperty().addListener(o -> {
65-
String basemapString = basemapList.getSelectionModel().getSelectedItem().toString();
66-
map = new ArcGISMap(Basemap.Type.valueOf(basemapString), LATITUDE, LONGITUDE, LOD);
65+
// change the basemap when a list option is selected
66+
basemapStyleListView.getSelectionModel().selectedItemProperty().addListener(o -> {
67+
BasemapStyle selectedBasemapStyle = basemapStyleListView.getSelectionModel().getSelectedItem();
68+
map = new ArcGISMap(selectedBasemapStyle);
6769
mapView.setMap(map);
70+
mapView.setViewpoint(new Viewpoint(57.5000, -5.0000, 9244648));
6871
});
6972

70-
// select the first basemap
71-
basemapList.getSelectionModel().selectFirst();
73+
// select the first basemap style
74+
basemapStyleListView.getSelectionModel().selectFirst();
7275

7376
// add the map view and control panel to stack pane
74-
stackPane.getChildren().addAll(mapView, basemapList);
75-
StackPane.setAlignment(basemapList, Pos.TOP_LEFT);
76-
StackPane.setMargin(basemapList, new Insets(10, 0, 0, 10));
77+
stackPane.getChildren().addAll(mapView, basemapStyleListView);
78+
StackPane.setAlignment(basemapStyleListView, Pos.TOP_LEFT);
79+
StackPane.setMargin(basemapStyleListView, new Insets(10, 0, 0, 10));
7780

7881
} catch (Exception e) {
7982
// on any error, display the stack trace.

map/create-and-save-map/build.gradle

Lines changed: 1 addition & 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 {

map/create-and-save-map/src/main/java/com/esri/samples/create_and_save_map/CreateAndSaveMapController.java

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@
3232
import javafx.scene.control.TextField;
3333
import javafx.util.StringConverter;
3434

35+
import com.esri.arcgisruntime.ArcGISRuntimeEnvironment;
3536
import com.esri.arcgisruntime.concurrent.ListenableFuture;
3637
import com.esri.arcgisruntime.layers.ArcGISMapImageLayer;
3738
import com.esri.arcgisruntime.layers.Layer;
3839
import com.esri.arcgisruntime.loadable.LoadStatus;
3940
import com.esri.arcgisruntime.mapping.ArcGISMap;
4041
import com.esri.arcgisruntime.mapping.Basemap;
42+
import com.esri.arcgisruntime.mapping.BasemapStyle;
4143
import com.esri.arcgisruntime.mapping.view.MapView;
4244
import com.esri.arcgisruntime.portal.Portal;
4345
import com.esri.arcgisruntime.portal.PortalFolder;
@@ -60,7 +62,7 @@ public class CreateAndSaveMapController {
6062
@FXML
6163
private ComboBox<PortalFolder> folderList;
6264
@FXML
63-
private ListView<Basemap> basemapList;
65+
private ListView<BasemapStyle> basemapStyleListView;
6466
@FXML
6567
private ListView<Layer> layersList;
6668
@FXML
@@ -74,29 +76,36 @@ public class CreateAndSaveMapController {
7476
@FXML
7577
private void initialize() {
7678

77-
// set basemap options
78-
basemapList.getItems().addAll(Basemap.createStreets(), Basemap.createImagery(), Basemap
79-
.createTopographic(), Basemap.createOceans());
79+
// authentication with an API key or named user is required to access basemaps and other location services
80+
String yourAPIKey = System.getProperty("apiKey");
81+
ArcGISRuntimeEnvironment.setApiKey(yourAPIKey);
8082

81-
// update basemap when selection changes
82-
basemapList.getSelectionModel().select(0);
83-
basemapList.getSelectionModel().selectedItemProperty()
84-
.addListener(o -> map.setBasemap(basemapList.getSelectionModel().getSelectedItem()));
83+
// set the basemap style options
84+
basemapStyleListView.getItems().addAll(
85+
BasemapStyle.ARCGIS_STREETS,
86+
BasemapStyle.ARCGIS_IMAGERY_STANDARD,
87+
BasemapStyle.ARCGIS_TOPOGRAPHIC,
88+
BasemapStyle.ARCGIS_OCEANS);
8589

86-
basemapList.setCellFactory(c -> new BasemapCell());
90+
basemapStyleListView.setCellFactory(c -> new BasemapCell());
8791

88-
// create and set a map with the first basemap option
89-
map = new ArcGISMap(basemapList.getSelectionModel().getSelectedItem());
92+
// update the basemap when the selection changes
93+
basemapStyleListView.getSelectionModel().select(0);
94+
basemapStyleListView.getSelectionModel().selectedItemProperty()
95+
.addListener(o -> map.setBasemap(new Basemap(basemapStyleListView.getSelectionModel().getSelectedItem())));
96+
97+
// create a basemap with the first basemap style option and set it to the map
98+
Basemap basemap = new Basemap(basemapStyleListView.getSelectionModel().getSelectedItem());
99+
map = new ArcGISMap(basemap);
90100
mapView.setMap(map);
91101

92102
// set operational layer options
93-
String worldElevationService =
94-
"https://sampleserver6.arcgisonline.com/arcgis/rest/services/WorldTimeZones/MapServer";
95-
ArcGISMapImageLayer worldElevation = new ArcGISMapImageLayer(worldElevationService);
103+
ArcGISMapImageLayer worldElevation = new ArcGISMapImageLayer(
104+
"https://sampleserver6.arcgisonline.com/arcgis/rest/services/WorldTimeZones/MapServer");
96105
worldElevation.loadAsync();
97106

98-
String worldCensusService = "https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer";
99-
ArcGISMapImageLayer worldCensus = new ArcGISMapImageLayer(worldCensusService);
107+
ArcGISMapImageLayer worldCensus = new ArcGISMapImageLayer(
108+
"https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer");
100109
worldCensus.loadAsync();
101110

102111
layersList.getItems().addAll(worldElevation, worldCensus);
@@ -171,14 +180,14 @@ void authenticate() {
171180
}
172181

173182
/**
174-
* Shows a Basemap title in a ListView.
183+
* Shows a BasemapStyle title in a ListView.
175184
*/
176-
private class BasemapCell extends ListCell<Basemap> {
185+
private class BasemapCell extends ListCell<BasemapStyle> {
177186

178187
@Override
179-
protected void updateItem(Basemap basemap, boolean empty) {
180-
super.updateItem(basemap, empty);
181-
setText(empty || basemap == null ? null : basemap.getName());
188+
protected void updateItem(BasemapStyle basemapStyle, boolean empty) {
189+
super.updateItem(basemapStyle, empty);
190+
setText(empty || basemapStyle == null ? null : basemapStyle.name());
182191
setGraphic(null);
183192
}
184193
}
@@ -204,7 +213,7 @@ private void saveMap() {
204213
progress.setVisible(true);
205214
try {
206215
ListenableFuture<PortalItem> result = map.saveAsAsync(portal, folderList.getSelectionModel().getSelectedItem(),
207-
title.getText(), Arrays.asList(tags.getText().split(",")), description.getText(), null, true);
216+
title.getText(), Arrays.asList(tags.getText().split(",")), description.getText(), null, true);
208217
result.addDoneListener(() -> {
209218
try {
210219
PortalItem portalItem = result.get();

map/create-and-save-map/src/main/resources/create_and_save_map/main.fxml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
</VBox>
6767
<VBox>
6868
<Label text="Basemap"/>
69-
<ListView fx:id="basemapList"/>
69+
<ListView fx:id="basemapStyleListView"/>
7070
</VBox>
7171
<VBox>
7272
<Label text="Operational layers"/>

map/display-map/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ Run the sample to view the map. Pan and zoom to navigate the map.
1414

1515
## How it works
1616

17-
1. Create an ArcGIS map using a default `Basemap` such use `Basemap.createImagery()`.
17+
1. Create an ArcGIS map using a default `BasemapStyle` such as `BasemapStyle.ARCGIS_IMAGERY_STANDARD`.
1818
2. Create a `MapView` object to display the map.
1919
3. Set the map to the map view.
2020

2121
## Relevant API
2222

2323
* ArcGISMap
24-
* Basemap
24+
* BasemapStyle
2525
* MapView
2626

2727
## Tags

0 commit comments

Comments
 (0)