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
This commit is contained in:
euzuro
2006-07-07 14:50:46 +00:00
parent 2897834520
commit 517282baa4

View File

@@ -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<77>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<77>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.<br>";
html += "<br>";
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.<br>";
html += "<br>";
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.<br>";
html += "<br>";
html += "For help getting this working correctly, ";
html += "<a href='http://trac.openlayers.org/wiki/Google' "
html += "target='_blank'>";
html += "click here";
html += "</a>";
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
*/