From 42fedc4d69f937b9cd2aa4fafc6114c5565e1fb9 Mon Sep 17 00:00:00 2001 From: ahocevar Date: Wed, 18 Aug 2010 16:43:45 +0000 Subject: [PATCH] Make it safer to extend the Google Layer by not invoking Map.getLayersByClass. Also removed an unused variable. tschaub made one more change to check for other Google layers only if we have a cache already - otherwise the whole logic would not apply anyway. Thanks iacovlev_pavel for bringing this up on IRC. p+r=tschaub,me (closes #2793) git-svn-id: http://svn.openlayers.org/trunk/openlayers@10632 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Layer/Google/v3.js | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/lib/OpenLayers/Layer/Google/v3.js b/lib/OpenLayers/Layer/Google/v3.js index 9a49aefb39..fa9d64f960 100644 --- a/lib/OpenLayers/Layer/Google/v3.js +++ b/lib/OpenLayers/Layer/Google/v3.js @@ -181,22 +181,20 @@ OpenLayers.Layer.Google.v3 = { * visible - {Boolean} Display the GMap elements. */ setGMapVisibility: function(visible) { - var type = this.type; - - var layers = this.map.getLayersByClass("OpenLayers.Layer.Google"); - var index = OpenLayers.Util.indexOf(layers, this); - var layer; - for (var i=layers.length-1; i>=0; --i) { - layer = layers[i]; - if (layer.visibility === true && layer.inRange === true) { - type = layer.type; - visible = true; - break; - } - } - var cache = OpenLayers.Layer.Google.cache[this.map.id]; if (cache) { + var type = this.type; + var layers = this.map.layers; + var layer; + for (var i=layers.length-1; i>=0; --i) { + layer = layers[i]; + if (layer instanceof OpenLayers.Layer.Google && + layer.visibility === true && layer.inRange === true) { + type = layer.type; + visible = true; + break; + } + } var container = this.mapObject.getDiv(); if (visible === true) { this.mapObject.setMapTypeId(type);