[OpenLayers-Commits] r11991 - in sandbox/ahocevar/google-ng: lib/OpenLayers lib/OpenLayers/Layer lib/OpenLayers/Tile tests tests/Layer tests/Tile

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Mon May 23 07:56:30 EDT 2011


Author: ahocevar
Date: 2011-05-23 04:56:30 -0700 (Mon, 23 May 2011)
New Revision: 11991

Added:
   sandbox/ahocevar/google-ng/tests/Layer/GoogleNG.html
   sandbox/ahocevar/google-ng/tests/Tile/Google.html
Modified:
   sandbox/ahocevar/google-ng/lib/OpenLayers/Layer/GoogleNG.js
   sandbox/ahocevar/google-ng/lib/OpenLayers/Tile.js
   sandbox/ahocevar/google-ng/lib/OpenLayers/Tile/Google.js
   sandbox/ahocevar/google-ng/tests/list-tests.html
Log:
adding tests; simplifying Tile.Google signature and making Tile.size optional

Modified: sandbox/ahocevar/google-ng/lib/OpenLayers/Layer/GoogleNG.js
===================================================================
--- sandbox/ahocevar/google-ng/lib/OpenLayers/Layer/GoogleNG.js	2011-05-23 05:58:02 UTC (rev 11990)
+++ sandbox/ahocevar/google-ng/lib/OpenLayers/Layer/GoogleNG.js	2011-05-23 11:56:30 UTC (rev 11991)
@@ -158,8 +158,9 @@
      * {<OpenLayers.Tile.Goolge>} The added OpenLayers.Tile.Google
      */
     addTile:function(bounds, position) {
-        return new OpenLayers.Tile.Google(this, position, bounds, null, 
-                                         this.tileSize, this.tileOptions);
+        return new OpenLayers.Tile.Google(
+            this, position, bounds, this.tileOptions
+        );
     },
     
     /**

Modified: sandbox/ahocevar/google-ng/lib/OpenLayers/Tile/Google.js
===================================================================
--- sandbox/ahocevar/google-ng/lib/OpenLayers/Tile/Google.js	2011-05-23 05:58:02 UTC (rev 11990)
+++ sandbox/ahocevar/google-ng/lib/OpenLayers/Tile/Google.js	2011-05-23 11:56:30 UTC (rev 11991)
@@ -26,11 +26,9 @@
      * Property: node
      * {DOMElement} The tile node from the MapType's getTile method
      */
-    node: false,
+    node: null,
         
-    /** TBD 3.0 -- remove 'url' from the list of parameters to the constructor.
-     *             there is no need for the base tile class to have a url.
-     * 
+    /** 
      * Constructor: OpenLayers.Tile.Google
      * Constructor for a new <OpenLayers.Tile.Google> instance.
      * 
@@ -38,12 +36,12 @@
      * layer - {<OpenLayers.Layer>} layer that the tile will go in.
      * position - {<OpenLayers.Pixel>}
      * bounds - {<OpenLayers.Bounds>}
-     * url - {<String>}
-     * size - {<OpenLayers.Size>}
      * options - {Object}
      */   
