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.
This commit is contained in:
ahocevar
2013-04-04 11:40:21 +02:00
parent aaabdbc803
commit f0ef4728d8

View File

@@ -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() {
container.style.display = '';
cache.googleControl.appendChild(map.viewPortDiv);
cache.rendered = true;
});
} else {
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;
container.style.display = 'none';
}
}
},