Извините за задержку, посмотрите на этот пример, который я сделал для вас, я думаю, он может вам помочь,
<html>
<head>
<script src="https://api.mqcdn.com/sdk/mapquest-js/v1.3.2/mapquest.js"></script>
<link type="text/css" rel="stylesheet" href="https://api.mqcdn.com/sdk/mapquest-js/v1.3.2/mapquest.css"/>
<script type="text/javascript">
window.onload = function() {
L.mapquest.key = 'lYrP4vF3Uk5zgTiGGuEzQGwGIVDGuy24';
var coords = [
[40.768469, -73.965561],
[40.776224, -73.962194],
[40.783750, -73.977886]
];
var getStyle = function (tA, cA, tB, cB) {
return {
startMarker: {
icon: 'circle',
iconOptions: {
size: 'sm',
primaryColor: cA,
secondaryColor: cA,
symbol: tA
},
title: 'Drag to change location'
},
endMarker: {
icon: 'circle',
iconOptions: {
size: 'sm',
primaryColor: cB,
secondaryColor: cB,
symbol: tB
},
title: 'Drag to change location'
},
routeRibbon: {
color: "#2aa6ce",
opacity: 1.0,
showTraffic: false
}
};
}
var styles = [
getStyle('A', '#aa0000', 'B', '#0000aa'),
getStyle('B', '#0000aa', 'C', '#00aa00')
];
var layers = [];
const directions = L.mapquest.directions();
for (let i = 1; i < coords.length; i++) {
directions.route({
start: coords[i-1],
end: coords[i]
}, createMap);
}
// create map
function createMap(err, response) {
if (!response) {
return;
}
const l = L.mapquest.directionsLayer({
...styles[layers.length],
directionsResponse: response
});
layers.push(l);
if (layers.length === coords.length - 1) {
var map = L.mapquest.map('map', {
center: [40.776224, -73.962194],
layers: L.mapquest.tileLayer('map'),
zoom: 12
});
for(let i = 0; i < layers.length; i++) {
map.addLayer(layers[i]);
}
}
}
}
</script>
</head>
<body style="border: 0; margin: 0;">
<div id="map" style="width: 100%; height: 530px;"></div>
</body>
</html>