V
V
VasPaGit2019-02-21 21:06:46
Yandex
VasPaGit, 2019-02-21 21:06:46

Yandex map settings on different screen extensions?

It is necessary that on the desktop there is one central point, and on the phone another. How will this be achieved? Just like changing other settings, for example, on the computer there is a "drag" setting, but on the phone it is disabled. Is there something like media?

ymaps.ready(init);
    function init() {
      var myMap = new ymaps.Map("map", {
        center: [54.755553, 55.897349],
        zoom: 12
      });

      myMap.controls.remove('geolocationControl').remove('searchControl').remove('routeButton').remove('rulerControl').remove('fullscreenControl').remove('typeSelector').remove('trafficControl');

      myMap.behaviors.disable([
        'scrollZoom',
        'drag'
      ]);

      var placemark = new ymaps.Placemark([54.752656, 56.002053], {}, {
        iconLayout: 'default#image',
        iconImageHref: 'img/maps.png',
        iconImageSize: [48, 48],
        iconImageOffset: [-24, -48]
      });

      myMap.geoObjects.add(placemark);
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
fromaline, 2020-01-29
@fromaline

Have a nice day)
Yes, of course, such an opportunity exists, because. this is JS, you just need to bind the handler to the event

const APIReadyHandler = () => {
        if (window.innerWidth <= 500) {
          myMap.setCenter([59.465577, 30.900147]);
          myMap.behaviors.enable('scrollZoom', 'drag')
        }
      }
      ymaps.ready(function() {
        APIReadyHandler();
      });

In this snippet, when the API is ready for use, the function is executed and the same settings change occurs. If you need to change when the viewport is resized, then the function must be executed on the window.onresize event.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question