tulov / angular-yandex-map

AngularJS directive to work with Yandex maps
173 stars 58 forks source link

setZoom не хвататет #34

Closed dn-l closed 7 years ago

dn-l commented 9 years ago

https://tech.yandex.ru/maps/doc/jsapi/2.0/ref/reference/Map-docpage/#setZoom Через ya-zoom масштаб не меняется

ivanovevgeny commented 8 years ago

Вопрос старый, но актуальный: масштаб автоматически не меняется. Решил проблему следующим костылем:

1) Добавляем событие onAfterInit(), чтобы получить объект карты

<ya-map ya-zoom="{{data.zoom}}" ya-center="{{data.center}}" ya-behaviors="default scrollZoom" ya-after-init="fn.afterMapInit($target)">

var _map;
var data = {}, fn = {};
        $scope.data = data;
        $scope.fn = fn;

data.center = [58.979107, 53.410967];
data.zoom = 11;

fn.afterMapInit = afterMapInit;

function afterMapInit (map){
            _map = map;
        };

2) После создания массива объектов на карте

createGeoObjects().then(function() {
                    .. получение адреса
                    if (address) {
                        centerToAddress(address.geometry.coordinates, 13);
                    }
                })

function centerToAddress(coords, zoom) {
            data.center = coords;
            if (zoom) {
                data.zoom = zoom;
            };

            $timeout(function(){
                if (_map) {
                    _map.setCenter(data.center, data.zoom, {duration: 300});
                }
            }, 1000);

            if (zoom) {
                $timeout(function(){
                    if (_map) {
                        _map.setCenter(data.center, data.zoom, {duration: 300});
                    }
                }, 1000);
            }
        }
dn-l commented 7 years ago

outdated