Adding a getMinZoom API method.
This can be used by zoom slider controls, e.g. the GeoExt.ZoomSlider. Note that adjustZoom now also respects the map's fractionalZoom setting.
This commit is contained in:
@@ -194,10 +194,7 @@ OpenLayers.Control.PanZoomBar = OpenLayers.Class(OpenLayers.Control.PanZoom, {
|
|||||||
_addZoomBar:function(centered) {
|
_addZoomBar:function(centered) {
|
||||||
var imgLocation = OpenLayers.Util.getImageLocation("slider.png");
|
var imgLocation = OpenLayers.Util.getImageLocation("slider.png");
|
||||||
var id = this.id + "_" + this.map.id;
|
var id = this.id + "_" + this.map.id;
|
||||||
var minZoom = 0;
|
var minZoom = this.map.getMinZoom();
|
||||||
if (this.map.baseLayer && this.map.baseLayer.wrapDateLine) {
|
|
||||||
minZoom = this.map.adjustZoom(0);
|
|
||||||
}
|
|
||||||
var zoomsToEnd = this.map.getNumZoomLevels() - 1 - this.map.getZoom();
|
var zoomsToEnd = this.map.getNumZoomLevels() - 1 - this.map.getZoom();
|
||||||
var slider = OpenLayers.Util.createAlphaImageDiv(id,
|
var slider = OpenLayers.Util.createAlphaImageDiv(id,
|
||||||
centered.add(-1, zoomsToEnd * this.zoomStopHeight),
|
centered.add(-1, zoomsToEnd * this.zoomStopHeight),
|
||||||
|
|||||||
+37
-15
@@ -1786,18 +1786,42 @@ OpenLayers.Map = OpenLayers.Class({
|
|||||||
* <baseLayer>'s maxExtent.
|
* <baseLayer>'s maxExtent.
|
||||||
*/
|
*/
|
||||||
adjustZoom: function(zoom) {
|
adjustZoom: function(zoom) {
|
||||||
var resolution, resolutions = this.baseLayer.resolutions,
|
if (this.baseLayer && this.baseLayer.wrapDateLine) {
|
||||||
maxResolution = this.getMaxExtent().getWidth() / this.size.w;
|
var resolution, resolutions = this.baseLayer.resolutions,
|
||||||
if (this.getResolutionForZoom(zoom) > maxResolution) {
|
maxResolution = this.getMaxExtent().getWidth() / this.size.w;
|
||||||
for (var i=zoom|0, ii=resolutions.length; i<ii; ++i) {
|
if (this.getResolutionForZoom(zoom) > maxResolution) {
|
||||||
if (resolutions[i] <= maxResolution) {
|
if (this.fractionalZoom) {
|
||||||
zoom = i;
|
zoom = this.getZoomForResolution(maxResolution);
|
||||||
break;
|
} else {
|
||||||
}
|
for (var i=zoom|0, ii=resolutions.length; i<ii; ++i) {
|
||||||
|
if (resolutions[i] <= maxResolution) {
|
||||||
|
zoom = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return zoom;
|
return zoom;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APIMethod: getMinZoom
|
||||||
|
* Returns the minimum zoom level for the current map view. If the base
|
||||||
|
* layer is configured with <wrapDateLine> set to true, this will be the
|
||||||
|
* first zoom level that shows no more than one world width in the current
|
||||||
|
* map viewport. Components that rely on this value (e.g. zoom sliders)
|
||||||
|
* should also listen to the map's "updatesize" event and call this method
|
||||||
|
* in the "updatesize" listener.
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* {Number} Minimum zoom level that shows a map not wider than its
|
||||||
|
* <baseLayer>'s maxExtent. This is an Integer value, unless the map is
|
||||||
|
* configured with <fractionalZoom> set to true.
|
||||||
|
*/
|
||||||
|
getMinZoom: function() {
|
||||||
|
return this.adjustZoom(0);
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method: moveTo
|
* Method: moveTo
|
||||||
@@ -1820,13 +1844,11 @@ OpenLayers.Map = OpenLayers.Class({
|
|||||||
zoom = Math.round(zoom);
|
zoom = Math.round(zoom);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.baseLayer.wrapDateLine) {
|
var requestedZoom = zoom;
|
||||||
var requestedZoom = zoom;
|
zoom = this.adjustZoom(zoom);
|
||||||
zoom = this.adjustZoom(zoom);
|
if (zoom !== requestedZoom) {
|
||||||
if (zoom !== requestedZoom) {
|
// zoom was adjusted, so keep old lonlat to avoid panning
|
||||||
// zoom was adjusted, so keep old lonlat to avoid panning
|
lonlat = this.getCenter();
|
||||||
lonlat = this.getCenter();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// dragging is false by default
|
// dragging is false by default
|
||||||
var dragging = options.dragging || this.dragging;
|
var dragging = options.dragging || this.dragging;
|
||||||
|
|||||||
Reference in New Issue
Block a user