diff --git a/lib/OpenLayers/Layer/Google.js b/lib/OpenLayers/Layer/Google.js
index 065801b00f..f2f4ef0f06 100644
--- a/lib/OpenLayers/Layer/Google.js
+++ b/lib/OpenLayers/Layer/Google.js
@@ -119,40 +119,95 @@ OpenLayers.Layer.Google.prototype = Object.extend( new OpenLayers.Layer(), {
*/
loadGMap:function() {
- //test if the gmaps library has been loaded
+ //has gmaps library has been loaded?
var gmapsLoaded = (typeof GMap2) != "undefined";
- if (gmapsLoaded) {
-
+ if (!gmapsLoaded) {
+ this.loadWarningMessage();
+ } else {
+
// create GMap, hide nav controls
this.gmap = new GMap2(this.div);
-
- // this causes the GMap to set itself to Map's center/zoom
- this.moveTo();
-
- // catch pans and zooms from GMap
- GEvent.addListener(this.gmap,
- "moveend",
- this.catchPanZoom.bindAsEventListener(this));
-
-
- // attach to the drag start and end and weŽll set a flag so that
- // we dont get recursivity. this is because when we call setCenter(),
- // it calls moveTo() on all layers
- GEvent.addListener(this.gmap,
- "dragstart",
- this.dragStart.bindAsEventListener(this));
-
- GEvent.addListener(this.gmap,
- "dragend",
- this.dragEnd.bindAsEventListener(this));
-
- // catch pans and zooms from GMap
- GEvent.addListener(this.gmap,
- "drag",
- this.catchPanZoom.bindAsEventListener(this));
+
+ if (this.gmap == null) {
+ this.loadWarningMessage();
+ } else {
+
+ // this causes the GMap to set itself to Map's center/zoom
+ this.moveTo();
+
+ // catch pans and zooms from GMap
+ GEvent.addListener(this.gmap,
+ "moveend",
+ this.catchPanZoom.bindAsEventListener(this));
+
+
+ // attach to the drag start and end and weŽll set a flag so that
+ // we dont get recursivity. this is because when we call setCenter(),
+ // it calls moveTo() on all layers
+ GEvent.addListener(this.gmap,
+ "dragstart",
+ this.dragStart.bindAsEventListener(this));
+
+ GEvent.addListener(this.gmap,
+ "dragend",
+ this.dragEnd.bindAsEventListener(this));
+
+ // catch pans and zooms from GMap
+ GEvent.addListener(this.gmap,
+ "drag",
+ this.catchPanZoom.bindAsEventListener(this));
+ }
}
},
+ /** If we can't load the GMap, then display an error message to the
+ * user and tell them where to go for help.
+ */
+ loadWarningMessage:function() {
+
+ this.div.style.backgroundColor = "red";
+
+ var html = "";
+ html += "The Google Layer was unable to load correctly.
";
+ html += "
";
+ html += "Most likely, this is because the Google Maps library";
+ html += " script was either not included, or does not contain the";
+ html += " correct API key for your site.
";
+ html += "
";
+ html += "If you wish to use a GMaps Layer with OpenLayers, you";
+ html += " must include the gmaps script library in your HTML";
+ html += " file, just before including OpenLayers.js.
";
+ html += "
";
+ html += "For help getting this working correctly, ";
+ html += "";
+ html += "click here";
+ html += "";
+
+ var viewSize = this.map.getSize();
+
+ msgW = Math.min(viewSize.w, 300);
+ msgH = Math.min(viewSize.h, 200);
+ var size = new OpenLayers.Size(msgW, msgH);
+
+ var centerPx = new OpenLayers.Pixel(viewSize.w/2, viewSize.h/2);
+
+ var topLeft = centerPx.add(-size.w/2, -size.h/2);
+
+ var div = OpenLayers.Util.createDiv("gmapsWarning",
+ topLeft,
+ size,
+ null,
+ null,
+ null,
+ "auto");
+
+ div.style.backgroundColor = "yellow";
+
+ div.innerHTML = html;
+ this.div.appendChild(div);
+ },
+
/**
* @private
*/