Moona/moona/static/js/safe_app_school/mapbasics_templates.js

51 lines
1.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

function init() {
// Задаём точки мультимаршрута.
var pointA = <point1>,
pointB = <point2>,
/**
* Создаем мультимаршрут.
* @see https://api.yandex.ru/maps/doc/jsapi/2.1/ref/reference/multiRouter.MultiRoute.xml
*/
multiRoute = new ymaps.multiRouter.MultiRoute({
referencePoints: [
pointA,
pointB
],
params: {
//Тип маршрутизации - пешеходная маршрутизация.
routingMode: 'pedestrian'
}
}, {
// Автоматически устанавливать границы карты так, чтобы маршрут был виден целиком.
boundsAutoApply: true
});
// Создаем кнопку.
var changePointsButton = new ymaps.control.Button({
data: {content: "Поменять местами точки А и В"},
options: {selectOnClick: false}
});
// Объявляем обработчики для кнопки.
changePointsButton.events.add('select', function () {
multiRoute.model.setReferencePoints([pointB, pointA]);
});
changePointsButton.events.add('deselect', function () {
multiRoute.model.setReferencePoints([pointA, pointB]);
});
// Создаем карту с добавленной на нее кнопкой.
var myMap = new ymaps.Map('map', {
center: [55.739625, 37.54120],
zoom: 12,
controls: [changePointsButton]
}, {
buttonMaxWidth: 300
});
// Добавляем мультимаршрут на карту.
myMap.geoObjects.add(multiRoute);
}
ymaps.ready(init);