From 45ad8ee4680925d20819314b46a46d0ee03c4a1e Mon Sep 17 00:00:00 2001 From: rlx <0x0073@0x2620.org> Date: Sat, 29 Oct 2011 11:04:21 +0000 Subject: [PATCH] map fixes (when loaded without places, zoom out; when resizing causes the minimum zoom to be larger than the current zoom, zoom out) --- source/Ox.UI/js/Map/Ox.Map.js | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/source/Ox.UI/js/Map/Ox.Map.js b/source/Ox.UI/js/Map/Ox.Map.js index 348ddadd..74925e9d 100644 --- a/source/Ox.UI/js/Map/Ox.Map.js +++ b/source/Ox.UI/js/Map/Ox.Map.js @@ -553,6 +553,11 @@ Ox.Map = function(options, self) { } } + function crossesDateline() { + var bounds = self.map.getBounds(); + return bounds.getSouthWest().lng() > bounds.getNorthEast().lng(); + } + function editing() { var place = getSelectedPlace(); return place && place.editing; @@ -769,7 +774,13 @@ Ox.Map = function(options, self) { } else if (self.options.selected) { selectPlace(self.options.selected, true); } else { - mapBounds && self.map.fitBounds(mapBounds); + if (mapBounds) { + if (isEmpty(mapBounds)) { + self.map.setZoom(self.minZoom); + } else { + self.map.fitBounds(mapBounds); + } + } if (self.map.getZoom() < self.minZoom) { self.map.setZoom(self.minZoom); } @@ -801,9 +812,12 @@ Ox.Map = function(options, self) { } } - function crossesDateline() { - var bounds = self.map.getBounds(); - return bounds.getSouthWest().lng() > bounds.getNorthEast().lng(); + function isEmpty(bounds) { + // Google's bounds.isEmpty() is not reliable + var southWest = bounds.getSouthWest(), + northEast = bounds.getNorthEast(); + return southWest.lat() == northEast.lat() + && southWest.lng() == northEast.lng(); } function mapChanged() { @@ -1396,6 +1410,9 @@ Ox.Map = function(options, self) { self.options.width = that.$element.width(); self.mapHeight = getMapHeight(); self.minZoom = getMinZoom(); + if (self.minZoom > self.map.getZoom()) { + self.map.setZoom(self.minZoom); + } self.$map.css({ height: self.mapHeight + 'px', width: self.options.width + 'px'