Skip to content

Commit

Permalink
Fix for "OL is breaking Google API Terms", patch by pwr, r=me, (Close…
Browse files Browse the repository at this point in the history
…s #1858)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@9272 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
  • Loading branch information
crschmidt committed Apr 12, 2009
1 parent 29a2373 commit da3a4b2
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 17 deletions.
1 change: 1 addition & 0 deletions doc/authors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Philip Lindsay
Martijn van Oosterhout
David Overstrom
Corey Puffault
Peter William Robins
Gregers Rygg
Tim Schaub
Christopher Schmidt
Expand Down
7 changes: 6 additions & 1 deletion examples/google.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<head>
<title>OpenLayers Google Layer Example</title>
<link rel="stylesheet" href="../theme/default/style.css" type="text/css" />
<link rel="stylesheet" href="../theme/default/google.css" type="text/css" />
<link rel="stylesheet" href="style.css" type="text/css" />
<!-- this gmaps key generated for http://openlayers.org/dev/ -->
<script src='http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAjpkAC9ePGem0lIq5XcMiuhR_wWLPFku8Ix9i2SXYRVK3e45q1BQUd_beF8dtzKET_EteAjPdGDwqpQ'></script>
Expand Down Expand Up @@ -49,10 +50,14 @@ <h1 id="title">Google Layer Example</h1>
<div id="map" class="smallmap"></div>

<div id="docs">
<p>
For best performance, you must be using a version of the Google Maps
API which is v2.93 or higher. In order to use this version of the API,
it is best to simply set your application to use the string "v=2" in
the request, rather than tying your application to an explicit version.
the request, rather than tying your application to an explicit version.</p>
<p>
In order to position the Google attribution div in the default ocation,
you must include the extra theme/default/google.css stylesheet.</p>
</div>
</body>
</html>
75 changes: 59 additions & 16 deletions lib/OpenLayers/Layer/Google.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,18 @@ OpenLayers.Layer.Google = OpenLayers.Class(
*/
dragObject: null,

/**
* Property: termsOfUse
* {DOMElement} Div for Google's copyright and terms of use link
*/
termsOfUse: null,

/**
* Property: poweredBy
* {DOMElement} Div for Google's powered by logo and link
*/
poweredBy: null,

/**
* Constructor: OpenLayers.Layer.Google
*
Expand Down Expand Up @@ -122,22 +134,32 @@ OpenLayers.Layer.Google = OpenLayers.Class(
this.dragPanMapObject = null;
}


// move the ToS and branding stuff up to the pane
// thanks a *mil* Erik for thinking of this
var termsOfUse = this.div.lastChild;
this.div.removeChild(termsOfUse);
this.pane.appendChild(termsOfUse);
termsOfUse.className = "olLayerGoogleCopyright";
termsOfUse.style.right = "";
termsOfUse.style.bottom = "";

var poweredBy = this.div.lastChild;
this.div.removeChild(poweredBy);
this.pane.appendChild(poweredBy);
poweredBy.className = "olLayerGooglePoweredBy gmnoprint";
poweredBy.style.left = "";
poweredBy.style.bottom = "";
// move the ToS and branding stuff up to the container div
this.termsOfUse = this.div.lastChild;
this.div.removeChild(this.termsOfUse);
if (this.isFixed) {
this.map.viewPortDiv.appendChild(this.termsOfUse);
} else {
this.map.layerContainerDiv.appendChild(this.termsOfUse);
}
this.termsOfUse.style.zIndex = "1100";
this.termsOfUse.style.display = this.div.style.display;
this.termsOfUse.style.right = "";
this.termsOfUse.style.bottom = "";
this.termsOfUse.className = "olLayerGoogleCopyright";

this.poweredBy = this.div.lastChild;
this.div.removeChild(this.poweredBy);
if (this.isFixed) {
this.map.viewPortDiv.appendChild(this.poweredBy);
} else {
this.map.layerContainerDiv.appendChild(this.poweredBy);
}
this.poweredBy.style.zIndex = "1100";
this.poweredBy.style.display = this.div.style.display;
this.poweredBy.style.right = "";
this.poweredBy.style.bottom = "";
this.poweredBy.className = "olLayerGooglePoweredBy gmnoprint";

} catch (e) {
OpenLayers.Console.error(e);
Expand Down Expand Up @@ -219,6 +241,27 @@ OpenLayers.Layer.Google = OpenLayers.Class(
display: function(display) {
OpenLayers.Layer.EventPane.prototype.display.apply(this, arguments);
this.checkResize();
this.termsOfUse.style.display = this.div.style.display;
this.poweredBy.style.display = this.div.style.display;
},

/**
* APIMethod: removeMap
* On being removed from the map, also remove termsOfUse and poweredBy divs
*
* Parameters:
* map - {<OpenLayers.Map>}
*/
removeMap: function(map) {
if (this.termsOfUse && this.termsOfUse.parentNode) {
this.termsOfUse.parentNode.removeChild(this.termsOfUse);
this.termsOfUse = null;
}
if (this.poweredBy && this.poweredBy.parentNode) {
this.poweredBy.parentNode.removeChild(this.poweredBy);
this.poweredBy = null;
}
OpenLayers.Layer.EventPane.prototype.removeMap.apply(this, arguments);
},

/**
Expand Down
9 changes: 9 additions & 0 deletions theme/default/google.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.olLayerGoogleCopyright {
right: 3px;
bottom: 2px;
}
.olLayerGooglePoweredBy {
left: 2px;
bottom: 2px;
}

0 comments on commit da3a4b2

Please sign in to comment.