[OpenLayers-Commits] r12105 - in trunk/openlayers: lib/OpenLayers/Layer tests/Layer tests/manual

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Sat Jun 18 15:11:55 EDT 2011


Author: ahocevar
Date: 2011-06-18 12:11:54 -0700 (Sat, 18 Jun 2011)
New Revision: 12105

Added:
   trunk/openlayers/tests/manual/alloverlays-mixed.html
Modified:
   trunk/openlayers/lib/OpenLayers/Layer/FixedZoomLevels.js
   trunk/openlayers/tests/Layer/FixedZoomLevels.html
Log:
fixing getOLZoomFromMapObjectZoom so it also works when the layer is not the baseLayer. r=bartvde,tschaub (see #3342)

Modified: trunk/openlayers/lib/OpenLayers/Layer/FixedZoomLevels.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Layer/FixedZoomLevels.js	2011-06-17 21:10:15 UTC (rev 12104)
+++ trunk/openlayers/lib/OpenLayers/Layer/FixedZoomLevels.js	2011-06-18 19:11:54 UTC (rev 12105)
@@ -287,6 +287,11 @@
         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 @@
         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;
     },

Modified: trunk/openlayers/tests/Layer/FixedZoomLevels.html
===================================================================
--- trunk/openlayers/tests/Layer/FixedZoomLevels.html	2011-06-17 21:10:15 UTC (rev 12104)
+++ trunk/openlayers/tests/Layer/FixedZoomLevels.html	2011-06-18 19:11:54 UTC (rev 12105)
@@ -82,7 +82,35 @@
             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) {
 
         layer.map = mapOptions || {};
@@ -104,6 +132,6 @@
   </script>
 </head>
 <body>
-  <div id="map"></div>
+  <div id="map" style="width:256px;height:256px"></div>
 </body>
 </html>

Added: trunk/openlayers/tests/manual/alloverlays-mixed.html
===================================================================
--- trunk/openlayers/tests/manual/alloverlays-mixed.html	                        (rev 0)
+++ trunk/openlayers/tests/manual/alloverlays-mixed.html	2011-06-18 19:11:54 UTC (rev 12105)
@@ -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>



More information about the Commits mailing list