Skip to content

Commit 8d5c2d1

Browse files
authored
Merge pull request #157 from Esri/tschie/update-route-samples
Tschie/update route samples
2 parents c0187c9 + b0ff81e commit 8d5c2d1

File tree

8 files changed

+363
-366
lines changed

8 files changed

+363
-366
lines changed

src/main/java/com/esri/samples/na/closest_facility/ClosestFacilitySample.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package com.esri.samples.na.closest_facility;
1717

1818
import java.util.Arrays;
19+
import java.util.Collections;
1920
import java.util.List;
2021
import java.util.concurrent.ExecutionException;
2122
import java.util.stream.Collectors;
@@ -170,7 +171,7 @@ private void populateParametersAndSolveRoute() {
170171
facilityParameters.clearIncidents();
171172
// set new parameters to find route
172173
facilityParameters.setFacilities(facilities);
173-
facilityParameters.setIncidents(Arrays.asList(new Incident(incidentPoint)));
174+
facilityParameters.setIncidents(Collections.singletonList(new Incident(incidentPoint)));
174175

175176
// find closest route using parameters from above
176177
ListenableFuture<ClosestFacilityResult> result = task.solveClosestFacilityAsync(facilityParameters);

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 {
Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,44 @@
1-
<h1>Service Area Task</h1>
2-
3-
<p>Demonstrates how to find services areas around a point using the ServiceAreaTask. A service area shows locations that can be reached from a facility based off a certain impedance [such as travel time]. Barriers can also be added which can effect the impedance by not letting traffic through or adding the time is takes to pass that barrier.</p>
4-
5-
<p><img src="ServiceAreaTask.gif"/></p>
6-
7-
<h2>How to use sample</h2>
8-
<li>In order to find any service areas at least one ServiceAreaFaciltiy needs to be added.</li>
9-
<li>To add a facility, click the facility button, then click anywhere on the MapView.</li>
10-
<li>To add a barrier, click the barrier button, and click multiple locations on MapView.</li>
11-
<ul><li>Hit the barrier button again to finish drawing barrier.</li>
12-
<li>Hitting any other button will also stop the barrier from drawing.</li></ul>
13-
<li>To show service areas around facilities that were added, click show service areas button.</li>
14-
<li>Reset button, clears all graphics and reset ServiceAreaTask.</li>
15-
16-
<h2>How it works</h2>
17-
18-
<p>To display service areas around a certain location:</p>
19-
20-
<ol>
21-
<li>Create a <code>ServiceAreaTask</code> from an online service.</li>
22-
<li>Get ServiceAreaParameters from task, <code>task.createDefaultParametersAsync()</code></li>
23-
<li>Setting return polygons to true will return all services areas, <code>serviceAreaParameters.setReturnPolygons(true)</code></li>
24-
<li>Add a <code>ServiceAreaFacilty</code> to parameters, <code>serviceAreaParameters.setFacilities(serviceAreaFacility)</code></li>
25-
<li>Get <code>ServiceAreaResult</code> by solving the service area task using parameters, <code>task.solveServiceAreaAsync(serviceAreaParameters).get()</code></li>
26-
<li>Get any <code>ServiceAreaPolygon</code>s that were returned, <code>serviceAreaResult.getResultPolygons(facilityIndex)</code></li>
27-
<ul><li>facilityIndex is the faciltiy from the mapview that you want to get the services areas of</li></ul>
28-
<li>Display services areas to MapView, <code>graphicsOverlay.getGraphics().add(new Graphic(serviceAreaPolygon.getGeometry(), fillSymbol))</code></li>
29-
</ol>
30-
31-
<h2>Features</h2>
32-
<ul>
33-
<li>ArcGISMap</li>
34-
<li>GraphicsOverlay</li>
35-
<li>MapView</li>
36-
<li>PolylineBarrier</li>
37-
<li>ServiceAreaFacility</li>
38-
<li>ServiceAreaParameters</li>
39-
<li>ServiceAreaPolygon</li>
40-
<li>ServiceAreaResult</li>
41-
<li>ServiceAreaTask</li>
42-
<li>PolylineBuilder</li>
43-
</ul>
44-
1+
<h1>Service Area Task</h1>
2+
3+
<p>Demonstrates how to find services areas around a point using the ServiceAreaTask. A service area shows locations that can be reached from a facility based off a certain impedance [such as travel time]. Barriers can also be added which can effect the impedance by not letting traffic through or adding the time is takes to pass that barrier.</p>
4+
5+
<p><img src="ServiceAreaTask.gif"/></p>
6+
7+
<h2>How to use sample</h2>
8+
<li>In order to find any service areas at least one ServiceAreaFaciltiy needs to be added.</li>
9+
<li>To add a facility, click the facility button, then click anywhere on the MapView.</li>
10+
<li>To add a barrier, click the barrier button, and click multiple locations on MapView.</li>
11+
<ul><li>Hit the barrier button again to finish drawing barrier.</li>
12+
<li>Hitting any other button will also stop the barrier from drawing.</li></ul>
13+
<li>To show service areas around facilities that were added, click show service areas button.</li>
14+
<li>Reset button, clears all graphics and reset ServiceAreaTask.</li>
15+
16+
<h2>How it works</h2>
17+
18+
<p>To display service areas around a certain location:</p>
19+
20+
<ol>
21+
<li>Create a <code>ServiceAreaTask</code> from an online service.</li>
22+
<li>Get ServiceAreaParameters from task, <code>task.createDefaultParametersAsync()</code></li>
23+
<li>Setting return polygons to true will return all services areas, <code>serviceAreaParameters.setReturnPolygons(true)</code></li>
24+
<li>Add a <code>ServiceAreaFacilty</code> to parameters, <code>serviceAreaParameters.setFacilities(serviceAreaFacility)</code></li>
25+
<li>Get <code>ServiceAreaResult</code> by solving the service area task using parameters, <code>task.solveServiceAreaAsync(serviceAreaParameters).get()</code></li>
26+
<li>Get any <code>ServiceAreaPolygon</code>s that were returned, <code>serviceAreaResult.getResultPolygons(facilityIndex)</code></li>
27+
<ul><li>facilityIndex is the faciltiy from the mapview that you want to get the services areas of</li></ul>
28+
<li>Display services areas to MapView, <code>graphicsOverlay.getGraphics().add(new Graphic(serviceAreaPolygon.getGeometry(), fillSymbol))</code></li>
29+
</ol>
30+
31+
<h2>Features</h2>
32+
<ul>
33+
<li>ArcGISMap</li>
34+
<li>GraphicsOverlay</li>
35+
<li>MapView</li>
36+
<li>PolylineBarrier</li>
37+
<li>ServiceAreaFacility</li>
38+
<li>ServiceAreaParameters</li>
39+
<li>ServiceAreaPolygon</li>
40+
<li>ServiceAreaResult</li>
41+
<li>ServiceAreaTask</li>
42+
<li>PolylineBuilder</li>
43+
</ul>
44+

0 commit comments

Comments
 (0)