JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://api-maps.yandex.ru/2.1/?lang=ru_RU"></script>
<div id="map"></div>
CSS
#map {
width: 600px;
height: 400px;
}
JavaScript
var globalOM;
var globalMAP;
function createFeatures () {
var features = {
'type': 'FeatureCollection',
'features': [{
type: 'Feature',
id: 0,
geometry: {
type: 'Point',
coordinates: [59.9249506, 30.3331176],
viewportMargin: 0,
margin: 0,
},
}, {
type: 'Feature',
id: 1,
geometry: {
type: 'Point',
coordinates: [59.923721, 30.33688],
viewportMargin: 0,
margin: 0,
},
}, {
type: 'Feature',
id: 2,
geometry: {
type: 'Point',
coordinates: [59.928212, 30.333457],
viewportMargin: 0,
margin: 0,
}
}]
}
globalOM.add(features);
globalMAP.geoObjects.add(globalOM);
globalMAP.setBounds(globalOM.getBounds());
}
ymaps.ready(function () {
var map_options = {
center: ['61.698653', '99.505405'],
controls: ['zoomControl'],
zoom: 10,
};
var map_parameters = {
autoFitToViewport: 'always',
suppressMapOpenBlock: true,
yandexMapDisablePoiInteractivity: true,
zoomControlPosition: { right: 20, top: 20, },
zoomControlSize: 'medium',
};
var object_manager_options = {
clusterize: true,
viewportMargin: 0,
margin: 0,
gridSize: 128,
};
globalMAP = new ymaps.Map('map', map_options, map_parameters);
globalOM = new ymaps.ObjectManager(object_manager_options);
createFeatures();
var closest = ymaps.geoQuery(globalOM).getClosestTo([59.9249506, 30.3331176]);
console.log(closest);
});