JSFiddle - React, Tailwind, and code Playground
HTML
<!DOCTYPE html>
<html>
<head>
<title>Примеры. Пользовательский макет балуна кластера.</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- Если вы используете API локально, то в URL ресурса необходимо указывать протокол в стандартном виде (http://...)-->
<script src="//api-maps.yandex.ru/2.0/?load=package.full&lang=ru-RU" type="text/javascript"></script>
<style>
.cluster-balloon-item {
margin: 10px;
cursor: pointer;
}
#map {
width: 600px;
height: 500px;
}
</style>
</head>
<body>
<div id="map"></div>
</body>
</html>
JavaScript
ymaps.ready(init);
function init() {
var center = [55.74954, 37.621587],
myMap = new ymaps.Map('map', {
center: center,
zoom: 10
}),
// Создадим макет правой части балуна кластера.
MainContentLayout = ymaps.templateLayoutFactory.createClass('', {
build: function () {
// Сначала вызываем метод build родительского класса.
MainContentLayout.superclass.build.call(this);
// Нужно отслеживать, какой из пунктов левого меню выбран,
// чтобы обновлять содержимое правой части.
this.stateListener = this.getData().state.events.group()
.add('change', this.onStateChange, this);
// Запоминаем текущий активный объект.
this.activeObject = this.getData().state.get('activeObject');
this.applyContent();
},
clear: function () {
if (this.activeObjectLayout) {
this.activeObjectLayout.setParentElement(null);
this.activeObjectLayout = null;
}
// Снимаем слушателей изменения полей.
this.stateListener.removeAll();
// А затем вызываем метод clear родительского класса.
MainContentLayout.superclass.clear.call(this);
},
onStateChange: function () {
// При изменении одного из полей состояния
// проверяем, не сменился ли активный объект.
var newActiveObject = this.getData().state.get('activeObject');
if (newActiveObject != this.activeObject) {
// Если объект изменился, нужно обновить
// содержимое правой части.
this.activeObject = newActiveObject;
this.applyContent();
}
},
...