Files
Fakel-Gym/template-parts/la-components/blocks/contacts-block/contacts-block.js
GP_DEV 21562852ca full
2025-07-08 14:21:19 +03:00

74 lines
2.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

ymaps.ready(function () {
var buildingCoordinates = [56.462317, 84.969289];
// Смещение карты, чтобы иконка была визуально по центру
var offsetCoefficient = 0.001;
var mapCenter = [
buildingCoordinates[0],
buildingCoordinates[1] - offsetCoefficient
];
var myMap = new ymaps.Map('map', {
center: mapCenter,
zoom: 17,
controls: []
});
// Отключаем все взаимодействия с картой
myMap.behaviors.disable(['scrollZoom', 'drag', 'multiTouch', 'dblClickZoom']);
// Создаем метку с серой дефолтной иконкой
var myPlacemark = new ymaps.Placemark(
buildingCoordinates,
{hintContent: '', balloonContent: ''},
{
preset: 'islands#greyIcon'
}
);
// Делаем карту черно-белой
myMap.panes.get('ground').getElement().style.filter = 'grayscale(100%)';
// Добавляем метку на карту
myMap.geoObjects.add(myPlacemark);
// Логика интерактивности карты остается без изменений
var isMapInteractive = false;
var mapElement = document.getElementById('map');
function activateMap(e) {
if (!isMapInteractive) {
myMap.behaviors.enable(['scrollZoom', 'drag', 'multiTouch', 'dblClickZoom']);
isMapInteractive = true;
setTimeout(function () {
document.addEventListener('click', deactivateMap);
document.addEventListener('touchend', deactivateMap);
}, 100);
e.stopPropagation();
}
}
function deactivateMap(e) {
var target = e.target;
if (e.type === 'touchend' || e.changedTouches || e.changedTouches[0]) {
var touch = e.changedTouches[0];
target = document.elementFromPoint(touch.clientX, touch.clientY);
}
if (!mapElement.contains(target)) {
myMap.behaviors.disable(['scrollZoom', 'drag', 'multiTouch', 'dblClickZoom']);
isMapInteractive = false;
document.removeEventListener('click', deactivateMap);
document.removeEventListener('touchend', deactivateMap);
}
}
mapElement.addEventListener('click', activateMap);
mapElement.addEventListener('touchstart', activateMap);
});