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:
@@ -119,40 +119,95 @@ OpenLayers.Layer.Google.prototype = Object.extend( new OpenLayers.Layer(), {
|
|||||||
*/
|
*/
|
||||||
loadGMap:function() {
|
loadGMap:function() {
|
||||||
|
|
||||||
//test if the gmaps library has been loaded
|
//has gmaps library has been loaded?
|
||||||
var gmapsLoaded = (typeof GMap2) != "undefined";
|
var gmapsLoaded = (typeof GMap2) != "undefined";
|
||||||
if (gmapsLoaded) {
|
if (!gmapsLoaded) {
|
||||||
|
this.loadWarningMessage();
|
||||||
|
} else {
|
||||||
|
|
||||||
// create GMap, hide nav controls
|
// create GMap, hide nav controls
|
||||||
this.gmap = new GMap2(this.div);
|
this.gmap = new GMap2(this.div);
|
||||||
|
|
||||||
// this causes the GMap to set itself to Map's center/zoom
|
if (this.gmap == null) {
|
||||||
this.moveTo();
|
this.loadWarningMessage();
|
||||||
|
} else {
|
||||||
// catch pans and zooms from GMap
|
|
||||||
GEvent.addListener(this.gmap,
|
// this causes the GMap to set itself to Map's center/zoom
|
||||||
"moveend",
|
this.moveTo();
|
||||||
this.catchPanZoom.bindAsEventListener(this));
|
|
||||||
|
// catch pans and zooms from GMap
|
||||||
|
GEvent.addListener(this.gmap,
|
||||||
// attach to the drag start and end and we´ll set a flag so that
|
"moveend",
|
||||||
// we dont get recursivity. this is because when we call setCenter(),
|
this.catchPanZoom.bindAsEventListener(this));
|
||||||
// it calls moveTo() on all layers
|
|
||||||
GEvent.addListener(this.gmap,
|
|
||||||
"dragstart",
|
// attach to the drag start and end and we´ll set a flag so that
|
||||||
this.dragStart.bindAsEventListener(this));
|
// we dont get recursivity. this is because when we call setCenter(),
|
||||||
|
// it calls moveTo() on all layers
|
||||||
GEvent.addListener(this.gmap,
|
GEvent.addListener(this.gmap,
|
||||||
"dragend",
|
"dragstart",
|
||||||
this.dragEnd.bindAsEventListener(this));
|
this.dragStart.bindAsEventListener(this));
|
||||||
|
|
||||||
// catch pans and zooms from GMap
|
GEvent.addListener(this.gmap,
|
||||||
GEvent.addListener(this.gmap,
|
"dragend",
|
||||||
"drag",
|
this.dragEnd.bindAsEventListener(this));
|
||||||
this.catchPanZoom.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
|
* @private
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user