-    initialize: function(layer, position, bounds, url, size, options) {
-        OpenLayers.Tile.prototype.initialize.apply(this, arguments);
+    initialize: function(layer, position, bounds, options) {
+        OpenLayers.Tile.prototype.initialize.apply(this, [
+            layer, position, bounds, null, null, options
+        ]);
     },
 
     /** 
@@ -68,14 +66,14 @@
         if (obj == null) {
             obj = new OpenLayers.Tile.Google(this.layer, 
                                       this.position, 
-                                      this.bounds, 
-                                      this.url, 
-                                      this.size);
+                                      this.bounds);
         } 
         
         // catch any randomly tagged-on properties
         OpenLayers.Util.applyDefaults(obj, this);
         
+        obj.node = null;
+        
         return obj;
     },
 
@@ -109,6 +107,9 @@
             this.events.triggerEvent("loadstart");
 
             this.layer.div.appendChild(this.node);
+            
+            // We only modify what we need to - we expect the size to be set
+            // by getTile, and we have a test that will fail if this changes.
             OpenLayers.Util.modifyDOMElement(
                 this.node, null, this.position, null, "absolute"
             );  

Modified: sandbox/ahocevar/google-ng/lib/OpenLayers/Tile.js
===================================================================
--- sandbox/ahocevar/google-ng/lib/OpenLayers/Tile.js	2011-05-23 05:58:02 UTC (rev 11990)
+++ sandbox/ahocevar/google-ng/lib/OpenLayers/Tile.js	2011-05-23 11:56:30 UTC (rev 11991)
@@ -103,7 +103,9 @@
         this.position = position.clone();
         this.bounds = bounds.clone();
         this.url = url;
-        this.size = size.clone();
+        if (size) {
+            this.size = size.clone();
+        }
 
         //give the tile a unique id based on its BBOX.
         this.id = OpenLayers.Util.createUniqueID("Tile_");

Added: sandbox/ahocevar/google-ng/tests/Layer/GoogleNG.html
===================================================================
--- sandbox/ahocevar/google-ng/tests/Layer/GoogleNG.html	                        (rev 0)
+++ sandbox/ahocevar/google-ng/tests/Layer/GoogleNG.html	2011-05-23 11:56:30 UTC (rev 11991)
@@ -0,0 +1,88 @@
+<html>
+<head>
+  <script src="http://maps.google.com/maps/api/js?sensor=false&v=3.5"></script>
+  <script src="../OLLoader.js"></script>
+  <script type="text/javascript">
+    var map, layer; 
+
+    function test_constructor(t) {
+        t.plan(2);
+                       
+        layer = new OpenLayers.Layer.GoogleNG({type: "foo"});
+        t.ok(layer instanceof OpenLayers.Layer.GoogleNG, "returns OpenLayers.Layer.GoogleNG object" );
+        t.eq(layer.type, "foo", "Layer type set");
+    }
+    
+    function test_initLayer(t) {
+        t.plan(2);
+
+        map = new OpenLayers.Map("map");
+        layer = new OpenLayers.Layer.GoogleNG();
+        var extent;
+        map.addLayers([layer, new OpenLayers.Layer(null, {
+            moveTo: function(bounds, changed) {
+                extent = bounds;
+            }
+        })]);
+        map.zoomToMaxExtent();
+        
+        var map2 = new OpenLayers.Map("map2");
+        var layer2 = new OpenLayers.Layer.GoogleNG({
+            initLayer: function() {
+                // pretend we have a minZoom of 1
+                this.mapObject.mapTypes[this.type].minZoom = 1;
+                OpenLayers.Layer.GoogleNG.prototype.initLayer.apply(this, arguments);
+            }
+        });
+        var extent2;
+        map2.addLayers([layer2, new OpenLayers.Layer(null, {
+            moveTo: function(bounds, changed) {
+                extent2 = bounds;
+            }
+        })]);
+        map2.zoomToMaxExtent();
+        
+        t.delay_call(1, function() {
+            t.eq(extent.toBBOX(), map.getExtent().toBBOX(), "layer extent correct for base layer with minZoom == 0.");
+            map.destroy();
+
+            t.eq(extent2.toBBOX(), map2.getExtent().toBBOX(), "layer extent correct for base layer with minZoom == 1.");
+            map2.destroy();
+        });
+    }
+    
+    function test_attribution(t) {
+        t.plan(3);
+        
+        var log = [];
+        var map = new OpenLayers.Map("map");
+        layer = new OpenLayers.Layer.GoogleNG({type: google.maps.MapTypeId.HYBRID});
+        map.addLayer(layer);
+        map.zoomToMaxExtent();
+        
+        t.delay_call(1, function() {
+            t.ok(layer.attribution.indexOf('olGoogleAttribution hybrid') !== -1, "Attribution has the correct css class");
+            t.ok(layer.attribution.indexOf('?ll=0,0&z=0&t=h"') != -1, "maps.google.com link has correct parameters");
+            t.ok(layer.attribution.indexOf('&center=0,0&zoom=0&size=500x550&maptype=hybrid') != -1 , "Attribution has correct map data link");
+            map.destroy();
+        });
+    }
+
+    function test_clone(t) {
+        t.plan(2);
+        
+        var clone;
+        
+        layer = new OpenLayers.Layer.GoogleNG({type: google.maps.MapTypeId.HYBRID});
+        clone = layer.clone();
+        t.ok(clone instanceof OpenLayers.Layer.GoogleNG, "clone is a Layer.GoogleNG instance");
+        t.eq(clone.type, google.maps.MapTypeId.HYBRID, "with the correct map type");
+    }
+
+  </script>
+</head>
+<body>
+<div id="map" style="width:500px;height:550px"></div>
+<div id="map2" style="width:500px;height:550px"></div>
+</body>
+</html>

Added: sandbox/ahocevar/google-ng/tests/Tile/Google.html
===================================================================
--- sandbox/ahocevar/google-ng/tests/Tile/Google.html	                        (rev 0)
+++ sandbox/ahocevar/google-ng/tests/Tile/Google.html	2011-05-23 11:56:30 UTC (rev 11991)
@@ -0,0 +1,74 @@
+<html>
+<head>
+  <script src="http://maps.google.com/maps/api/js?sensor=false&v=3.5"></script>
+  <script src="../OLLoader.js"></script>
+  <script type="text/javascript">
+    var tile; 
+    var layer = new OpenLayers.Layer.GoogleNG(); 
+    var position = new OpenLayers.Pixel(20,30);
+    var bounds = new OpenLayers.Bounds(1,2,3,4);
+
+    
+    function test_constructor (t) {
+        t.plan( 4 );
+        
+        tile = new OpenLayers.Tile.Google(layer, position, bounds);
+    
+        t.ok( tile instanceof OpenLayers.Tile.Google, "new OpenLayers.Tile.Google returns Tile object" );
+        t.ok( tile.layer == layer, "tile.layer is set correctly");
+        t.ok( tile.position.equals(position), "tile.position is set correctly");
+        t.ok( tile.bounds.equals(bounds), "tile.bounds is set correctly");
+    }
+
+    function test_clone (t) {
+        t.plan( 5 );
+        
+        tile = new OpenLayers.Tile.Google(layer, position, bounds);
+        tile.node = document.createElement("div");
+        var clone = tile.clone();
+    
+        t.ok( clone instanceof OpenLayers.Tile.Google, "OpenLayers.Tile.Google.clone returns Tile.Google object" );
+        t.ok( clone.layer == layer, "clone.layer is set correctly");
+        t.ok( clone.position.equals(position), "clone.position is set correctly");
+        t.ok( clone.bounds.equals(bounds), "clone.bounds is set correctly");
+        t.ok( !clone.node, "node not cloned");
+    }
+    
+    function test_draw (t) {
+        t.plan( 5 );
+
+        var map = new OpenLayers.Map('map');
+        map.addLayer(layer);  
+
+        tile = new OpenLayers.Tile.Google(layer, position, bounds);
+
+        tile.events.register("loadstart", this, function() { 
+            t.ok(true, "loadstart triggered");
+        });
+        tile.events.register("loadend", this, function() { 
+            t.ok(true, "loadend triggered");
+        });
+
+        t.delay_call(1, function() {
+            //this should trigger a "loadstart" event
+            tile.draw();
+
+            t.ok( tile.node, "tile.draw creates a node");
+            // The two tests below will fail when getTile doesn't set the tile size
+            t.eq( tile.node.style.width, layer.tileSize.w+"px", "Image width is correct" );
+            t.eq( tile.node.style.height, layer.tileSize.h+"px", "Image height is correct" );
+        });       
+        t.delay_call(2, function() {
+            map.removeLayer(layer);
+            map.destroy();
+            /* wait until "loadend" fires */
+        });        
+        
+    }
+        
+  </script>
+</head>
+<body>
+<div id="map" style="height:550px;width:500px"></div>
+</body>
+</html>
\ No newline at end of file

Modified: sandbox/ahocevar/google-ng/tests/list-tests.html
===================================================================
--- sandbox/ahocevar/google-ng/tests/list-tests.html	2011-05-23 05:58:02 UTC (rev 11990)
+++ sandbox/ahocevar/google-ng/tests/list-tests.html	2011-05-23 11:56:30 UTC (rev 11991)
@@ -144,6 +144,7 @@
     <li>Layer/GML.html</li>
     <li>Layer/Google.html</li>
     <li>Layer/Google/v3.html</li>
+    <li>Layer/GoogleNG.html</li>
     <li>Layer/Grid.html</li>
     <li>Layer/HTTPRequest.html</li>
     <li>Layer/Image.html</li>
@@ -213,6 +214,7 @@
     <li>Symbolizer/Raster.html</li>
     <li>Symbolizer/Text.html</li>
     <li>Tile.html</li>
+    <li>Tile/Google.html</li>
     <li>Tile/Image.html</li>
     <li>Tile/Image/IFrame.html</li>
     <li>Tile/WFS.html</li>



More information about the Commits mailing list