JSFiddle - React, Tailwind, and code Playground
HTML
<div id="map"></div>
CSS
</style>
<script type="text/javascript" src="https://api-maps.yandex.ru/2.1/?lang=ru-RU"></script>
<script type="text/javascript" src="https://yandex.st/jquery/2.1.0/jquery.min.js"></script>
<style>
html, body, #map {
width: 100%; height: 100%; padding: 0; margin: 0;
}
Babel + JSX
ymaps.ready(init);
function init() {
var myMap = new ymaps.Map('map', {
center: [55.75396, 37.620393],
zoom: 10,
controls: ['zoomControl']
});
var ClusterContentBalloonLayout= ymaps.templateLayoutFactory.createClass('{% for item in properties.data %}<li>{{ item.content }}</li>{% endfor %}', {
build: function () {
console.info('build')
var _this = this;
ClusterContentBalloonLayout.superclass.build.call(this);
var geoObjects = this.getData().properties.get('geoObjects');
var ids = geoObjects
.map(geoObject => geoObject.id);
var data = _this.getData().properties.get('data');
console.info('data', data);
if (!data) {
getPointInfo(ids).done(function (data) {
_this.getData().properties.set('data', data);
_this.rebuild();
});
}
}
}
);
var loadingObjectManager = new ymaps.LoadingObjectManager('http://brainshock-001-site3.gtempurl.com/YandexExample.ashx',
{
clusterize: true,
splitRequests: false,
clusterOpenBalloonOnClick: true,
clusterDisableClickZoom: false,
clusterBalloonContentLayout: ClusterContentBalloonLayout,
geoObjectOpenBalloonOnClick: true
});
myMap.geoObjects.add(loadingObjectManager);
// Функция, эмулирующая запрос за данными на сервер.
function getPointInfo(ids) {
var defer = ymaps.vow.defer();
window.setTimeout(() => {
defer.resolve(ids.map(id => ({content: 'Контент метки id: ' + id})));
}, 1000);
return defer.promise();
}
}