From 978af4e86d6f9e9b6a0f9164d08a735489c79705 Mon Sep 17 00:00:00 2001 From: Alexander Gusev Date: Mon, 14 Sep 2015 11:35:05 +0300 Subject: [PATCH 1/3] FIX #12 Zoom of the map won't be larger then initial map zoom when ymapsConfig.fitMarkers = true --- angular-ymaps.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/angular-ymaps.js b/angular-ymaps.js index 514b2ec..3815156 100644 --- a/angular-ymaps.js +++ b/angular-ymaps.js @@ -93,6 +93,8 @@ angular.module('ymaps', []) map.setBounds(collection.getBounds(), { checkZoomRange: true, zoomMargin: config.fitMarkersZoomMargin + }).then(function () { + if(map.getZoom() > $scope.zoom) map.setZoom($scope.zoom); }); } }, 100)); From e20d5d0055a91401ff3590c45973fefb9500a6f3 Mon Sep 17 00:00:00 2001 From: Alexander Gusev Date: Mon, 14 Sep 2015 12:02:54 +0300 Subject: [PATCH 2/3] FIX #12 --- angular-ymaps.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/angular-ymaps.js b/angular-ymaps.js index 3815156..40d7cb3 100644 --- a/angular-ymaps.js +++ b/angular-ymaps.js @@ -90,11 +90,14 @@ angular.module('ymaps', []) function initAutoFit(map, collection, ymaps) { collection.events.add('boundschange', debounce(function () { if(collection.getLength() > 0) { + var maxZoomBefore = map.options.get('maxZoom'); + map.options.set('maxZoom', $scope.zoom); map.setBounds(collection.getBounds(), { checkZoomRange: true, zoomMargin: config.fitMarkersZoomMargin }).then(function () { - if(map.getZoom() > $scope.zoom) map.setZoom($scope.zoom); + map.options.set('maxZoom', maxZoomBefore); + map.setZoom(map.getZoom()); // Setting current zoom. Without this the plus button on the yandex map doesn't get updated after .set('maxZoom'). }); } }, 100)); From 591e4ad7161bb5c8b29939f42516c08424cb56ce Mon Sep 17 00:00:00 2001 From: goooseman Date: Mon, 14 Sep 2015 13:09:28 +0300 Subject: [PATCH 3/3] Tests pass Rewrite map mock, so test successfully pass --- spec/ymaps.spec.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/spec/ymaps.spec.js b/spec/ymaps.spec.js index c863745..df6ae01 100644 --- a/spec/ymaps.spec.js +++ b/spec/ymaps.spec.js @@ -43,13 +43,18 @@ describe('Ymaps', function() { $provide.value('debounce', angular.identity); $provide.factory('ymapsLoader', function($q) { mapMock = { + options: jasmine.createSpyObj('mapOptions', ['get', 'set']), events: jasmine.createSpyObj('mapEvents', ['add']), panTo: jasmine.createSpy('panSpy').and.callFake(function() { this.deferred = $q.defer(); this.deferred.promise.always = this.deferred.promise.finally; return this.deferred.promise; }), - setBounds: jasmine.createSpy('mapBounds'), + setBounds: jasmine.createSpy('mapBounds').and.callFake(function() { + this.deferred = $q.defer(); + this.deferred.promise.always = this.deferred.promise.finally; + return this.deferred.promise; + }), setZoom: jasmine.createSpy('zoomSpy'), controls: jasmine.createSpyObj('mapObjControls', ['add']), geoObjects: jasmine.createSpyObj('mapObjElements', ['add']) @@ -69,7 +74,7 @@ describe('Ymaps', function() { GeoObjectCollection: jasmine.createSpy('geoObjectsCollection').and.returnValue(geoObjectsMock), Placemark: jasmine.createSpy('placemark').and.returnValue(placemarkMock) }; - return { + return { ready: function(callback) {callback(ymapsMock);} }; }); @@ -146,7 +151,7 @@ describe('Ymaps', function() { scope.$apply(); callback(new YaEvent({newCenter: [62.16, 34.56], newZoom: 23})); expect(scope.center).toEqual([62.16, 34.56]); - }); + }); it('should add nested markers to map', function() { createElement(