Only create Google control once
The control div is now an empty container that we can always append to and remove from without having to worry about GMaps changing styles on it. It also makes sure that the control is appended before Google's own attribution control, so the "Report a map error" link will always be clickable.
This commit is contained in:
@@ -88,10 +88,15 @@ OpenLayers.Layer.Google.v3 = {
|
||||
scrollwheel: false,
|
||||
streetViewControl: false
|
||||
});
|
||||
var googleControl = document.createElement('div');
|
||||
googleControl.style.width = '100%';
|
||||
googleControl.style.height = '100%';
|
||||
mapObject.controls[google.maps.ControlPosition.TOP_LEFT].push(googleControl);
|
||||
|
||||
// cache elements for use by any other google layers added to
|
||||
// this same map
|
||||
cache = {
|
||||
googleControl: googleControl,
|
||||
mapObject: mapObject,
|
||||
count: 1
|
||||
};
|
||||
@@ -134,32 +139,17 @@ OpenLayers.Layer.Google.v3 = {
|
||||
}
|
||||
var container = this.mapObject.getDiv();
|
||||
if (visible === true) {
|
||||
if (!cache.gmapHasViewport) {
|
||||
this.map.div.removeChild(this.map.viewPortDiv);
|
||||
this.mapObject.controls[google.maps.ControlPosition.TOP_LEFT].push(this.map.viewPortDiv);
|
||||
cache.gmapHasViewport = true;
|
||||
if (!cache.googleControl.hasChildNodes()) {
|
||||
cache.googleControl.appendChild(this.map.viewPortDiv);
|
||||
this.map.div.appendChild(container);
|
||||
google.maps.event.trigger(this.mapObject, 'resize');
|
||||
}
|
||||
this.mapObject.setMapTypeId(type);
|
||||
cache.displayed = this.id;
|
||||
} else {
|
||||
if (cache.gmapHasViewport) {
|
||||
if (cache.googleControl.hasChildNodes()) {
|
||||
this.map.div.removeChild(container);
|
||||
this.map.div.appendChild(
|
||||
this.mapObject.controls[google.maps.ControlPosition.TOP_LEFT].pop()
|
||||
);
|
||||
delete cache.gmapHasViewport;
|
||||
|
||||
// restore all styles of the viewPortDiv, in case GMaps
|
||||
// changes any. At the time of writing this, it definitely
|
||||
// changes the position.
|
||||
OpenLayers.Util.modifyDOMElement(
|
||||
this.map.viewPortDiv, null, null, null, 'relative',
|
||||
null, 'hidden'
|
||||
);
|
||||
this.map.viewPortDiv.style.width = "100%";
|
||||
this.map.viewPortDiv.style.height = "100%";
|
||||
this.map.div.appendChild(this.map.viewPortDiv);
|
||||
}
|
||||
delete cache.displayed;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user