Народ, помогите, имеется код вывода карты, на карте есть метки, при клике на метку вылезает окно(baloon). Как мне добавить событие, при клике на этот baloon? Нужно чтобы при клике на контент, карта приближалась.
<script>
var ccaij = <?php echo json_encode($curCityAdrIds); ?>;
$(document).ready(function(){
ymaps.ready(init);
function init () {
var string_coordinates = [];
string_coordinates.push(<?=$arResult["ITEMS"][0]["PROPERTY_OFFICE_COORDS_D_VALUE"]?>);
string_coordinates.push(<?=$arResult["ITEMS"][0]["PROPERTY_OFFICE_COORDS_S_VALUE"]?>);
//alert(string_coordinates);
var myMap = new ymaps.Map('map', {
center: string_coordinates,
controls: [],
zoom: 10
}, {
searchControlProvider: 'yandex#search'
}),
objectManager = new ymaps.ObjectManager({
clusterize: true,
gridSize: 32
});
objectManager.objects.options.set({iconLayout: 'default#image',iconImageHref: '<?=SITE_TEMPLATE_PATH?>/img/map-location2.png',iconImageSize: [61, 75],iconImageOffset: [-6, -72]});
objectManager.clusters.options.set({iconLayout: 'default#image',iconImageHref: '<?=SITE_TEMPLATE_PATH?>/img/map-location2.png',iconImageSize: [61, 75],iconImageOffset: [-6, -72]});
//objectManager.objects.events.add('click', event => {alert('клац');});
myMap.geoObjects.add(objectManager);
var data = {
"type": "FeatureCollection",
"features": [
<?foreach($arResult["ITEMS"] as $key => $value):?>
{"type":
"Feature",
"id": <?=$value['ID']?>,
"geometry": {
"type": "Point",
"coordinates": [
<?=substr($value["PROPERTY_OFFICE_COORDS_D_VALUE"], 0, 9)?>,
<?=substr($value["PROPERTY_OFFICE_COORDS_S_VALUE"], 0, 9)?>
]
},
"properties": {
"balloonContent": "<div class='map_item baloon' data-go='[<?=$value["PROPERTY_OFFICE_COORDS_D_VALUE"]?>, <?=$value["PROPERTY_OFFICE_COORDS_S_VALUE"]?>]'><span class='c_red'><b><?=$value['PROPERTY_OFFICE_ADRESS_VALUE']?></b></span><span>Режим работы: </span><div class='schedule'><span class='c_red'>Пн-Пт</span><span><?=$value['PROPERTY_OFFICE_TIME_WORKDAYS_VALUE']?></span><span class='c_red'>Сб-Вс</span><span><?=$value['PROPERTY_OFFICE_TIME_HOLIDAYS_VALUE"=']?></span></div></div>", "clusterCaption": "<?=$value["NAME"]?>", "hintContent": "<?=$value["PROPERTY_OFFICE_ADRESS_VALUE"]?>"
}
}<?if($arResult["ITEMS"][$key+1]["NAME"]!=""):?>,<?endif;?>
<?endforeach;?>
]
}
objectManager.add(data)
$('.map_item').on('click',function(){
/*myMap.geoObjects.each(function (geoObject) {
console.log(geoObject.properties);
if (geoObject.properties.get('id') == '0') {
// do something
return false;
}
});*/
var pos = $(this).data('go');
myMap.setCenter(pos, 15, {
duration: 2000
});
//myMap.balloon.open();
});
var mapBounds = myMap.getBounds(),
mapBotLeft = mapBounds[0],
mapTopRight = mapBounds[1];
data.features.forEach(function(entry) {
if (entry.geometry.coordinates[0] < mapBotLeft[0] ||
entry.geometry.coordinates[0] > mapTopRight[0] ||
entry.geometry.coordinates[1] < mapBotLeft[1] ||
entry.geometry.coordinates[1] > mapTopRight[1]) {
$("#point"+entry.id).hide();
} else {
$("#point"+entry.id).show();
}
$('.map_bg .left_side').css("opacity", 1);
});
myMap.events.add('boundschange', function (event) {
mapBounds = myMap.getBounds();
mapBotLeft = mapBounds[0];
mapTopRight = mapBounds[1];
data.features.forEach(function(entry) {
if (entry.geometry.coordinates[0] < mapBotLeft[0] ||
entry.geometry.coordinates[0] > mapTopRight[0] ||
entry.geometry.coordinates[1] < mapBotLeft[1] ||
entry.geometry.coordinates[1] > mapTopRight[1]) {
var hideAdr = true;
for (index = 0; index < ccaij.length; ++index) {
if(entry.id == ccaij[index]) {
hideAdr = false;
break;
}
}
if(hideAdr) {
$("#point"+entry.id).hide();
} else {
$("#point"+entry.id).show();
}
} else {
$("#point"+entry.id).show();
}
});
});
}
});
</script>