wait for done listener before getting travel modes
@@ -90,6 +90,8 @@ public class OfflineRoutingSample extends Application {
ArcGISMap map = new ArcGISMap(basemap);
mapView = new MapView();
mapView.setMap(map);
+ // display map view to application
+ stackPane.getChildren().add(mapView);
// create graphics overlays for route and stops
stopsOverlay = new GraphicsOverlay();
@@ -110,11 +112,41 @@ public class OfflineRoutingSample extends Application {
boundaryOverlay.getGraphics().add(boundary);
mapView.getGraphicsOverlays().add(boundaryOverlay);
- // create route parameters
routeTask.addDoneLoadingListener(() -> {
if (routeTask.getLoadStatus() == LoadStatus.LOADED) {
try {
+ // create route parameters
routeParameters = routeTask.createDefaultParametersAsync().get();
+
+ // create travel mode selector
+ List<TravelMode> travelModeList = routeTask.getRouteTaskInfo().getTravelModes();
+ ComboBox<TravelMode> travelModes = new ComboBox<>();
+ travelModes.getItems().addAll(travelModeList);
+ travelModes.getSelectionModel().selectedItemProperty().addListener(o -> {
+ routeParameters.setTravelMode(travelModes.getSelectionModel().getSelectedItem());
+ updateRoute();
+ });
+ // display travel mode name within combobox
+ travelModes.setConverter(new StringConverter<TravelMode>() {
+
+ @Override
+ public String toString(TravelMode travelMode) {
+
+ return travelMode.getName();
+ }
+
+ @Override
+ public TravelMode fromString(String fileName) {
+
+ return null;
+ }
+ });
+ travelModes.getSelectionModel().select(0);
+
+ // add travel mode selection to application
+ stackPane.getChildren().add(travelModes);
+ StackPane.setAlignment(travelModes, Pos.TOP_LEFT);
+ StackPane.setMargin(travelModes, new Insets(10, 0, 0, 10));
} catch (InterruptedException | ExecutionException e) {
displayMessage("Error getting default route parameters", e.getMessage());
}
@@ -123,7 +155,6 @@ public class OfflineRoutingSample extends Application {
}
});
-
// create symbol for route
lineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, 0xFF0000FF, 3);
@@ -205,36 +236,6 @@ public class OfflineRoutingSample extends Application {
}
}
});
-
- // create travel mode selector
- List<TravelMode> travelModeList = routeTask.getRouteTaskInfo().getTravelModes();
- ComboBox<TravelMode> travelModes = new ComboBox<>();
- travelModes.getItems().addAll(travelModeList);
- travelModes.getSelectionModel().selectedItemProperty().addListener(o -> {
- routeParameters.setTravelMode(travelModes.getSelectionModel().getSelectedItem());
- updateRoute();
- });
- travelModes.setConverter(new StringConverter<TravelMode>() {
-
- @Override
- public String toString(TravelMode travelMode) {
-
- return travelMode.getName();
- }
-
- @Override
- public TravelMode fromString(String fileName) {
-
- return null;
- }
- });
- travelModes.getSelectionModel().select(0);
-
- // add the map view and control panel to stack pane
- stackPane.getChildren().addAll(mapView, travelModes);
- StackPane.setAlignment(travelModes, Pos.TOP_LEFT);
- StackPane.setMargin(travelModes, new Insets(10, 0, 0, 10));
-
} catch (Exception e) {
// on any error, display the stack trace.
e.printStackTrace();
