Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix isValidCenter() for null value causing center-directive to fail #1021

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/services/leafletHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ angular.module('leaflet-directive').service('leafletHelpers', function($q, $log)
equals: angular.equals,

isValidCenter: function(center) {
return angular.isDefined(center) && angular.isNumber(center.lat) &&
return center !== null && angular.isObject(center) && angular.isNumber(center.lat) &&
angular.isNumber(center.lng) && angular.isNumber(center.zoom);
},

Expand Down
13 changes: 13 additions & 0 deletions test/unit/010-centerDirectiveSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@ describe('Directive: leaflet center', function() {
});
});

it('should fallback to default map center if the model value is null', function () {
scope.center = null;
var element = angular.element('<leaflet center="center"></leaflet>');
element = $compile(element)(scope);
scope.$digest();

leafletData.getMap().then(function(map) {
expect(map.getZoom()).toEqual(1);
expect(map.getCenter().lat).toEqual(0);
expect(map.getCenter().lng).toEqual(0);
});
});

it('should update the map center if the initial center scope properties are set', function() {
var element = angular.element('<leaflet center="center"></leaflet>');
element = $compile(element)(scope);
Expand Down
46 changes: 46 additions & 0 deletions test/unit/services/leafletHelpersSpec.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.