Building a pedestrian multiroute
To build a walking route, you should specify the field routingMode: 'pedestrian' in the routing parameters.
To build a route on public transport, use the Building a iroute on public transport example.
index.html
multiroute_pedestrian.js
<!DOCTYPE html>
<html>
<head>
<title>Examples. The walking route.</title>
<meta
http-equiv="Content-Type"
content="text/html; charset=UTF-8"
/>
<!--
Set your own API-key. Testing key is not valid for other web-sites and services.
Get your API-key on the Developer Dashboard: https://developer.tech.yandex.ru/keys/
-->
<script
src="https://api-maps.yandex.ru/2.1/?lang=en_RU&apikey=<your API-key>"
type="text/javascript"
></script>
<script
src="multiroute_pedestrian.js"
type="text/javascript"
></script>
<style>
html,
body,
#map {
width: 100%;
height: 100%;
padding: 0;
margin: 0;
}
</style>
</head>
<body>
<div id="map"></div>
</body>
</html>
function init() {
// Setting points of the multi-stop route.
var pointA = [55.749, 37.524],
pointB = "Moscow, Red square",
/**
* Creating a multiroute.
* @see https://api.yandex.com/maps/doc/jsapi/2.1/ref/reference/multiRouter.MultiRoute.xml
*/
multiRoute = new ymaps.multiRouter.MultiRoute(
{
referencePoints: [pointA, pointB],
params: {
//The routing type - pedestrian.
routingMode: "pedestrian",
},
},
{
// Automatically set the map boundaries so the entire route is visible.
boundsAutoApply: true,
}
);
// Creating a button.
var changePointsButton = new ymaps.control.Button({
data: { content: "Swap points A and B" },
options: { selectOnClick: true },
});
// Declaring handlers for the button.
changePointsButton.events.add("select", function () {
multiRoute.model.setReferencePoints([pointB, pointA]);
});
changePointsButton.events.add("deselect", function () {
multiRoute.model.setReferencePoints([pointA, pointB]);
});
// Creating the map with the button added to it.
var myMap = new ymaps.Map(
"map",
{
center: [55.739625, 37.5412],
zoom: 12,
controls: [changePointsButton],
},
{
buttonMaxWidth: 300,
}
);
// Adding a multiroute to the map.
myMap.geoObjects.add(multiRoute);
}
ymaps.ready(init);