fixing getOLZoomFromMapObjectZoom so it also works when the layer is not the baseLayer. r=bartvde,tschaub (see #3342)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@12105 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
ahocevar
2011-06-18 19:11:54 +00:00
parent 1ccf325285
commit 6248cdc94d
3 changed files with 94 additions and 1 deletions

View File

@@ -287,6 +287,11 @@ OpenLayers.Layer.FixedZoomLevels = OpenLayers.Class({
var zoom = null;
if (moZoom != null) {
zoom = moZoom - this.minZoomLevel;
if (this.map.baseLayer !== this) {
zoom = this.map.baseLayer.getZoomForResolution(
this.getResolutionForZoom(zoom)
)
}
}
return zoom;
},
@@ -306,6 +311,11 @@ OpenLayers.Layer.FixedZoomLevels = OpenLayers.Class({
var zoom = null;
if (olZoom != null) {
zoom = olZoom + this.minZoomLevel;
if (this.map.baseLayer !== this) {
zoom = this.getZoomForResolution(
this.map.baseLayer.getResolutionForZoom(zoom)
);
}
}
return zoom;
},

View File

@@ -82,6 +82,34 @@
t.eq( layer.resolutions[i], resolutions[i + minZoomLevel], "resolutions array at index " + i + " ok");
}
}
function test_getMapObjectZoomFromOLZoom(t) {
t.plan(4);
var map = new OpenLayers.Map("map", {allOverlays: true});
var xyz = new OpenLayers.Layer.XYZ("xyz", "${x}${y}${z}", {
sphericalMercator: true,
resolutions: [39135.7584765625, 19567.87923828125, 9783.939619140625]
});
var fixed = new (OpenLayers.Class(OpenLayers.Layer, OpenLayers.Layer.FixedZoomLevels, {
initialize: function() {
OpenLayers.Layer.prototype.initialize.apply(this, arguments);
}
}))("fixed", {
resolutions: [156543.03390625, 78271.516953125, 39135.7584765625, 19567.87923828125, 9783.939619140625],
minZoomLevel: 1
});
map.addLayers([xyz, fixed]);
map.setCenter(new OpenLayers.LonLat(0, 0), 2);
// map.getZoom() returns 2
t.eq(fixed.getMapObjectZoomFromOLZoom(map.getZoom()), 4, "correct return value from getMapObjectZoomFromOLZoom");
t.eq(fixed.getOLZoomFromMapObjectZoom(4), map.getZoom() - fixed.minZoomLevel, "correct return value from getOLZoomFromMapObjectZoom");
map.setBaseLayer(fixed);
// map.getZoom() returns 4 now
t.eq(fixed.getMapObjectZoomFromOLZoom(map.getZoom()), 5, "correct return value from getMapObjectZoomFromOLZoom");
t.eq(fixed.getOLZoomFromMapObjectZoom(5), map.getZoom(), "correct return value from getOLZoomFromMapObjectZoom");
}
function p_createLayer(layer, mapOptions, layerOptions) {
@@ -104,6 +132,6 @@
</script>
</head>
<body>
<div id="map"></div>
<div id="map" style="width:256px;height:256px"></div>
</body>
</html>

View File

@@ -0,0 +1,55 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
<meta name="apple-mobile-web-app-capable" content="yes">
<title>OpenLayers Mixed allOverlays Test</title>
<link rel="stylesheet" href="../../theme/default/style.css" type="text/css">
<link rel="stylesheet" href="../../theme/default/google.css" type="text/css">
<link rel="stylesheet" href="../../examples/style.css" type="text/css">
<script src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript">
var map;
function init() {
map = new OpenLayers.Map('map', {allOverlays: true});
map.addControl(new OpenLayers.Control.LayerSwitcher());
var osm = new OpenLayers.Layer.OSM("OSM", null, {
visibility: false,
maxResolution: 78271.516953125,
serverResolutions: [156543.03390625, 78271.516953125, 39135.7584765625, 19567.87923828125, 9783.939619140625, 4891.9698095703125, 2445.9849047851562, 1222.9924523925781, 611.4962261962891, 305.74811309814453, 152.87405654907226, 76.43702827453613, 38.218514137268066, 19.109257068634033, 9.554628534317017, 4.777314267158508, 2.388657133579254, 1.194328566789627, 0.5971642833948135]
});
var google = new OpenLayers.Layer.Google("Google");
var wms = new OpenLayers.Layer.WMS("WMS",
"http://vmap0.tiles.osgeo.org/wms/vmap0",
{layers: 'basic'}, {
opacity: .5,
maxExtent: new OpenLayers.Bounds(
-20037508.34, -20037508.34, 20037508.34, 20037508.34
),
wrapDateLine: true
}
);
map.addLayers([osm, google, wms]);
map.setCenter(new OpenLayers.LonLat(0, 0), 3);
}
</script>
</head>
<body onload="init()">
<h1 id="title">Mixed allOverlays Test</h1>
<div id="map" class="smallmap"></div>
<div id="docs">
<p>
The map image aboved should show a Google layer and an opaque WMS
layer. They both should align (look at the border of West Africa)
</p>
</div>
</body>
</html>