|
24 | 24 | var map, datasource; |
25 | 25 |
|
26 | 26 | // 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'; |
28 | 28 |
|
29 | 29 | function getMap() { |
30 | 30 | // Initialize a map instance. |
|
84 | 84 | var startPosition = [-122.33028, 47.60323]; |
85 | 85 | var startPoint = new atlas.data.Feature(new atlas.data.Point(startPosition), { |
86 | 86 | title: 'Seattle', |
87 | | - iconImage: 'pin-blue' |
| 87 | + iconImage: 'pin-blue', |
| 88 | + pointIndex: 0, |
| 89 | + pointType: "waypoint" |
88 | 90 | }); |
89 | 91 |
|
90 | 92 | var endPosition = [-122.124, 47.67491]; |
91 | 93 | var endPoint = new atlas.data.Feature(new atlas.data.Point(endPosition), { |
92 | 94 | title: 'Redmond', |
93 | | - iconImage: 'pin-red' |
| 95 | + iconImage: 'pin-red', |
| 96 | + pointIndex: 1, |
| 97 | + pointType: "waypoint" |
94 | 98 | }); |
95 | 99 |
|
96 | 100 | // Add the data to the data source. |
|
102 | 106 | padding: 50 |
103 | 107 | }); |
104 | 108 |
|
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 | + }; |
108 | 118 |
|
109 | 119 | // 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); |
122 | 123 | }); |
123 | 124 | }); |
124 | 125 | } |
|
0 commit comments