remove document.write() call that loaded the gmaps script in google.js. from now on, the user is responsible for adding that script tag to his/her page. Add a test to make sure gmaps code base is loaded before trying to initialize new gmap2. update isBaseLayer() to return true only if gmaps is correctly loaded. finally, protect all methods if this.gmap is null, do nothing. update OpenLayers.js to now include Google.js and library.cfg to not exclude it.
git-svn-id: http://svn.openlayers.org/trunk/openlayers@910 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -7,7 +7,6 @@ OpenLayers.js
|
|||||||
[last]
|
[last]
|
||||||
|
|
||||||
[exclude]
|
[exclude]
|
||||||
OpenLayers/Layer/Google.js
|
|
||||||
OpenLayers/Layer/Yahoo.js
|
OpenLayers/Layer/Yahoo.js
|
||||||
OpenLayers/Layer/VirtualEarth.js
|
OpenLayers/Layer/VirtualEarth.js
|
||||||
OpenLayers/Layer/WMS/Untiled.js
|
OpenLayers/Layer/WMS/Untiled.js
|
||||||
|
|||||||
+1
-1
@@ -64,7 +64,7 @@ if (typeof(_OPENLAYERS_SFL_) == "undefined") {
|
|||||||
"OpenLayers/Feature/WFS.js",
|
"OpenLayers/Feature/WFS.js",
|
||||||
"OpenLayers/Tile/Image.js",
|
"OpenLayers/Tile/Image.js",
|
||||||
"OpenLayers/Tile/WFS.js",
|
"OpenLayers/Tile/WFS.js",
|
||||||
// "OpenLayers/Layer/Google.js",
|
"OpenLayers/Layer/Google.js",
|
||||||
// "OpenLayers/Layer/VirtualEarth.js",
|
// "OpenLayers/Layer/VirtualEarth.js",
|
||||||
// "OpenLayers/Layer/Yahoo.js",
|
// "OpenLayers/Layer/Yahoo.js",
|
||||||
"OpenLayers/Layer/HTTPRequest.js",
|
"OpenLayers/Layer/HTTPRequest.js",
|
||||||
|
|||||||
@@ -3,10 +3,6 @@
|
|||||||
* text of the license. */
|
* text of the license. */
|
||||||
// @require: OpenLayers/Layer.js
|
// @require: OpenLayers/Layer.js
|
||||||
|
|
||||||
// load Google map control script
|
|
||||||
// this key was generated for: http://openlayers.python-hosting.com/testing/euzuro/
|
|
||||||
document.write("<script src='http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAmQ3udCHPQVB_9T_edFZ7YRRRlP-tOiFgaSzksg_0w1dphL9c5BTfdJMKT91b0UJGibNcWEM0Q5-O1w'></script>");
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class
|
* @class
|
||||||
*/
|
*/
|
||||||
@@ -58,7 +54,7 @@ OpenLayers.Layer.Google.prototype = Object.extend( new OpenLayers.Layer(), {
|
|||||||
* @type Boolean
|
* @type Boolean
|
||||||
*/
|
*/
|
||||||
isBaseLayer: function() {
|
isBaseLayer: function() {
|
||||||
return true;
|
return (this.gmap != null);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -95,6 +91,10 @@ OpenLayers.Layer.Google.prototype = Object.extend( new OpenLayers.Layer(), {
|
|||||||
*/
|
*/
|
||||||
loadGMap:function() {
|
loadGMap:function() {
|
||||||
|
|
||||||
|
//test if the gmaps library has been loaded
|
||||||
|
var gmapsLoaded = (typeof GMap2) != "undefined";
|
||||||
|
if (gmapsLoaded) {
|
||||||
|
|
||||||
// create GMap, hide nav controls
|
// create GMap, hide nav controls
|
||||||
this.gmap = new GMap2(this.div);
|
this.gmap = new GMap2(this.div);
|
||||||
|
|
||||||
@@ -122,7 +122,7 @@ OpenLayers.Layer.Google.prototype = Object.extend( new OpenLayers.Layer(), {
|
|||||||
GEvent.addListener(this.gmap,
|
GEvent.addListener(this.gmap,
|
||||||
"drag",
|
"drag",
|
||||||
this.catchPanZoom.bindAsEventListener(this));
|
this.catchPanZoom.bindAsEventListener(this));
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -161,13 +161,17 @@ OpenLayers.Layer.Google.prototype = Object.extend( new OpenLayers.Layer(), {
|
|||||||
*
|
*
|
||||||
* @returns An OpenLayers.LonLat which is the passed-in view port
|
* @returns An OpenLayers.LonLat which is the passed-in view port
|
||||||
* OpenLayers.Pixel, translated into lon/lat by GMAPS
|
* OpenLayers.Pixel, translated into lon/lat by GMAPS
|
||||||
|
* If gmap is not loaded, returns null.
|
||||||
* @type OpenLayers.LonLat
|
* @type OpenLayers.LonLat
|
||||||
*/
|
*/
|
||||||
getLonLatFromViewPortPx: function (viewPortPx) {
|
getLonLatFromViewPortPx: function (viewPortPx) {
|
||||||
|
var lonlat = null;
|
||||||
|
if (this.gmap != null) {
|
||||||
var gPoint = this.getGPointFromOLPixel(viewPortPx);
|
var gPoint = this.getGPointFromOLPixel(viewPortPx);
|
||||||
var gLatLng = this.gmap.fromContainerPixelToLatLng(gPoint)
|
var gLatLng = this.gmap.fromContainerPixelToLatLng(gPoint)
|
||||||
|
lonlat = this.getOLLonLatFromGLatLng(gLatLng);
|
||||||
return this.getOLLonLatFromGLatLng(gLatLng);
|
}
|
||||||
|
return lonlat;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
@@ -176,16 +180,21 @@ OpenLayers.Layer.Google.prototype = Object.extend( new OpenLayers.Layer(), {
|
|||||||
*
|
*
|
||||||
* @returns An OpenLayers.Pixel which is the passed-in OpenLayers.LonLat,
|
* @returns An OpenLayers.Pixel which is the passed-in OpenLayers.LonLat,
|
||||||
* translated into view port pixels BY GMAPS
|
* translated into view port pixels BY GMAPS
|
||||||
|
* If gmap is not loaded, returns null.
|
||||||
* @type OpenLayers.Pixel
|
* @type OpenLayers.Pixel
|
||||||
*/
|
*/
|
||||||
getViewPortPxFromLonLat: function (lonlat) {
|
getViewPortPxFromLonLat: function (lonlat) {
|
||||||
|
var viewPortPx = null;
|
||||||
|
if (this.gmap != null) {
|
||||||
var gLatLng = this.getGLatLngFromOLLonLat(lonlat);
|
var gLatLng = this.getGLatLngFromOLLonLat(lonlat);
|
||||||
|
|
||||||
// note we use special hacked function here,
|
// note we use special hacked function here,
|
||||||
// because GMaps doesnt give it to us
|
// because GMaps doesnt give it to us
|
||||||
var gPoint = this.fromLatLngToContainerPixel(gLatLng);
|
var gPoint = this.fromLatLngToContainerPixel(gLatLng);
|
||||||
|
|
||||||
return this.getOLPixelFromGPoint(gPoint);
|
viewPortPx = this.getOLPixelFromGPoint(gPoint);
|
||||||
|
}
|
||||||
|
return viewPortPx;
|
||||||
},
|
},
|
||||||
|
|
||||||
/** Hacked function because GMAPS does not give us
|
/** Hacked function because GMAPS does not give us
|
||||||
@@ -217,26 +226,36 @@ OpenLayers.Layer.Google.prototype = Object.extend( new OpenLayers.Layer(), {
|
|||||||
/**
|
/**
|
||||||
* @param {OpenLayers.Bounds} bounds
|
* @param {OpenLayers.Bounds} bounds
|
||||||
*
|
*
|
||||||
* @return {int}
|
* @returns Corresponding zoom level for a specified Bounds.
|
||||||
|
* If gmap is not loaded, returns null.
|
||||||
|
* @type int
|
||||||
*/
|
*/
|
||||||
getZoomForExtent: function (bounds) {
|
getZoomForExtent: function (bounds) {
|
||||||
|
var zoom = null;
|
||||||
|
if (this.gmap != null) {
|
||||||
var gBounds = this.getGLatLngBoundsFromOLBounds(bounds);
|
var gBounds = this.getGLatLngBoundsFromOLBounds(bounds);
|
||||||
var gZoom = this.gmap.getBoundsZoomLevel(gBounds);
|
var gZoom = this.gmap.getBoundsZoomLevel(gBounds);
|
||||||
|
zoom = this.getOLZoomFromGZoom(gZoom);
|
||||||
return this.getOLZoomFromGZoom(gZoom);
|
}
|
||||||
|
return zoom;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns A Bounds object which represents the lon/lat bounds of the
|
* @returns A Bounds object which represents the lon/lat bounds of the
|
||||||
* current viewPort.
|
* current viewPort.
|
||||||
|
* If gmap is not loaded, returns null
|
||||||
* @type OpenLayers.Bounds
|
* @type OpenLayers.Bounds
|
||||||
*/
|
*/
|
||||||
getExtent: function () {
|
getExtent: function () {
|
||||||
|
var extent = null;
|
||||||
|
if (this.gmap != null) {
|
||||||
if (this.gmap.getCenter() == null) {
|
if (this.gmap.getCenter() == null) {
|
||||||
this.moveTo();
|
this.moveTo();
|
||||||
}
|
}
|
||||||
var gLatLngBounds = this.gmap.getBounds();
|
var gLatLngBounds = this.gmap.getBounds();
|
||||||
return this.getOLBoundsFromGLatLngBounds(gLatLngBounds);
|
extent = this.getOLBoundsFromGLatLngBounds(gLatLngBounds);
|
||||||
|
}
|
||||||
|
return extent;
|
||||||
},
|
},
|
||||||
|
|
||||||
/********************************************************/
|
/********************************************************/
|
||||||
|
|||||||
Reference in New Issue
Block a user