From f0ef4728d8bc711d5840198507274bb720397a88 Mon Sep 17 00:00:00 2001 From: ahocevar Date: Thu, 4 Apr 2013 11:40:21 +0200 Subject: [PATCH] Simplifying layer visibility handling Instead of adding and removing the Google container, we just toggle style.display. This also removes the unused rendered and displayed properties of the cache. --- lib/OpenLayers/Layer/Google/v3.js | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/lib/OpenLayers/Layer/Google/v3.js b/lib/OpenLayers/Layer/Google/v3.js index a70c7bbf13..10c3e856c5 100644 --- a/lib/OpenLayers/Layer/Google/v3.js +++ b/lib/OpenLayers/Layer/Google/v3.js @@ -92,6 +92,7 @@ OpenLayers.Layer.Google.v3 = { googleControl.style.width = '100%'; googleControl.style.height = '100%'; mapObject.controls[google.maps.ControlPosition.TOP_LEFT].push(googleControl); + this.map.div.appendChild(container); // cache elements for use by any other google layers added to // this same map @@ -140,26 +141,13 @@ OpenLayers.Layer.Google.v3 = { } var container = this.mapObject.getDiv(); if (visible === true) { - if (container.parentNode !== map.div) { - map.div.appendChild(container); - if (!cache.rendered) { - google.maps.event.addListenerOnce(this.mapObject, 'tilesloaded', function() { - cache.googleControl.appendChild(map.viewPortDiv); - cache.rendered = true; - }); - } else { - cache.googleControl.appendChild(map.viewPortDiv); - } - google.maps.event.trigger(this.mapObject, 'resize'); - } + container.style.display = ''; + cache.googleControl.appendChild(map.viewPortDiv); + google.maps.event.trigger(this.mapObject, 'resize'); this.mapObject.setMapTypeId(type); - cache.displayed = this.id; } else { - if (cache.googleControl.hasChildNodes()) { - map.div.appendChild(map.viewPortDiv); - map.div.removeChild(container); - } - delete cache.displayed; + map.div.appendChild(map.viewPortDiv); + container.style.display = 'none'; } } },