C
C
Cheizer2021-07-06 14:04:30
Yandex maps
Cheizer, 2021-07-06 14:04:30

Yandex map API how to shift the center of the map by px?


Greetings, please tell me how to move the center of the map along with the marker to the left by 100px?

Tried through

var positions = myMap.getGlobalPixelCenter();
            myMap.setGlobalPixelCenter([ positions[0] - 100, positions[1] ]);

But it doesn't work, the call is:
if ($('.map').length) {
        ymaps.ready(function () {
            var myMap = new ymaps.Map('map', {
                center: [55.------, 37.------],
                zoom: 17
            }, {
                searchControl: 'yandex#search'
            });
      
      var positions = myMap.getGlobalPixelCenter();
            myMap.setGlobalPixelCenter([ positions[0] - 100, positions[1] ]);

                myPlacemark = new ymaps.Placemark(myMap.getCenter(), {
                    balloonContent: 'ул. Примерная д. 13А'
                }, {
                    iconLayout: 'default#image',
                    iconImageHref: '../media/bg/local2.svg',
                    iconImageSize: [266, 81],
                    iconImageOffset: [-40, -40]
                });

            myMap.geoObjects
                .add(myPlacemark)
            myMap.controls.remove('searchControl')
            myMap.behaviors.disable('scrollZoom')
        });
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2021-07-06
@Cheizer

var positions = myMap.getGlobalPixelCenter();
var offsetPos = myMap.options.get('projection').fromGlobalPixels([ positions[0] - 100, positions[1] ], myMap.getZoom());
var myPlacemark = new ymaps.Placemark(offsetPos);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question