map fixes (when loaded without places, zoom out; when resizing causes the minimum zoom to be larger than the current zoom, zoom out)

This commit is contained in:
rlx 2011-10-29 11:04:21 +00:00
parent 4c641db867
commit 45ad8ee468

View file

@ -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'