O
O
Oleg Sevoc2020-04-15 12:43:35
Yandex maps
Oleg Sevoc, 2020-04-15 12:43:35

How to remove scroll in Yandex map?

Good day to all, tell me how to remove the scroll?
when scrolling the site, the map will scroll and how to remove it?

let myMap;
let placemarkCollections = {};
let placemarkList = {};

// Список городов и магазинов в них
let shopList = [{
        'cityName': 'Гомель',
        'shops': [{
            'coordinates': [52.42508751299095, 31.009944890212992],
            'name': 'Гомель лепешинского 7'
        }]
    }, {
        'cityName': 'Мозырь',
        'shops': [{
            'coordinates': [52.03931576703287, 29.27202567790984],
            'name': 'Интернациональная, 53Б ТЦ «Интерплаза»'
        }],



    }, {
        'cityName': 'Минск',
        'shops': [{
            'coordinates': [53.88897228722193, 27.580830949737535],
            'name': 'г. Минске, ул. Ленина, 27, ТЦ «Ленинград» пав.97 '
        }],



    }


]


ymaps.ready(init);

function init() {

    // Создаем карту
    myMap = new ymaps.Map("map", {
        center: [56, 37],
        zoom: 8,
        controls: [
            'zoomControl'
        ],
        zoomMargin: [20]
    });

    for (let i = 0; i < shopList.length; i++) {

        // Добавляем название города в выпадающий список
        $('select#cities').append('<option value="' + i + '">' + shopList[i].cityName + '</option>');

        // Создаём коллекцию меток для города
        let cityCollection = new ymaps.GeoObjectCollection();

        for (let c = 0; c < shopList[i].shops.length; c++) {
            let shopInfo = shopList[i].shops[c];

            let shopPlacemark = new ymaps.Placemark(
                shopInfo.coordinates, {
                    hintContent: shopInfo.name,
                    balloonContent: shopInfo.name
                }
            );

            if (!placemarkList[i]) placemarkList[i] = {};
            placemarkList[i][c] = shopPlacemark;

            // Добавляем метку в коллекцию
            cityCollection.add(shopPlacemark);

        }

        placemarkCollections[i] = cityCollection;

        // Добавляем коллекцию на карту
        myMap.geoObjects.add(cityCollection);


    }

    $('select#cities').trigger('change');
}


// Переключение города
$(document).on('change', $('select#city'), function() {
    let cityId = $('select#cities').val();

    // Масштабируем и выравниваем карту так, чтобы были видны метки для выбранного города
    myMap.setBounds(placemarkCollections[cityId].getBounds(), {
        checkZoomRange: false
    }).then(function() {

        if (myMap.getZoom() > 18) myMap.setZoom(17); // Если значение zoom превышает 15, то устанавливаем 15.
    });

    $('#shops').html('');
    for (let c = 0; c < shopList[cityId].shops.length; c++) {
        $('#shops').append('<li value="' + c + '">' + shopList[cityId].shops[c].name + '</li>');
    }

});

// Клик на адрес
$(document).on('click', '#shops li', function() {

    let cityId = $('select#cities').val();
    let shopId = $(this).val();

    placemarkList[cityId][shopId].events.fire('click');
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg Sevoc, 2020-04-15
@mrgreeg7

If anyone needs
myMap.behaviors.disable('scrollZoom');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question