From 09a858559ba67b46d52778b22452175986584c7c Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sat, 20 Feb 2010 20:14:53 +0000 Subject: [PATCH] Adding clone method to the Google layer. r=ahocevar (closes #2473) git-svn-id: http://svn.openlayers.org/trunk/openlayers@10081 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Layer/Google.js | 29 +++++++++++++++++++++++++---- tests/Layer/Google.html | 23 +++++++++++++++++++++++ 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/lib/OpenLayers/Layer/Google.js b/lib/OpenLayers/Layer/Google.js index b7b8443cd7..9dd8b01152 100644 --- a/lib/OpenLayers/Layer/Google.js +++ b/lib/OpenLayers/Layer/Google.js @@ -117,6 +117,25 @@ OpenLayers.Layer.Google = OpenLayers.Class( } }, + /** + * Method: clone + * Create a clone of this layer + * + * Returns: + * {} An exact clone of this layer + */ + clone: function() { + /** + * This method isn't intended to be called by a subclass and it + * doesn't call the same method on the superclass. We don't call + * the super's clone because we don't want properties that are set + * on this layer after initialize (i.e. this.mapObject etc.). + */ + return new OpenLayers.Layer.Google( + this.name, this.getOptions() + ); + }, + /** * Method: loadMapObject * Load the GMap and register appropriate event listeners. If we can't @@ -294,10 +313,12 @@ OpenLayers.Layer.Google = OpenLayers.Class( * deletes the mapObject reference before removing this layer from * the map. */ - this.setGMapVisibility(false); - var cache = OpenLayers.Layer.Google.cache[this.map.id]; - if (cache && cache.count <= 1) { - this.removeGMapElements(false); + if (this.map) { + this.setGMapVisibility(false); + var cache = OpenLayers.Layer.Google.cache[this.map.id]; + if (cache && cache.count <= 1) { + this.removeGMapElements(false); + } } OpenLayers.Layer.EventPane.prototype.destroy.apply(this, arguments); }, diff --git a/tests/Layer/Google.html b/tests/Layer/Google.html index 1750189259..143a8f3e90 100644 --- a/tests/Layer/Google.html +++ b/tests/Layer/Google.html @@ -39,6 +39,29 @@ window.location.host); } } + + function test_clone(t) { + if (validkey) { + t.plan(2); + var layer, clone; + + // test default layer + layer = new OpenLayers.Layer.Google(); + clone = layer.clone(); + t.ok(clone instanceof OpenLayers.Layer.Google, "[default] good instance"); + + layer.destroy(); + clone.destroy(); + + // test with alt type + layer = new OpenLayers.Layer.Google(null, {type: G_SATELLITE_MAP}); + clone = layer.clone(); + t.ok(clone.type === G_SATELLITE_MAP, "[sat] correct type"); + + layer.destroy(); + clone.destroy(); + } + } function test_Layer_Google_isBaseLayer (t) { if(validkey) {