Skip to content

Commit 9c80f5b

Browse files
committed
removed use of deprecated api
1 parent 7e5c864 commit 9c80f5b

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

src/main/java/com/esri/samples/na/offline_routing/OfflineRoutingSample.java

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111

1212
package com.esri.samples.na.offline_routing;
1313

14+
import java.util.ArrayList;
1415
import java.util.Arrays;
15-
import java.util.HashMap;
1616
import java.util.List;
1717
import java.util.concurrent.ExecutionException;
18+
import java.util.stream.Collectors;
1819

1920
import javafx.application.Application;
2021
import javafx.event.EventHandler;
@@ -57,6 +58,7 @@ public class OfflineRoutingSample extends Application {
5758
private GraphicsOverlay routeOverlay;
5859
private RouteTask routeTask;
5960
private RouteParameters routeParameters;
61+
private List<Graphic> stopGraphics;
6062
private LineSymbol lineSymbol;
6163

6264
private EventHandler<MouseEvent> mouseMovedListener;
@@ -89,6 +91,7 @@ public void start(Stage stage) throws Exception {
8991
stopsOverlay = new GraphicsOverlay();
9092
routeOverlay = new GraphicsOverlay();
9193
mapView.getGraphicsOverlays().addAll(Arrays.asList(routeOverlay, stopsOverlay));
94+
stopGraphics = new ArrayList<>();
9295

9396
// create an offline RouteTask
9497
routeTask = new RouteTask("./samples-data/san_diego/sandiego.geodatabase", "Streets_ND");
@@ -111,10 +114,6 @@ public void start(Stage stage) throws Exception {
111114
// update the moving stop and graphic
112115
Graphic stopGraphic = stopsOverlay.getSelectedGraphics().get(0);
113116
stopGraphic.setGeometry(hoverPoint);
114-
int stopIndex = (int) stopGraphic.getAttributes().get("stopIndex");
115-
Stop newStop = new Stop(hoverPoint);
116-
routeParameters.getStops().set(stopIndex, newStop);
117-
stopGraphic.getAttributes().put("stopIndex", stopIndex);
118117

119118
// update route
120119
if (stopsOverlay.getGraphics().size() > 1) {
@@ -136,21 +135,14 @@ public void start(Stage stage) throws Exception {
136135
// left click adds a stop when not already moving a stop
137136
if (event.getButton() == MouseButton.PRIMARY && stopsOverlay.getSelectedGraphics().isEmpty()) {
138137

139-
// add stop to route parameters
140-
Stop stop = new Stop(point);
141-
routeParameters.getStops().add(stop);
142-
143138
// create graphic for stop
144139
TextSymbol stopLabel = new TextSymbol(20, Integer.toString(stopsOverlay.getGraphics().size() + 1),
145140
0xFFFF0000, TextSymbol.HorizontalAlignment.RIGHT, TextSymbol.VerticalAlignment.TOP);
146141

147-
// save the stop with the graphic
148-
HashMap<String, Object> attributes = new HashMap<>();
149-
attributes.put("stopIndex", routeParameters.getStops().size() - 1);
150-
151-
// create and add the stop graphic to the graphics overlay
152-
Graphic stopGraphic = new Graphic(point, attributes, stopLabel);
142+
// create and add the stop graphic to the graphics overlay and list
143+
Graphic stopGraphic = new Graphic(point, stopLabel);
153144
stopsOverlay.getGraphics().add(stopGraphic);
145+
stopGraphics.add(stopGraphic);
154146

155147
// update the route
156148
updateRoute();
@@ -230,13 +222,17 @@ public TravelMode fromString(String fileName) {
230222
*/
231223
private void updateRoute() {
232224

233-
if (routeParameters.getStops().size() > 1) {
225+
if (stopGraphics.size() > 1) {
234226
// remove listener until route task is solved
235227
if (!stopsOverlay.getSelectedGraphics().isEmpty()) {
236228
mapView.setOnMouseMoved(null);
237229
}
238230

239-
// solve route
231+
// update stops and solve route
232+
List<Stop> stops = stopGraphics.stream()
233+
.map(g -> new Stop((Point) g.getGeometry()))
234+
.collect(Collectors.toList());
235+
routeParameters.setStops(stops);
240236
ListenableFuture<RouteResult> results = routeTask.solveRouteAsync(routeParameters);
241237
results.addDoneListener(() -> {
242238
try {

0 commit comments

Comments
 (0)