Skip to content

Commit be5445a

Browse files
committed
Update Simple REST Directions.html
1 parent 6d4cd87 commit be5445a

1 file changed

Lines changed: 19 additions & 18 deletions

File tree

Samples/REST Services/Simple REST Directions/Simple REST Directions.html

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
var tokenServiceUrl = 'https://samples.azuremaps.com/api/GetAzureMapsToken';
3131

3232
// URL for the Azure Maps Route API.
33-
var routeUrl = 'https://{azMapsDomain}/route/directions/json?api-version=1.0&query={query}&routeRepresentation=polyline&travelMode=car&view=Auto';
33+
var routeUrl = 'https://{azMapsDomain}/route/directions?api-version=2025-01-01';
3434

3535
// Function to retrieve an Azure Maps access token.
3636
function getToken(resolve, reject, map) {
@@ -96,13 +96,17 @@
9696
var startPosition = [-122.33028, 47.60323];
9797
var startPoint = new atlas.data.Feature(new atlas.data.Point(startPosition), {
9898
title: 'Seattle',
99-
iconImage: 'pin-blue'
99+
iconImage: 'pin-blue',
100+
pointIndex: 0,
101+
pointType: "waypoint"
100102
});
101103

102104
var endPosition = [-122.124, 47.67491];
103105
var endPoint = new atlas.data.Feature(new atlas.data.Point(endPosition), {
104106
title: 'Redmond',
105-
iconImage: 'pin-red'
107+
iconImage: 'pin-red',
108+
pointIndex: 1,
109+
pointType: "waypoint"
106110
});
107111

108112
// Add the data to the data source.
@@ -114,23 +118,20 @@
114118
padding: 50
115119
});
116120

117-
// Create the route request with the query being the start and end point in the format 'startLongitude,startLatitude:endLongitude,endLatitude'.
118-
var routeRequestURL = routeUrl
119-
.replace('{query}', `${startPosition[1]},${startPosition[0]}:${endPosition[1]},${endPosition[0]}`);
121+
// Create the route request.
122+
var routeRequestBody = {
123+
type: 'FeatureCollection',
124+
features: [startPoint, endPoint],
125+
optimizeRoute: 'fastestWithTraffic',
126+
routeOutputOptions: ['routePath'],
127+
maxRouteCount: 1,
128+
travelMode: 'driving'
129+
};
120130

121131
// Process the request and render the route result on the map.
122-
processRequest(routeRequestURL).then(directions => {
123-
// Extract the first route from the directions.
124-
const route = directions.routes[0];
125-
126-
// Combine all leg coordinates into a single array.
127-
const routeCoordinates = route.legs.flatMap(leg => leg.points.map(point => [point.longitude, point.latitude]));
128-
129-
// Create a LineString from the route path points.
130-
const routeLine = new atlas.data.LineString(routeCoordinates);
131-
132-
// Add it to the data source.
133-
datasource.add(routeLine);
132+
processPostRequest(routeUrl, JSON.stringify(routeRequestBody)).then(directions => {
133+
// Add directions to the data source.
134+
datasource.add(directions);
134135
});
135136
});
136137
}

0 commit comments

Comments
 (0)