From 517282baa4b528bc1bb4af64529dc8209e5aa1a7 Mon Sep 17 00:00:00 2001 From: euzuro Date: Fri, 7 Jul 2006 14:50:46 +0000 Subject: [PATCH] if gmaps is unable to load, well then we will show the user some help git-svn-id: http://svn.openlayers.org/trunk/openlayers@912 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Layer/Google.js | 111 ++++++++++++++++++++++++--------- 1 file changed, 83 insertions(+), 28 deletions(-) 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 += "