Skip to content

Commit fd6a2e8

Browse files
authored
Merge pull request #181 from rbrundritt/main
Update Simple REST Directions.html
2 parents 2eca238 + 9e0beca commit fd6a2e8

2 files changed

Lines changed: 20 additions & 19 deletions

File tree

Samples/Animations/Animate along a route path/Animate along a route path.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
//Extract timestamp information from a custom property of the point features.
122122
//By default the `moveAlongRoute` function looks for a `_timestamp` property on the point features that is a Date.getTime() value.
123123
//If your points already have a `_timestamp` property with the correct value type, you can skip this extraction step.
124-
routePoints = atlas.animations.extractRoutePoints(route, 'timestamp');
124+
routePoints = atlas.animations.extractRoutePoints(routePoints, 'timestamp');
125125

126126
//Create the animation.
127127
animation = atlas.animations.moveAlongRoute(routePoints, pin, {

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

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
var map, datasource;
2525

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

2929
function getMap() {
3030
// Initialize a map instance.
@@ -84,13 +84,17 @@
8484
var startPosition = [-122.33028, 47.60323];
8585
var startPoint = new atlas.data.Feature(new atlas.data.Point(startPosition), {
8686
title: 'Seattle',
87-
iconImage: 'pin-blue'
87+
iconImage: 'pin-blue',
88+
pointIndex: 0,
89+
pointType: "waypoint"
8890
});
8991

9092
var endPosition = [-122.124, 47.67491];
9193
var endPoint = new atlas.data.Feature(new atlas.data.Point(endPosition), {
9294
title: 'Redmond',
93-
iconImage: 'pin-red'
95+
iconImage: 'pin-red',
96+
pointIndex: 1,
97+
pointType: "waypoint"
9498
});
9599

96100
// Add the data to the data source.
@@ -102,23 +106,20 @@
102106
padding: 50
103107
});
104108

105-
// Create the route request with the query being the start and end point in the format 'startLongitude,startLatitude:endLongitude,endLatitude'.
106-
var routeRequestURL = routeUrl
107-
.replace('{query}', `${startPosition[1]},${startPosition[0]}:${endPosition[1]},${endPosition[0]}`);
109+
// Create the route request.
110+
var routeRequestBody = {
111+
type: 'FeatureCollection',
112+
features: [startPoint, endPoint],
113+
optimizeRoute: 'fastestWithTraffic',
114+
routeOutputOptions: ['routePath'],
115+
maxRouteCount: 1,
116+
travelMode: 'driving'
117+
};
108118

109119
// Process the request and render the route result on the map.
110-
processRequest(routeRequestURL).then(directions => {
111-
// Extract the first route from the directions.
112-
const route = directions.routes[0];
113-
114-
// Combine all leg coordinates into a single array.
115-
const routeCoordinates = route.legs.flatMap(leg => leg.points.map(point => [point.longitude, point.latitude]));
116-
117-
// Create a LineString from the route path points.
118-
const routeLine = new atlas.data.LineString(routeCoordinates);
119-
120-
// Add it to the data source.
121-
datasource.add(routeLine);
120+
processPostRequest(routeUrl, JSON.stringify(routeRequestBody)).then(directions => {
121+
// Add directions to the data source.
122+
datasource.add(directions);
122123
});
123124
});
124125
}

0 commit comments

Comments
 (0)