JSFiddle - React, Tailwind, and code Playground
by Tk Dk
HTML
<script src="http://api-maps.yandex.ru/2.1/?lang=ru_RU"></script>
<div id="map"></div>
CSS
#map {
width: 500px;
height: 500px;
}
JavaScript
function init() {
var myMap = new ymaps.Map('map', {
center: [55.752278, 37.622095],
zoom: 9,
type: 'yandex#map',
behaviors: ['scrollZoom', 'drag'],
controls: ['routeEditor']
}),
searchStartPoint = new ymaps.control.SearchControl({
options: {
useMapBounds: true,
noPlacemark: true,
noPopup: true,
placeholderContent: 'Адрес начальной точки',
size: 'small'
}
}),
searchFinishPoint = new ymaps.control.SearchControl({
options: {
useMapBounds: true,
noCentering: true,
noPopup: true,
noPlacemark: true,
placeholderContent: 'Адрес конечной точки',
size: 'small',
float: 'none',
position: { left: 10, top: 44 }
}
}),
calculator = new DeliveryCalculator(myMap, myMap.getCenter());
myMap.controls.add(searchStartPoint);
myMap.controls.add(searchFinishPoint);
searchStartPoint.events.add('resultselect', function (e) {
var results = searchStartPoint.getResultsArray(),
selected = e.get('index'),
point = results[selected].geometry.getCoordinates();
calculator.setStartPoint(point);
})
.add('load', function (event) {
// По полю skip определяем, что это не дозагрузка данных.
// По getRusultsCount определяем, что есть хотя бы 1 результат.
if (!event.get('skip') && searchStartPoint.getResultsCount()) {
searchStartPoint.showResult(0);
}
});
searchFinishPoint.events.add('resultselect', function (e) {
var results = searchFinishPoint.getResultsArray(),
selected = e.get('index'),
point = results[selected].geometry.getCoordinates();
...