У меня есть следующий код JavaScript, чтобы показать рассчитанный маршрут и варианты на моем сайте. Я хочу предварительно выбрать маршрут с параметром routeIndex, но это не работает.
var map, infobox, directionsManager, directionWaypointLayer;
function GetMap() {
map = new Microsoft.Maps.Map('#myMap', {});
//Create a layer for managing custom waypoints.
directionWaypointLayer = new Microsoft.Maps.Layer();
//Add mouse events for showing instruction when hovering pins in directions waypoint layer.
Microsoft.Maps.Events.addHandler(directionWaypointLayer, 'mouseover', showInstruction);
Microsoft.Maps.Events.addHandler(directionWaypointLayer, 'mouseout', hideInstruction);
map.layers.insert(directionWaypointLayer);
//Create a reusable infobox.
infobox = new Microsoft.Maps.Infobox(map.getCenter(), {
showCloseButton: false,
visible: false
});
infobox.setMap(map);
//Load the directions module.
Microsoft.Maps.loadModule('Microsoft.Maps.Directions', function () {
//Create an instance of the directions manager.
directionsManager = new Microsoft.Maps.Directions.DirectionsManager(map);
directionsManager.setRequestOptions({ routeMode: Microsoft.Maps.Directions.RouteMode.driving, maxRoutes: 3, routeIndex: 2, avoidTraffic: false, showInstruction: false });
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function (m, key, value) {
vars[key] = value;
});
directionsManager.addWaypoint(new Microsoft.Maps.Directions.Waypoint({ location: new Microsoft.Maps.Location(vars["wp1"].split(',')[0], vars["wp1"].split(',')[1]) }));
directionsManager.addWaypoint(new Microsoft.Maps.Directions.Waypoint({ location: new Microsoft.Maps.Location(vars["wp2"].split(',')[0], vars["wp2"].split(',')[1]) }));
//Calculate directions.
directionsManager.calculateDirections();
});
}