add support for GMaps v3. Thanks tschaub for the big improvements to my original patch. p=tschaub,me, r=tschaub (closes #2493)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@10474 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
32
examples/google-v3.html
Normal file
32
examples/google-v3.html
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>OpenLayers Google (v3) Layer Example</title>
|
||||||
|
<link rel="stylesheet" href="../theme/default/style.css" type="text/css">
|
||||||
|
<link rel="stylesheet" href="../theme/default/google.css" type="text/css">
|
||||||
|
<link rel="stylesheet" href="style.css" type="text/css">
|
||||||
|
<script src="http://maps.google.com/maps/api/js?sensor=false"></script>
|
||||||
|
<script src="../lib/OpenLayers.js"></script>
|
||||||
|
<script src="google-v3.js"></script>
|
||||||
|
</head>
|
||||||
|
<body onload="init()">
|
||||||
|
<h1 id="title">Google (v3) Layer Example</h1>
|
||||||
|
<p id="shortdesc">
|
||||||
|
Demonstrate use the Google Maps v3 API.
|
||||||
|
</p>
|
||||||
|
<div id="map" class="smallmap"></div>
|
||||||
|
<div id="docs">
|
||||||
|
<p>
|
||||||
|
If you use the Google Maps v3 API with a Google layer, you don't
|
||||||
|
need to include an API key. This layer only works in the
|
||||||
|
spherical mercator projection. See the
|
||||||
|
<a href="google-v3.js" target="_blank">google-v3.js source</a>
|
||||||
|
to see how this is done.
|
||||||
|
<p>
|
||||||
|
In order to position the Google attribution div in the default
|
||||||
|
location, you must include the extra theme/default/google.css
|
||||||
|
stylesheet.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
32
examples/google-v3.js
Normal file
32
examples/google-v3.js
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
var map;
|
||||||
|
|
||||||
|
function init() {
|
||||||
|
map = new OpenLayers.Map('map');
|
||||||
|
map.addControl(new OpenLayers.Control.LayerSwitcher());
|
||||||
|
|
||||||
|
var gphy = new OpenLayers.Layer.Google(
|
||||||
|
"Google Physical",
|
||||||
|
{type: google.maps.MapTypeId.TERRAIN}
|
||||||
|
);
|
||||||
|
var gmap = new OpenLayers.Layer.Google(
|
||||||
|
"Google Streets", // the default
|
||||||
|
{numZoomLevels: 20}
|
||||||
|
);
|
||||||
|
var ghyb = new OpenLayers.Layer.Google(
|
||||||
|
"Google Hybrid",
|
||||||
|
{type: google.maps.MapTypeId.HYBRID, numZoomLevels: 20}
|
||||||
|
);
|
||||||
|
var gsat = new OpenLayers.Layer.Google(
|
||||||
|
"Google Satellite",
|
||||||
|
{type: google.maps.MapTypeId.SATELLITE, numZoomLevels: 22}
|
||||||
|
);
|
||||||
|
|
||||||
|
map.addLayers([gphy, gmap, ghyb, gsat]);
|
||||||
|
|
||||||
|
// Google.v3 uses EPSG:900913 as projection, so we have to
|
||||||
|
// transform our coordinates
|
||||||
|
map.setCenter(new OpenLayers.LonLat(10.2, 48.9).transform(
|
||||||
|
new OpenLayers.Projection("EPSG:4326"),
|
||||||
|
map.getProjectionObject()
|
||||||
|
), 5);
|
||||||
|
}
|
||||||
27
examples/osm-google.html
Normal file
27
examples/osm-google.html
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>OpenLayers OSM and Google Example</title>
|
||||||
|
<link rel="stylesheet" href="../theme/default/style.css" type="text/css">
|
||||||
|
<link rel="stylesheet" href="../theme/default/google.css" type="text/css">
|
||||||
|
<link rel="stylesheet" href="style.css" type="text/css">
|
||||||
|
<script src="http://maps.google.com/maps/api/js?sensor=false"></script>
|
||||||
|
<script src="../lib/OpenLayers.js"></script>
|
||||||
|
<script src="osm-google.js"></script>
|
||||||
|
</head>
|
||||||
|
<body onload="init()">
|
||||||
|
<h1 id="title">OSM and Google Together</h1>
|
||||||
|
<p id="shortdesc">
|
||||||
|
Demonstrate use of an OSM layer and a Google layer as base layers.
|
||||||
|
</p>
|
||||||
|
<div id="map" class="smallmap"></div>
|
||||||
|
<div id="docs">
|
||||||
|
<p>
|
||||||
|
The Google(v3) layer and the OSM are both in the same projection
|
||||||
|
- spherical mercator - and can be used on a map together.
|
||||||
|
See the <a href="osm-google.js" target="_blank">
|
||||||
|
osm-google.js source</a> to see how this is done.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
28
examples/osm-google.js
Normal file
28
examples/osm-google.js
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
var map;
|
||||||
|
|
||||||
|
function init() {
|
||||||
|
map = new OpenLayers.Map({
|
||||||
|
div: "map",
|
||||||
|
projection: new OpenLayers.Projection("EPSG:900913"),
|
||||||
|
units: "m",
|
||||||
|
maxResolution: 156543.0339,
|
||||||
|
maxExtent: new OpenLayers.Bounds(
|
||||||
|
-20037508, -20037508, 20037508, 20037508.34
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
|
var osm = new OpenLayers.Layer.OSM();
|
||||||
|
var gmap = new OpenLayers.Layer.Google("Google Streets");
|
||||||
|
|
||||||
|
map.addLayers([osm, gmap]);
|
||||||
|
|
||||||
|
map.addControl(new OpenLayers.Control.LayerSwitcher());
|
||||||
|
|
||||||
|
map.setCenter(
|
||||||
|
new OpenLayers.LonLat(10.2, 48.9).transform(
|
||||||
|
new OpenLayers.Projection("EPSG:4326"),
|
||||||
|
map.getProjectionObject()
|
||||||
|
),
|
||||||
|
5
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -107,6 +107,8 @@
|
|||||||
"OpenLayers/Layer/EventPane.js",
|
"OpenLayers/Layer/EventPane.js",
|
||||||
"OpenLayers/Layer/FixedZoomLevels.js",
|
"OpenLayers/Layer/FixedZoomLevels.js",
|
||||||
"OpenLayers/Layer/Google.js",
|
"OpenLayers/Layer/Google.js",
|
||||||
|
"OpenLayers/Layer/Google/v2.js",
|
||||||
|
"OpenLayers/Layer/Google/v3.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",
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
* @requires OpenLayers/Layer/SphericalMercator.js
|
* @requires OpenLayers/Layer/SphericalMercator.js
|
||||||
* @requires OpenLayers/Layer/EventPane.js
|
* @requires OpenLayers/Layer/EventPane.js
|
||||||
* @requires OpenLayers/Layer/FixedZoomLevels.js
|
* @requires OpenLayers/Layer/FixedZoomLevels.js
|
||||||
* @requires OpenLayers/Console.js
|
* @requires OpenLayers/Layer/Google/v2.js
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -80,23 +80,10 @@ OpenLayers.Layer.Google = OpenLayers.Class(
|
|||||||
sphericalMercator: false,
|
sphericalMercator: false,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Property: dragObject
|
* Property: version
|
||||||
* {GDraggableObject} Since 2.93, Google has exposed the ability to get
|
* {Number} The version of the Google Maps API
|
||||||
* the maps GDraggableObject. We can now use this for smooth panning
|
|
||||||
*/
|
*/
|
||||||
dragObject: null,
|
version: null,
|
||||||
|
|
||||||
/**
|
|
||||||
* Property: termsOfUse
|
|
||||||
* {DOMElement} Div for Google's copyright and terms of use link
|
|
||||||
*/
|
|
||||||
termsOfUse: null,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Property: poweredBy
|
|
||||||
* {DOMElement} Div for Google's powered by logo and link
|
|
||||||
*/
|
|
||||||
poweredBy: null,
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor: OpenLayers.Layer.Google
|
* Constructor: OpenLayers.Layer.Google
|
||||||
@@ -107,10 +94,28 @@ OpenLayers.Layer.Google = OpenLayers.Class(
|
|||||||
* on the layer.
|
* on the layer.
|
||||||
*/
|
*/
|
||||||
initialize: function(name, options) {
|
initialize: function(name, options) {
|
||||||
OpenLayers.Layer.EventPane.prototype.initialize.apply(this, arguments);
|
options = options || {};
|
||||||
|
if(!options.version) {
|
||||||
|
options.version = typeof GMap2 === "function" ? "2" : "3";
|
||||||
|
}
|
||||||
|
var mixin = OpenLayers.Layer.Google["v" +
|
||||||
|
options.version.replace(/\./g, "_")];
|
||||||
|
if (mixin) {
|
||||||
|
OpenLayers.Util.applyDefaults(options, mixin);
|
||||||
|
} else {
|
||||||
|
throw "Unsupported Google Maps API version: " + options.version;
|
||||||
|
}
|
||||||
|
|
||||||
|
OpenLayers.Util.applyDefaults(options, mixin.DEFAULTS);
|
||||||
|
if (options.maxExtent) {
|
||||||
|
options.maxExtent = options.maxExtent.clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
OpenLayers.Layer.EventPane.prototype.initialize.apply(this,
|
||||||
|
[name, options]);
|
||||||
OpenLayers.Layer.FixedZoomLevels.prototype.initialize.apply(this,
|
OpenLayers.Layer.FixedZoomLevels.prototype.initialize.apply(this,
|
||||||
arguments);
|
[name, options]);
|
||||||
this.addContainerPxFunction();
|
|
||||||
if (this.sphericalMercator) {
|
if (this.sphericalMercator) {
|
||||||
OpenLayers.Util.extend(this, OpenLayers.Layer.SphericalMercator);
|
OpenLayers.Util.extend(this, OpenLayers.Layer.SphericalMercator);
|
||||||
this.initMercatorParameters();
|
this.initMercatorParameters();
|
||||||
@@ -136,116 +141,6 @@ OpenLayers.Layer.Google = OpenLayers.Class(
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* Method: loadMapObject
|
|
||||||
* Load the GMap and register appropriate event listeners. If we can't
|
|
||||||
* load GMap2, then display a warning message.
|
|
||||||
*/
|
|
||||||
loadMapObject:function() {
|
|
||||||
if (!this.type) {
|
|
||||||
this.type = G_NORMAL_MAP;
|
|
||||||
}
|
|
||||||
var mapObject, termsOfUse, poweredBy;
|
|
||||||
var cache = OpenLayers.Layer.Google.cache[this.map.id];
|
|
||||||
if (cache) {
|
|
||||||
// there are already Google layers added to this map
|
|
||||||
mapObject = cache.mapObject;
|
|
||||||
termsOfUse = cache.termsOfUse;
|
|
||||||
poweredBy = cache.poweredBy;
|
|
||||||
// increment the layer count
|
|
||||||
++cache.count;
|
|
||||||
} else {
|
|
||||||
// this is the first Google layer for this map
|
|
||||||
|
|
||||||
var container = this.map.viewPortDiv;
|
|
||||||
var div = document.createElement("div");
|
|
||||||
div.id = this.map.id + "_GMap2Container";
|
|
||||||
div.style.position = "absolute";
|
|
||||||
div.style.width = "100%";
|
|
||||||
div.style.height = "100%";
|
|
||||||
container.appendChild(div);
|
|
||||||
|
|
||||||
// create GMap and shuffle elements
|
|
||||||
try {
|
|
||||||
mapObject = new GMap2(div);
|
|
||||||
|
|
||||||
// move the ToS and branding stuff up to the container div
|
|
||||||
termsOfUse = div.lastChild;
|
|
||||||
container.appendChild(termsOfUse);
|
|
||||||
termsOfUse.style.zIndex = "1100";
|
|
||||||
termsOfUse.style.right = "";
|
|
||||||
termsOfUse.style.bottom = "";
|
|
||||||
termsOfUse.className = "olLayerGoogleCopyright";
|
|
||||||
|
|
||||||
poweredBy = div.lastChild;
|
|
||||||
container.appendChild(poweredBy);
|
|
||||||
poweredBy.style.zIndex = "1100";
|
|
||||||
poweredBy.style.right = "";
|
|
||||||
poweredBy.style.bottom = "";
|
|
||||||
poweredBy.className = "olLayerGooglePoweredBy gmnoprint";
|
|
||||||
|
|
||||||
} catch (e) {
|
|
||||||
OpenLayers.Console.error(e);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// cache elements for use by any other google layers added to
|
|
||||||
// this same map
|
|
||||||
OpenLayers.Layer.Google.cache[this.map.id] = {
|
|
||||||
mapObject: mapObject,
|
|
||||||
termsOfUse: termsOfUse,
|
|
||||||
poweredBy: poweredBy,
|
|
||||||
count: 1
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
this.mapObject = mapObject;
|
|
||||||
this.termsOfUse = termsOfUse;
|
|
||||||
this.poweredBy = poweredBy;
|
|
||||||
|
|
||||||
// ensure this layer type is one of the mapObject types
|
|
||||||
if (OpenLayers.Util.indexOf(this.mapObject.getMapTypes(),
|
|
||||||
this.type) === -1) {
|
|
||||||
this.mapObject.addMapType(this.type);
|
|
||||||
}
|
|
||||||
|
|
||||||
//since v 2.93 getDragObject is now available.
|
|
||||||
if(typeof mapObject.getDragObject == "function") {
|
|
||||||
this.dragObject = mapObject.getDragObject();
|
|
||||||
} else {
|
|
||||||
this.dragPanMapObject = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(this.isBaseLayer === false) {
|
|
||||||
this.setGMapVisibility(this.div.style.display !== "none");
|
|
||||||
}
|
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* APIMethod: onMapResize
|
|
||||||
*/
|
|
||||||
onMapResize: function() {
|
|
||||||
// workaround for resizing of invisible or not yet fully loaded layers
|
|
||||||
// where GMap2.checkResize() does not work. We need to load the GMap
|
|
||||||
// for the old div size, then checkResize(), and then call
|
|
||||||
// layer.moveTo() to trigger GMap.setCenter() (which will finish
|
|
||||||
// the GMap initialization).
|
|
||||||
if(this.visibility && this.mapObject.isLoaded()) {
|
|
||||||
this.mapObject.checkResize();
|
|
||||||
} else {
|
|
||||||
if(!this._resized) {
|
|
||||||
var layer = this;
|
|
||||||
var handle = GEvent.addListener(this.mapObject, "load", function() {
|
|
||||||
GEvent.removeListener(handle);
|
|
||||||
delete layer._resized;
|
|
||||||
layer.mapObject.checkResize();
|
|
||||||
layer.moveTo(layer.map.getCenter(), layer.map.getZoom());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
this._resized = true;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* APIMethod: setVisibility
|
* APIMethod: setVisibility
|
||||||
* Set the visibility flag for the layer and hide/show & redraw
|
* Set the visibility flag for the layer and hide/show & redraw
|
||||||
@@ -269,43 +164,6 @@ OpenLayers.Layer.Google = OpenLayers.Class(
|
|||||||
this.setOpacity(opacity);
|
this.setOpacity(opacity);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* Method: setGMapVisibility
|
|
||||||
* Display the GMap container and associated elements.
|
|
||||||
*
|
|
||||||
* Parameters:
|
|
||||||
* visible - {Boolean} Display the GMap elements.
|
|
||||||
*/
|
|
||||||
setGMapVisibility: function(visible) {
|
|
||||||
var cache = OpenLayers.Layer.Google.cache[this.map.id];
|
|
||||||
if (cache) {
|
|
||||||
var container = this.mapObject.getContainer();
|
|
||||||
if (visible === true) {
|
|
||||||
this.mapObject.setMapType(this.type);
|
|
||||||
container.style.display = "";
|
|
||||||
this.termsOfUse.style.left = "";
|
|
||||||
this.termsOfUse.style.display = "";
|
|
||||||
this.poweredBy.style.display = "";
|
|
||||||
cache.displayed = this.id;
|
|
||||||
} else {
|
|
||||||
if (cache.displayed === this.id) {
|
|
||||||
delete cache.displayed;
|
|
||||||
}
|
|
||||||
if (!cache.displayed) {
|
|
||||||
container.style.display = "none";
|
|
||||||
this.termsOfUse.style.display = "none";
|
|
||||||
// move ToU far to the left in addition to setting display
|
|
||||||
// to "none", because at the end of the GMap2 load
|
|
||||||
// sequence, display: none will be unset and ToU would be
|
|
||||||
// visible after loading a map with a google layer that is
|
|
||||||
// initially hidden.
|
|
||||||
this.termsOfUse.style.left = "-9999px";
|
|
||||||
this.poweredBy.style.display = "none";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* APIMethod: setOpacity
|
* APIMethod: setOpacity
|
||||||
* Sets the opacity for the entire layer (all images)
|
* Sets the opacity for the entire layer (all images)
|
||||||
@@ -326,7 +184,7 @@ OpenLayers.Layer.Google = OpenLayers.Class(
|
|||||||
// Though this layer's opacity may not change, we're sharing a container
|
// Though this layer's opacity may not change, we're sharing a container
|
||||||
// and need to update the opacity for the entire container.
|
// and need to update the opacity for the entire container.
|
||||||
if (this.getVisibility()) {
|
if (this.getVisibility()) {
|
||||||
var container = this.mapObject.getContainer();
|
var container = this.getMapContainer();
|
||||||
OpenLayers.Util.modifyDOMElement(
|
OpenLayers.Util.modifyDOMElement(
|
||||||
container, null, null, null, null, null, null, opacity
|
container, null, null, null, null, null, null, opacity
|
||||||
);
|
);
|
||||||
@@ -347,7 +205,7 @@ OpenLayers.Layer.Google = OpenLayers.Class(
|
|||||||
this.setGMapVisibility(false);
|
this.setGMapVisibility(false);
|
||||||
var cache = OpenLayers.Layer.Google.cache[this.map.id];
|
var cache = OpenLayers.Layer.Google.cache[this.map.id];
|
||||||
if (cache && cache.count <= 1) {
|
if (cache && cache.count <= 1) {
|
||||||
this.removeGMapElements(false);
|
this.removeGMapElements();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
OpenLayers.Layer.EventPane.prototype.destroy.apply(this, arguments);
|
OpenLayers.Layer.EventPane.prototype.destroy.apply(this, arguments);
|
||||||
@@ -362,7 +220,7 @@ OpenLayers.Layer.Google = OpenLayers.Class(
|
|||||||
var cache = OpenLayers.Layer.Google.cache[this.map.id];
|
var cache = OpenLayers.Layer.Google.cache[this.map.id];
|
||||||
if (cache) {
|
if (cache) {
|
||||||
// remove shared elements from dom
|
// remove shared elements from dom
|
||||||
var container = this.mapObject && this.mapObject.getContainer();
|
var container = this.mapObject && this.getMapContainer();
|
||||||
if (container && container.parentNode) {
|
if (container && container.parentNode) {
|
||||||
container.parentNode.removeChild(container);
|
container.parentNode.removeChild(container);
|
||||||
}
|
}
|
||||||
@@ -408,33 +266,6 @@ OpenLayers.Layer.Google = OpenLayers.Class(
|
|||||||
OpenLayers.Layer.EventPane.prototype.removeMap.apply(this, arguments);
|
OpenLayers.Layer.EventPane.prototype.removeMap.apply(this, arguments);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* APIMethod: getZoomForExtent
|
|
||||||
*
|
|
||||||
* Parameters:
|
|
||||||
* bounds - {<OpenLayers.Bounds>}
|
|
||||||
*
|
|
||||||
* Returns:
|
|
||||||
* {Integer} Corresponding zoom level for a specified Bounds.
|
|
||||||
* If mapObject is not loaded or not centered, returns null
|
|
||||||
*
|
|
||||||
getZoomForExtent: function (bounds) {
|
|
||||||
var zoom = null;
|
|
||||||
if (this.mapObject != null) {
|
|
||||||
var moBounds = this.getMapObjectBoundsFromOLBounds(bounds);
|
|
||||||
var moZoom = this.getMapObjectZoomFromMapObjectBounds(moBounds);
|
|
||||||
|
|
||||||
//make sure zoom is within bounds
|
|
||||||
var moZoom = Math.min(Math.max(moZoom, this.minZoomLevel),
|
|
||||||
this.maxZoomLevel);
|
|
||||||
|
|
||||||
zoom = this.getOLZoomFromMapObjectZoom(moZoom);
|
|
||||||
}
|
|
||||||
return zoom;
|
|
||||||
},
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// TRANSLATION: MapObject Bounds <-> OpenLayers.Bounds
|
// TRANSLATION: MapObject Bounds <-> OpenLayers.Bounds
|
||||||
//
|
//
|
||||||
@@ -470,62 +301,6 @@ OpenLayers.Layer.Google = OpenLayers.Class(
|
|||||||
return olBounds;
|
return olBounds;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* APIMethod: getMapObjectBoundsFromOLBounds
|
|
||||||
*
|
|
||||||
* Parameters:
|
|
||||||
* olBounds - {<OpenLayers.Bounds>}
|
|
||||||
*
|
|
||||||
* Returns:
|
|
||||||
* {Object} A MapObject Bounds, translated from olBounds
|
|
||||||
* Returns null if null value is passed in
|
|
||||||
*/
|
|
||||||
getMapObjectBoundsFromOLBounds: function(olBounds) {
|
|
||||||
var moBounds = null;
|
|
||||||
if (olBounds != null) {
|
|
||||||
var sw = this.sphericalMercator ?
|
|
||||||
this.inverseMercator(olBounds.bottom, olBounds.left) :
|
|
||||||
new OpenLayers.LonLat(olBounds.bottom, olBounds.left);
|
|
||||||
var ne = this.sphericalMercator ?
|
|
||||||
this.inverseMercator(olBounds.top, olBounds.right) :
|
|
||||||
new OpenLayers.LonLat(olBounds.top, olBounds.right);
|
|
||||||
moBounds = new GLatLngBounds(new GLatLng(sw.lat, sw.lon),
|
|
||||||
new GLatLng(ne.lat, ne.lon));
|
|
||||||
}
|
|
||||||
return moBounds;
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method: addContainerPxFunction
|
|
||||||
* Hack-on function because GMAPS does not give it to us
|
|
||||||
*
|
|
||||||
* Parameters:
|
|
||||||
* gLatLng - {GLatLng}
|
|
||||||
*
|
|
||||||
* Returns:
|
|
||||||
* {GPoint} A GPoint specifying gLatLng translated into "Container" coords
|
|
||||||
*/
|
|
||||||
addContainerPxFunction: function() {
|
|
||||||
if ( (typeof GMap2 != "undefined") &&
|
|
||||||
!GMap2.prototype.fromLatLngToContainerPixel) {
|
|
||||||
|
|
||||||
GMap2.prototype.fromLatLngToContainerPixel = function(gLatLng) {
|
|
||||||
|
|
||||||
// first we translate into "DivPixel"
|
|
||||||
var gPoint = this.fromLatLngToDivPixel(gLatLng);
|
|
||||||
|
|
||||||
// locate the sliding "Div" div
|
|
||||||
var div = this.getContainer().firstChild.firstChild;
|
|
||||||
|
|
||||||
// adjust by the offset of "Div" and voila!
|
|
||||||
gPoint.x += div.offsetLeft;
|
|
||||||
gPoint.y += div.offsetTop;
|
|
||||||
|
|
||||||
return gPoint;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* APIMethod: getWarningHTML
|
* APIMethod: getWarningHTML
|
||||||
*
|
*
|
||||||
@@ -547,29 +322,6 @@ OpenLayers.Layer.Google = OpenLayers.Class(
|
|||||||
|
|
||||||
// Get&Set Center, Zoom
|
// Get&Set Center, Zoom
|
||||||
|
|
||||||
/**
|
|
||||||
* APIMethod: setMapObjectCenter
|
|
||||||
* Set the mapObject to the specified center and zoom
|
|
||||||
*
|
|
||||||
* Parameters:
|
|
||||||
* center - {Object} MapObject LonLat format
|
|
||||||
* zoom - {int} MapObject zoom format
|
|
||||||
*/
|
|
||||||
setMapObjectCenter: function(center, zoom) {
|
|
||||||
this.mapObject.setCenter(center, zoom);
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* APIMethod: dragPanMapObject
|
|
||||||
*
|
|
||||||
* Parameters:
|
|
||||||
* dX - {Integer}
|
|
||||||
* dY - {Integer}
|
|
||||||
*/
|
|
||||||
dragPanMapObject: function(dX, dY) {
|
|
||||||
this.dragObject.moveBy(new GSize(-dX, dY));
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* APIMethod: getMapObjectCenter
|
* APIMethod: getMapObjectCenter
|
||||||
*
|
*
|
||||||
@@ -591,50 +343,6 @@ OpenLayers.Layer.Google = OpenLayers.Class(
|
|||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
// LonLat - Pixel Translation
|
|
||||||
|
|
||||||
/**
|
|
||||||
* APIMethod: getMapObjectLonLatFromMapObjectPixel
|
|
||||||
*
|
|
||||||
* Parameters:
|
|
||||||
* moPixel - {Object} MapObject Pixel format
|
|
||||||
*
|
|
||||||
* Returns:
|
|
||||||
* {Object} MapObject LonLat translated from MapObject Pixel
|
|
||||||
*/
|
|
||||||
getMapObjectLonLatFromMapObjectPixel: function(moPixel) {
|
|
||||||
return this.mapObject.fromContainerPixelToLatLng(moPixel);
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* APIMethod: getMapObjectPixelFromMapObjectLonLat
|
|
||||||
*
|
|
||||||
* Parameters:
|
|
||||||
* moLonLat - {Object} MapObject LonLat format
|
|
||||||
*
|
|
||||||
* Returns:
|
|
||||||
* {Object} MapObject Pixel transtlated from MapObject LonLat
|
|
||||||
*/
|
|
||||||
getMapObjectPixelFromMapObjectLonLat: function(moLonLat) {
|
|
||||||
return this.mapObject.fromLatLngToContainerPixel(moLonLat);
|
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
// Bounds
|
|
||||||
|
|
||||||
/**
|
|
||||||
* APIMethod: getMapObjectZoomFromMapObjectBounds
|
|
||||||
*
|
|
||||||
* Parameters:
|
|
||||||
* moBounds - {Object} MapObject Bounds format
|
|
||||||
*
|
|
||||||
* Returns:
|
|
||||||
* {Object} MapObject Zoom for specified MapObject Bounds
|
|
||||||
*/
|
|
||||||
getMapObjectZoomFromMapObjectBounds: function(moBounds) {
|
|
||||||
return this.mapObject.getBoundsZoomLevel(moBounds);
|
|
||||||
},
|
|
||||||
|
|
||||||
/************************************
|
/************************************
|
||||||
* *
|
* *
|
||||||
* MapObject Primitives *
|
* MapObject Primitives *
|
||||||
@@ -675,27 +383,6 @@ OpenLayers.Layer.Google = OpenLayers.Class(
|
|||||||
return lat;
|
return lat;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* APIMethod: getMapObjectLonLatFromLonLat
|
|
||||||
*
|
|
||||||
* Parameters:
|
|
||||||
* lon - {Float}
|
|
||||||
* lat - {Float}
|
|
||||||
*
|
|
||||||
* Returns:
|
|
||||||
* {Object} MapObject LonLat built from lon and lat params
|
|
||||||
*/
|
|
||||||
getMapObjectLonLatFromLonLat: function(lon, lat) {
|
|
||||||
var gLatLng;
|
|
||||||
if(this.sphericalMercator) {
|
|
||||||
var lonlat = this.inverseMercator(lon, lat);
|
|
||||||
gLatLng = new GLatLng(lonlat.lat, lonlat.lon);
|
|
||||||
} else {
|
|
||||||
gLatLng = new GLatLng(lat, lon);
|
|
||||||
}
|
|
||||||
return gLatLng;
|
|
||||||
},
|
|
||||||
|
|
||||||
// Pixel
|
// Pixel
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -724,20 +411,6 @@ OpenLayers.Layer.Google = OpenLayers.Class(
|
|||||||
return moPixel.y;
|
return moPixel.y;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* APIMethod: getMapObjectPixelFromXY
|
|
||||||
*
|
|
||||||
* Parameters:
|
|
||||||
* x - {Integer}
|
|
||||||
* y - {Integer}
|
|
||||||
*
|
|
||||||
* Returns:
|
|
||||||
* {Object} MapObject Pixel from x and y parameters
|
|
||||||
*/
|
|
||||||
getMapObjectPixelFromXY: function(x, y) {
|
|
||||||
return new GPoint(x, y);
|
|
||||||
},
|
|
||||||
|
|
||||||
CLASS_NAME: "OpenLayers.Layer.Google"
|
CLASS_NAME: "OpenLayers.Layer.Google"
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
692
lib/OpenLayers/Layer/Google/v2.js
Normal file
692
lib/OpenLayers/Layer/Google/v2.js
Normal file
@@ -0,0 +1,692 @@
|
|||||||
|
/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
|
||||||
|
* license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the
|
||||||
|
* full text of the license. */
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @requires OpenLayers/Layer/Google.js
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constant: OpenLayers.Layer.Google.v2
|
||||||
|
*
|
||||||
|
* Mixin providing functionality specific to the Google Maps API v2.
|
||||||
|
*/
|
||||||
|
OpenLayers.Layer.Google.v2 = {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Property: termsOfUse
|
||||||
|
* {DOMElement} Div for Google's copyright and terms of use link
|
||||||
|
*/
|
||||||
|
termsOfUse: null,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Property: poweredBy
|
||||||
|
* {DOMElement} Div for Google's powered by logo and link
|
||||||
|
*/
|
||||||
|
poweredBy: null,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Property: dragObject
|
||||||
|
* {GDraggableObject} Since 2.93, Google has exposed the ability to get
|
||||||
|
* the maps GDraggableObject. We can now use this for smooth panning
|
||||||
|
*/
|
||||||
|
dragObject: null,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method: loadMapObject
|
||||||
|
* Load the GMap and register appropriate event listeners. If we can't
|
||||||
|
* load GMap2, then display a warning message.
|
||||||
|
*/
|
||||||
|
loadMapObject:function() {
|
||||||
|
if (!this.type) {
|
||||||
|
this.type = G_NORMAL_MAP;
|
||||||
|
}
|
||||||
|
var mapObject, termsOfUse, poweredBy;
|
||||||
|
var cache = OpenLayers.Layer.Google.cache[this.map.id];
|
||||||
|
if (cache) {
|
||||||
|
// there are already Google layers added to this map
|
||||||
|
mapObject = cache.mapObject;
|
||||||
|
termsOfUse = cache.termsOfUse;
|
||||||
|
poweredBy = cache.poweredBy;
|
||||||
|
// increment the layer count
|
||||||
|
++cache.count;
|
||||||
|
} else {
|
||||||
|
// this is the first Google layer for this map
|
||||||
|
|
||||||
|
var container = this.map.viewPortDiv;
|
||||||
|
var div = document.createElement("div");
|
||||||
|
div.id = this.map.id + "_GMap2Container";
|
||||||
|
div.style.position = "absolute";
|
||||||
|
div.style.width = "100%";
|
||||||
|
div.style.height = "100%";
|
||||||
|
container.appendChild(div);
|
||||||
|
|
||||||
|
// create GMap and shuffle elements
|
||||||
|
try {
|
||||||
|
mapObject = new GMap2(div);
|
||||||
|
|
||||||
|
// move the ToS and branding stuff up to the container div
|
||||||
|
termsOfUse = div.lastChild;
|
||||||
|
container.appendChild(termsOfUse);
|
||||||
|
termsOfUse.style.zIndex = "1100";
|
||||||
|
termsOfUse.style.right = "";
|
||||||
|
termsOfUse.style.bottom = "";
|
||||||
|
termsOfUse.className = "olLayerGoogleCopyright";
|
||||||
|
|
||||||
|
poweredBy = div.lastChild;
|
||||||
|
container.appendChild(poweredBy);
|
||||||
|
poweredBy.style.zIndex = "1100";
|
||||||
|
poweredBy.style.right = "";
|
||||||
|
poweredBy.style.bottom = "";
|
||||||
|
poweredBy.className = "olLayerGooglePoweredBy gmnoprint";
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
throw(e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// cache elements for use by any other google layers added to
|
||||||
|
// this same map
|
||||||
|
OpenLayers.Layer.Google.cache[this.map.id] = {
|
||||||
|
mapObject: mapObject,
|
||||||
|
termsOfUse: termsOfUse,
|
||||||
|
poweredBy: poweredBy,
|
||||||
|
count: 1
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
this.mapObject = mapObject;
|
||||||
|
this.termsOfUse = termsOfUse;
|
||||||
|
this.poweredBy = poweredBy;
|
||||||
|
|
||||||
|
// ensure this layer type is one of the mapObject types
|
||||||
|
if (OpenLayers.Util.indexOf(this.mapObject.getMapTypes(),
|
||||||
|
this.type) === -1) {
|
||||||
|
this.mapObject.addMapType(this.type);
|
||||||
|
}
|
||||||
|
|
||||||
|
//since v 2.93 getDragObject is now available.
|
||||||
|
if(typeof mapObject.getDragObject == "function") {
|
||||||
|
this.dragObject = mapObject.getDragObject();
|
||||||
|
} else {
|
||||||
|
this.dragPanMapObject = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(this.isBaseLayer === false) {
|
||||||
|
this.setGMapVisibility(this.div.style.display !== "none");
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APIMethod: onMapResize
|
||||||
|
*/
|
||||||
|
onMapResize: function() {
|
||||||
|
// workaround for resizing of invisible or not yet fully loaded layers
|
||||||
|
// where GMap2.checkResize() does not work. We need to load the GMap
|
||||||
|
// for the old div size, then checkResize(), and then call
|
||||||
|
// layer.moveTo() to trigger GMap.setCenter() (which will finish
|
||||||
|
// the GMap initialization).
|
||||||
|
if(this.visibility && this.mapObject.isLoaded()) {
|
||||||
|
this.mapObject.checkResize();
|
||||||
|
} else {
|
||||||
|
if(!this._resized) {
|
||||||
|
var layer = this;
|
||||||
|
var handle = GEvent.addListener(this.mapObject, "load", function() {
|
||||||
|
GEvent.removeListener(handle);
|
||||||
|
delete layer._resized;
|
||||||
|
layer.mapObject.checkResize();
|
||||||
|
layer.moveTo(layer.map.getCenter(), layer.map.getZoom());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
this._resized = true;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method: setGMapVisibility
|
||||||
|
* Display the GMap container and associated elements.
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* visible - {Boolean} Display the GMap elements.
|
||||||
|
*/
|
||||||
|
setGMapVisibility: function(visible) {
|
||||||
|
var cache = OpenLayers.Layer.Google.cache[this.map.id];
|
||||||
|
if (cache) {
|
||||||
|
var container = this.mapObject.getContainer();
|
||||||
|
if (visible === true) {
|
||||||
|
this.mapObject.setMapType(this.type);
|
||||||
|
container.style.display = "";
|
||||||
|
this.termsOfUse.style.left = "";
|
||||||
|
this.termsOfUse.style.display = "";
|
||||||
|
this.poweredBy.style.display = "";
|
||||||
|
cache.displayed = this.id;
|
||||||
|
} else {
|
||||||
|
if (cache.displayed === this.id) {
|
||||||
|
delete cache.displayed;
|
||||||
|
}
|
||||||
|
if (!cache.displayed) {
|
||||||
|
container.style.display = "none";
|
||||||
|
this.termsOfUse.style.display = "none";
|
||||||
|
// move ToU far to the left in addition to setting display
|
||||||
|
// to "none", because at the end of the GMap2 load
|
||||||
|
// sequence, display: none will be unset and ToU would be
|
||||||
|
// visible after loading a map with a google layer that is
|
||||||
|
// initially hidden.
|
||||||
|
this.termsOfUse.style.left = "-9999px";
|
||||||
|
this.poweredBy.style.display = "none";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method: getMapContainer
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* {DOMElement} the GMap container's div
|
||||||
|
*/
|
||||||
|
getMapContainer: function() {
|
||||||
|
return this.mapObject.getContainer();
|
||||||
|
},
|
||||||
|
|
||||||
|
//
|
||||||
|
// TRANSLATION: MapObject Bounds <-> OpenLayers.Bounds
|
||||||
|
//
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APIMethod: getMapObjectBoundsFromOLBounds
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* olBounds - {<OpenLayers.Bounds>}
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* {Object} A MapObject Bounds, translated from olBounds
|
||||||
|
* Returns null if null value is passed in
|
||||||
|
*/
|
||||||
|
getMapObjectBoundsFromOLBounds: function(olBounds) {
|
||||||
|
var moBounds = null;
|
||||||
|
if (olBounds != null) {
|
||||||
|
var sw = this.sphericalMercator ?
|
||||||
|
this.inverseMercator(olBounds.bottom, olBounds.left) :
|
||||||
|
new OpenLayers.LonLat(olBounds.bottom, olBounds.left);
|
||||||
|
var ne = this.sphericalMercator ?
|
||||||
|
this.inverseMercator(olBounds.top, olBounds.right) :
|
||||||
|
new OpenLayers.LonLat(olBounds.top, olBounds.right);
|
||||||
|
moBounds = new GLatLngBounds(new GLatLng(sw.lat, sw.lon),
|
||||||
|
new GLatLng(ne.lat, ne.lon));
|
||||||
|
}
|
||||||
|
return moBounds;
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/************************************
|
||||||
|
* *
|
||||||
|
* MapObject Interface Controls *
|
||||||
|
* *
|
||||||
|
************************************/
|
||||||
|
|
||||||
|
|
||||||
|
// Get&Set Center, Zoom
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APIMethod: setMapObjectCenter
|
||||||
|
* Set the mapObject to the specified center and zoom
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* center - {Object} MapObject LonLat format
|
||||||
|
* zoom - {int} MapObject zoom format
|
||||||
|
*/
|
||||||
|
setMapObjectCenter: function(center, zoom) {
|
||||||
|
this.mapObject.setCenter(center, zoom);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APIMethod: dragPanMapObject
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* dX - {Integer}
|
||||||
|
* dY - {Integer}
|
||||||
|
*/
|
||||||
|
dragPanMapObject: function(dX, dY) {
|
||||||
|
this.dragObject.moveBy(new GSize(-dX, dY));
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
// LonLat - Pixel Translation
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APIMethod: getMapObjectLonLatFromMapObjectPixel
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* moPixel - {Object} MapObject Pixel format
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* {Object} MapObject LonLat translated from MapObject Pixel
|
||||||
|
*/
|
||||||
|
getMapObjectLonLatFromMapObjectPixel: function(moPixel) {
|
||||||
|
return this.mapObject.fromContainerPixelToLatLng(moPixel);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APIMethod: getMapObjectPixelFromMapObjectLonLat
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* moLonLat - {Object} MapObject LonLat format
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* {Object} MapObject Pixel transtlated from MapObject LonLat
|
||||||
|
*/
|
||||||
|
getMapObjectPixelFromMapObjectLonLat: function(moLonLat) {
|
||||||
|
return this.mapObject.fromLatLngToContainerPixel(moLonLat);
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
// Bounds
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APIMethod: getMapObjectZoomFromMapObjectBounds
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* moBounds - {Object} MapObject Bounds format
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* {Object} MapObject Zoom for specified MapObject Bounds
|
||||||
|
*/
|
||||||
|
getMapObjectZoomFromMapObjectBounds: function(moBounds) {
|
||||||
|
return this.mapObject.getBoundsZoomLevel(moBounds);
|
||||||
|
},
|
||||||
|
|
||||||
|
/************************************
|
||||||
|
* *
|
||||||
|
* MapObject Primitives *
|
||||||
|
* *
|
||||||
|
************************************/
|
||||||
|
|
||||||
|
|
||||||
|
// LonLat
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APIMethod: getMapObjectLonLatFromLonLat
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* lon - {Float}
|
||||||
|
* lat - {Float}
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* {Object} MapObject LonLat built from lon and lat params
|
||||||
|
*/
|
||||||
|
getMapObjectLonLatFromLonLat: function(lon, lat) {
|
||||||
|
var gLatLng;
|
||||||
|
if(this.sphericalMercator) {
|
||||||
|
var lonlat = this.inverseMercator(lon, lat);
|
||||||
|
gLatLng = new GLatLng(lonlat.lat, lonlat.lon);
|
||||||
|
} else {
|
||||||
|
gLatLng = new GLatLng(lat, lon);
|
||||||
|
}
|
||||||
|
return gLatLng;
|
||||||
|
},
|
||||||
|
|
||||||
|
// Pixel
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APIMethod: getMapObjectPixelFromXY
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* x - {Integer}
|
||||||
|
* y - {Integer}
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* {Object} MapObject Pixel from x and y parameters
|
||||||
|
*/
|
||||||
|
getMapObjectPixelFromXY: function(x, y) {
|
||||||
|
return new GPoint(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
|
||||||
|
* license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the
|
||||||
|
* full text of the license. */
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @requires OpenLayers/Layer/Google.js
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constant: OpenLayers.Layer.Google.v2
|
||||||
|
*
|
||||||
|
* Mixin providing functionality specific to the Google Maps API v2.
|
||||||
|
*/
|
||||||
|
OpenLayers.Layer.Google.v2 = {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Property: termsOfUse
|
||||||
|
* {DOMElement} Div for Google's copyright and terms of use link
|
||||||
|
*/
|
||||||
|
termsOfUse: null,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Property: poweredBy
|
||||||
|
* {DOMElement} Div for Google's powered by logo and link
|
||||||
|
*/
|
||||||
|
poweredBy: null,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Property: dragObject
|
||||||
|
* {GDraggableObject} Since 2.93, Google has exposed the ability to get
|
||||||
|
* the maps GDraggableObject. We can now use this for smooth panning
|
||||||
|
*/
|
||||||
|
dragObject: null,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method: loadMapObject
|
||||||
|
* Load the GMap and register appropriate event listeners. If we can't
|
||||||
|
* load GMap2, then display a warning message.
|
||||||
|
*/
|
||||||
|
loadMapObject:function() {
|
||||||
|
if (!this.type) {
|
||||||
|
this.type = G_NORMAL_MAP;
|
||||||
|
}
|
||||||
|
var mapObject, termsOfUse, poweredBy;
|
||||||
|
var cache = OpenLayers.Layer.Google.cache[this.map.id];
|
||||||
|
if (cache) {
|
||||||
|
// there are already Google layers added to this map
|
||||||
|
mapObject = cache.mapObject;
|
||||||
|
termsOfUse = cache.termsOfUse;
|
||||||
|
poweredBy = cache.poweredBy;
|
||||||
|
// increment the layer count
|
||||||
|
++cache.count;
|
||||||
|
} else {
|
||||||
|
// this is the first Google layer for this map
|
||||||
|
|
||||||
|
var container = this.map.viewPortDiv;
|
||||||
|
var div = document.createElement("div");
|
||||||
|
div.id = this.map.id + "_GMap2Container";
|
||||||
|
div.style.position = "absolute";
|
||||||
|
div.style.width = "100%";
|
||||||
|
div.style.height = "100%";
|
||||||
|
container.appendChild(div);
|
||||||
|
|
||||||
|
// create GMap and shuffle elements
|
||||||
|
try {
|
||||||
|
mapObject = new GMap2(div);
|
||||||
|
|
||||||
|
// move the ToS and branding stuff up to the container div
|
||||||
|
termsOfUse = div.lastChild;
|
||||||
|
container.appendChild(termsOfUse);
|
||||||
|
termsOfUse.style.zIndex = "1100";
|
||||||
|
termsOfUse.style.right = "";
|
||||||
|
termsOfUse.style.bottom = "";
|
||||||
|
termsOfUse.className = "olLayerGoogleCopyright";
|
||||||
|
|
||||||
|
poweredBy = div.lastChild;
|
||||||
|
container.appendChild(poweredBy);
|
||||||
|
poweredBy.style.zIndex = "1100";
|
||||||
|
poweredBy.style.right = "";
|
||||||
|
poweredBy.style.bottom = "";
|
||||||
|
poweredBy.className = "olLayerGooglePoweredBy gmnoprint";
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
throw(e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// cache elements for use by any other google layers added to
|
||||||
|
// this same map
|
||||||
|
OpenLayers.Layer.Google.cache[this.map.id] = {
|
||||||
|
mapObject: mapObject,
|
||||||
|
termsOfUse: termsOfUse,
|
||||||
|
poweredBy: poweredBy,
|
||||||
|
count: 1
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
this.mapObject = mapObject;
|
||||||
|
this.termsOfUse = termsOfUse;
|
||||||
|
this.poweredBy = poweredBy;
|
||||||
|
|
||||||
|
// ensure this layer type is one of the mapObject types
|
||||||
|
if (OpenLayers.Util.indexOf(this.mapObject.getMapTypes(),
|
||||||
|
this.type) === -1) {
|
||||||
|
this.mapObject.addMapType(this.type);
|
||||||
|
}
|
||||||
|
|
||||||
|
//since v 2.93 getDragObject is now available.
|
||||||
|
if(typeof mapObject.getDragObject == "function") {
|
||||||
|
this.dragObject = mapObject.getDragObject();
|
||||||
|
} else {
|
||||||
|
this.dragPanMapObject = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(this.isBaseLayer === false) {
|
||||||
|
this.setGMapVisibility(this.div.style.display !== "none");
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APIMethod: onMapResize
|
||||||
|
*/
|
||||||
|
onMapResize: function() {
|
||||||
|
// workaround for resizing of invisible or not yet fully loaded layers
|
||||||
|
// where GMap2.checkResize() does not work. We need to load the GMap
|
||||||
|
// for the old div size, then checkResize(), and then call
|
||||||
|
// layer.moveTo() to trigger GMap.setCenter() (which will finish
|
||||||
|
// the GMap initialization).
|
||||||
|
if(this.visibility && this.mapObject.isLoaded()) {
|
||||||
|
this.mapObject.checkResize();
|
||||||
|
} else {
|
||||||
|
if(!this._resized) {
|
||||||
|
var layer = this;
|
||||||
|
var handle = GEvent.addListener(this.mapObject, "load", function() {
|
||||||
|
GEvent.removeListener(handle);
|
||||||
|
delete layer._resized;
|
||||||
|
layer.mapObject.checkResize();
|
||||||
|
layer.moveTo(layer.map.getCenter(), layer.map.getZoom());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
this._resized = true;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method: setGMapVisibility
|
||||||
|
* Display the GMap container and associated elements.
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* visible - {Boolean} Display the GMap elements.
|
||||||
|
*/
|
||||||
|
setGMapVisibility: function(visible) {
|
||||||
|
var cache = OpenLayers.Layer.Google.cache[this.map.id];
|
||||||
|
if (cache) {
|
||||||
|
var container = this.mapObject.getContainer();
|
||||||
|
if (visible === true) {
|
||||||
|
this.mapObject.setMapType(this.type);
|
||||||
|
container.style.display = "";
|
||||||
|
this.termsOfUse.style.left = "";
|
||||||
|
this.termsOfUse.style.display = "";
|
||||||
|
this.poweredBy.style.display = "";
|
||||||
|
cache.displayed = this.id;
|
||||||
|
} else {
|
||||||
|
if (cache.displayed === this.id) {
|
||||||
|
delete cache.displayed;
|
||||||
|
}
|
||||||
|
if (!cache.displayed) {
|
||||||
|
container.style.display = "none";
|
||||||
|
this.termsOfUse.style.display = "none";
|
||||||
|
// move ToU far to the left in addition to setting display
|
||||||
|
// to "none", because at the end of the GMap2 load
|
||||||
|
// sequence, display: none will be unset and ToU would be
|
||||||
|
// visible after loading a map with a google layer that is
|
||||||
|
// initially hidden.
|
||||||
|
this.termsOfUse.style.left = "-9999px";
|
||||||
|
this.poweredBy.style.display = "none";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method: getMapContainer
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* {DOMElement} the GMap container's div
|
||||||
|
*/
|
||||||
|
getMapContainer: function() {
|
||||||
|
return this.mapObject.getContainer();
|
||||||
|
},
|
||||||
|
|
||||||
|
//
|
||||||
|
// TRANSLATION: MapObject Bounds <-> OpenLayers.Bounds
|
||||||
|
//
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APIMethod: getMapObjectBoundsFromOLBounds
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* olBounds - {<OpenLayers.Bounds>}
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* {Object} A MapObject Bounds, translated from olBounds
|
||||||
|
* Returns null if null value is passed in
|
||||||
|
*/
|
||||||
|
getMapObjectBoundsFromOLBounds: function(olBounds) {
|
||||||
|
var moBounds = null;
|
||||||
|
if (olBounds != null) {
|
||||||
|
var sw = this.sphericalMercator ?
|
||||||
|
this.inverseMercator(olBounds.bottom, olBounds.left) :
|
||||||
|
new OpenLayers.LonLat(olBounds.bottom, olBounds.left);
|
||||||
|
var ne = this.sphericalMercator ?
|
||||||
|
this.inverseMercator(olBounds.top, olBounds.right) :
|
||||||
|
new OpenLayers.LonLat(olBounds.top, olBounds.right);
|
||||||
|
moBounds = new GLatLngBounds(new GLatLng(sw.lat, sw.lon),
|
||||||
|
new GLatLng(ne.lat, ne.lon));
|
||||||
|
}
|
||||||
|
return moBounds;
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/************************************
|
||||||
|
* *
|
||||||
|
* MapObject Interface Controls *
|
||||||
|
* *
|
||||||
|
************************************/
|
||||||
|
|
||||||
|
|
||||||
|
// Get&Set Center, Zoom
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APIMethod: setMapObjectCenter
|
||||||
|
* Set the mapObject to the specified center and zoom
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* center - {Object} MapObject LonLat format
|
||||||
|
* zoom - {int} MapObject zoom format
|
||||||
|
*/
|
||||||
|
setMapObjectCenter: function(center, zoom) {
|
||||||
|
this.mapObject.setCenter(center, zoom);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APIMethod: dragPanMapObject
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* dX - {Integer}
|
||||||
|
* dY - {Integer}
|
||||||
|
*/
|
||||||
|
dragPanMapObject: function(dX, dY) {
|
||||||
|
this.dragObject.moveBy(new GSize(-dX, dY));
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
// LonLat - Pixel Translation
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APIMethod: getMapObjectLonLatFromMapObjectPixel
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* moPixel - {Object} MapObject Pixel format
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* {Object} MapObject LonLat translated from MapObject Pixel
|
||||||
|
*/
|
||||||
|
getMapObjectLonLatFromMapObjectPixel: function(moPixel) {
|
||||||
|
return this.mapObject.fromContainerPixelToLatLng(moPixel);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APIMethod: getMapObjectPixelFromMapObjectLonLat
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* moLonLat - {Object} MapObject LonLat format
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* {Object} MapObject Pixel transtlated from MapObject LonLat
|
||||||
|
*/
|
||||||
|
getMapObjectPixelFromMapObjectLonLat: function(moLonLat) {
|
||||||
|
return this.mapObject.fromLatLngToContainerPixel(moLonLat);
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
// Bounds
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APIMethod: getMapObjectZoomFromMapObjectBounds
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* moBounds - {Object} MapObject Bounds format
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* {Object} MapObject Zoom for specified MapObject Bounds
|
||||||
|
*/
|
||||||
|
getMapObjectZoomFromMapObjectBounds: function(moBounds) {
|
||||||
|
return this.mapObject.getBoundsZoomLevel(moBounds);
|
||||||
|
},
|
||||||
|
|
||||||
|
/************************************
|
||||||
|
* *
|
||||||
|
* MapObject Primitives *
|
||||||
|
* *
|
||||||
|
************************************/
|
||||||
|
|
||||||
|
|
||||||
|
// LonLat
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APIMethod: getMapObjectLonLatFromLonLat
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* lon - {Float}
|
||||||
|
* lat - {Float}
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* {Object} MapObject LonLat built from lon and lat params
|
||||||
|
*/
|
||||||
|
getMapObjectLonLatFromLonLat: function(lon, lat) {
|
||||||
|
var gLatLng;
|
||||||
|
if(this.sphericalMercator) {
|
||||||
|
var lonlat = this.inverseMercator(lon, lat);
|
||||||
|
gLatLng = new GLatLng(lonlat.lat, lonlat.lon);
|
||||||
|
} else {
|
||||||
|
gLatLng = new GLatLng(lat, lon);
|
||||||
|
}
|
||||||
|
return gLatLng;
|
||||||
|
},
|
||||||
|
|
||||||
|
// Pixel
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APIMethod: getMapObjectPixelFromXY
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* x - {Integer}
|
||||||
|
* y - {Integer}
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* {Object} MapObject Pixel from x and y parameters
|
||||||
|
*/
|
||||||
|
getMapObjectPixelFromXY: function(x, y) {
|
||||||
|
return new GPoint(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
786
lib/OpenLayers/Layer/Google/v3.js
Normal file
786
lib/OpenLayers/Layer/Google/v3.js
Normal file
@@ -0,0 +1,786 @@
|
|||||||
|
/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
|
||||||
|
* license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the
|
||||||
|
* full text of the license. */
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @requires OpenLayers/Layer/Google.js
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constant: OpenLayers.Layer.Google.v3
|
||||||
|
*
|
||||||
|
* Mixin providing functionality specific to the Google Maps API v3. Note that
|
||||||
|
*/
|
||||||
|
OpenLayers.Layer.Google.v3 = {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constant: DEFAULTS
|
||||||
|
* {Object} It is not recommended to change the properties set here. Note
|
||||||
|
* that Google.v3 layers only work when sphericalMercator is set to true.
|
||||||
|
*
|
||||||
|
* (code)
|
||||||
|
* {
|
||||||
|
* maxExtent: new OpenLayers.Bounds(
|
||||||
|
* -128 * 156543.0339,
|
||||||
|
* -128 * 156543.0339,
|
||||||
|
* 128 * 156543.0339,
|
||||||
|
* 128 * 156543.0339
|
||||||
|
* ),
|
||||||
|
* sphericalMercator: true,
|
||||||
|
* maxResolution: 156543.0339,
|
||||||
|
* units: "m",
|
||||||
|
* projection: "EPSG:900913"
|
||||||
|
* }
|
||||||
|
* (end)
|
||||||
|
*/
|
||||||
|
DEFAULTS: {
|
||||||
|
maxExtent: new OpenLayers.Bounds(
|
||||||
|
-128 * 156543.0339,
|
||||||
|
-128 * 156543.0339,
|
||||||
|
128 * 156543.0339,
|
||||||
|
128 * 156543.0339
|
||||||
|
),
|
||||||
|
sphericalMercator: true,
|
||||||
|
maxResolution: 156543.0339,
|
||||||
|
units: "m",
|
||||||
|
projection: "EPSG:900913"
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method: loadMapObject
|
||||||
|
* Load the GMap and register appropriate event listeners. If we can't
|
||||||
|
* load GMap2, then display a warning message.
|
||||||
|
*/
|
||||||
|
loadMapObject:function() {
|
||||||
|
if (!this.type) {
|
||||||
|
this.type = google.maps.MapTypeId.ROADMAP;
|
||||||
|
}
|
||||||
|
var mapObject, termsOfUse, poweredBy;
|
||||||
|
var cache = OpenLayers.Layer.Google.cache[this.map.id];
|
||||||
|
if (cache) {
|
||||||
|
// there are already Google layers added to this map
|
||||||
|
mapObject = cache.mapObject;
|
||||||
|
// increment the layer count
|
||||||
|
++cache.count;
|
||||||
|
} else {
|
||||||
|
// this is the first Google layer for this map
|
||||||
|
|
||||||
|
var container = this.map.viewPortDiv;
|
||||||
|
var div = document.createElement("div");
|
||||||
|
div.id = this.map.id + "_GMapContainer";
|
||||||
|
div.style.position = "absolute";
|
||||||
|
div.style.width = "100%";
|
||||||
|
div.style.height = "100%";
|
||||||
|
container.appendChild(div);
|
||||||
|
|
||||||
|
// create GMap and shuffle elements
|
||||||
|
var center = this.map.getCenter();
|
||||||
|
mapObject = new google.maps.Map(div, {
|
||||||
|
center: center ?
|
||||||
|
new google.maps.LatLng(center.lat, center.lon) :
|
||||||
|
new google.maps.LatLng(0, 0),
|
||||||
|
zoom: this.map.getZoom() || 0,
|
||||||
|
mapTypeId: this.type,
|
||||||
|
disableDefaultUI: true,
|
||||||
|
keyboardShortcuts: false,
|
||||||
|
draggable: false,
|
||||||
|
disableDoubleClickZoom: true,
|
||||||
|
scrollwheel: false
|
||||||
|
});
|
||||||
|
|
||||||
|
// cache elements for use by any other google layers added to
|
||||||
|
// this same map
|
||||||
|
cache = {
|
||||||
|
mapObject: mapObject,
|
||||||
|
count: 1
|
||||||
|
};
|
||||||
|
OpenLayers.Layer.Google.cache[this.map.id] = cache;
|
||||||
|
this.repositionListener = google.maps.event.addListenerOnce(
|
||||||
|
mapObject,
|
||||||
|
"center_changed",
|
||||||
|
OpenLayers.Function.bind(this.repositionMapElements, this)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.mapObject = mapObject;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method: repositionMapElements
|
||||||
|
*
|
||||||
|
* Waits until powered by and terms of use elements are available and then
|
||||||
|
* moves them so they are clickable.
|
||||||
|
*/
|
||||||
|
repositionMapElements: function() {
|
||||||
|
|
||||||
|
// This is the first time any Google layer in this mapObject has been
|
||||||
|
// made visible. The mapObject needs to know the container size.
|
||||||
|
google.maps.event.trigger(this.mapObject, "resize");
|
||||||
|
|
||||||
|
var div = this.mapObject.getDiv().firstChild;
|
||||||
|
if (div.childNodes.length < 3) {
|
||||||
|
this.repositionTimer = window.setTimeout(
|
||||||
|
OpenLayers.Function.bind(this.repositionMapElements, this),
|
||||||
|
250
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var cache = OpenLayers.Layer.Google.cache[this.map.id];
|
||||||
|
var container = this.map.viewPortDiv
|
||||||
|
|
||||||
|
// move the ToS and branding stuff up to the container div
|
||||||
|
var termsOfUse = div.lastChild;
|
||||||
|
container.appendChild(termsOfUse);
|
||||||
|
termsOfUse.style.zIndex = "1100";
|
||||||
|
termsOfUse.style.bottom = "";
|
||||||
|
termsOfUse.className = "olLayerGoogleCopyright olLayerGoogleV3";
|
||||||
|
termsOfUse.style.display = "";
|
||||||
|
cache.termsOfUse = termsOfUse;
|
||||||
|
|
||||||
|
var poweredBy = div.lastChild;
|
||||||
|
container.appendChild(poweredBy);
|
||||||
|
poweredBy.style.zIndex = "1100";
|
||||||
|
poweredBy.style.bottom = "";
|
||||||
|
poweredBy.className = "olLayerGooglePoweredBy olLayerGoogleV3 gmnoprint";
|
||||||
|
poweredBy.style.display = "";
|
||||||
|
cache.poweredBy = poweredBy;
|
||||||
|
|
||||||
|
this.setGMapVisibility(true);
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APIMethod: onMapResize
|
||||||
|
*/
|
||||||
|
onMapResize: function() {
|
||||||
|
if (this.visibility) {
|
||||||
|
google.maps.event.trigger(this.mapObject, "resize");
|
||||||
|
} else {
|
||||||
|
if (!this._resized) {
|
||||||
|
var layer = this;
|
||||||
|
google.maps.event.addListenerOnce(this.mapObject, "tilesloaded", function() {
|
||||||
|
delete layer._resized;
|
||||||
|
google.maps.event.trigger(layer.mapObject, "resize");
|
||||||
|
layer.moveTo(layer.map.getCenter(), layer.map.getZoom());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
this._resized = true;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method: setGMapVisibility
|
||||||
|
* Display the GMap container and associated elements.
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* visible - {Boolean} Display the GMap elements.
|
||||||
|
*/
|
||||||
|
setGMapVisibility: function(visible) {
|
||||||
|
var cache = OpenLayers.Layer.Google.cache[this.map.id];
|
||||||
|
if (cache) {
|
||||||
|
var container = this.mapObject.getDiv();
|
||||||
|
if (visible === true) {
|
||||||
|
this.mapObject.setMapTypeId(this.type);
|
||||||
|
container.style.display = "";
|
||||||
|
if (cache.termsOfUse && cache.termsOfUse.style) {
|
||||||
|
cache.termsOfUse.style.left = "";
|
||||||
|
cache.termsOfUse.style.display = "";
|
||||||
|
cache.poweredBy.style.display = "";
|
||||||
|
}
|
||||||
|
cache.displayed = this.id;
|
||||||
|
} else {
|
||||||
|
if (cache.displayed === this.id) {
|
||||||
|
delete cache.displayed;
|
||||||
|
}
|
||||||
|
if (!cache.displayed) {
|
||||||
|
container.style.display = "none";
|
||||||
|
if (cache.termsOfUse && cache.termsOfUse.style) {
|
||||||
|
cache.termsOfUse.style.display = "none";
|
||||||
|
// move ToU far to the left in addition to setting
|
||||||
|
// display to "none", because at the end of the GMap
|
||||||
|
// load sequence, display: none will be unset and ToU
|
||||||
|
// would be visible after loading a map with a google
|
||||||
|
// layer that is initially hidden.
|
||||||
|
cache.termsOfUse.style.left = "-9999px";
|
||||||
|
cache.poweredBy.style.display = "none";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method: getMapContainer
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* {DOMElement} the GMap container's div
|
||||||
|
*/
|
||||||
|
getMapContainer: function() {
|
||||||
|
return this.mapObject.getDiv();
|
||||||
|
},
|
||||||
|
|
||||||
|
//
|
||||||
|
// TRANSLATION: MapObject Bounds <-> OpenLayers.Bounds
|
||||||
|
//
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APIMethod: getMapObjectBoundsFromOLBounds
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* olBounds - {<OpenLayers.Bounds>}
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* {Object} A MapObject Bounds, translated from olBounds
|
||||||
|
* Returns null if null value is passed in
|
||||||
|
*/
|
||||||
|
getMapObjectBoundsFromOLBounds: function(olBounds) {
|
||||||
|
var moBounds = null;
|
||||||
|
if (olBounds != null) {
|
||||||
|
var sw = this.sphericalMercator ?
|
||||||
|
this.inverseMercator(olBounds.bottom, olBounds.left) :
|
||||||
|
new OpenLayers.LonLat(olBounds.bottom, olBounds.left);
|
||||||
|
var ne = this.sphericalMercator ?
|
||||||
|
this.inverseMercator(olBounds.top, olBounds.right) :
|
||||||
|
new OpenLayers.LonLat(olBounds.top, olBounds.right);
|
||||||
|
moBounds = new google.maps.LatLngBounds(
|
||||||
|
new google.maps.LatLng(sw.lat, sw.lon),
|
||||||
|
new google.maps.LatLng(ne.lat, ne.lon)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return moBounds;
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/************************************
|
||||||
|
* *
|
||||||
|
* MapObject Interface Controls *
|
||||||
|
* *
|
||||||
|
************************************/
|
||||||
|
|
||||||
|
|
||||||
|
// LonLat - Pixel Translation
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APIMethod: getMapObjectLonLatFromMapObjectPixel
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* moPixel - {Object} MapObject Pixel format
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* {Object} MapObject LonLat translated from MapObject Pixel
|
||||||
|
*/
|
||||||
|
getMapObjectLonLatFromMapObjectPixel: function(moPixel) {
|
||||||
|
var size = this.map.getSize();
|
||||||
|
var lon = this.getLongitudeFromMapObjectLonLat(this.mapObject.center);
|
||||||
|
var lat = this.getLatitudeFromMapObjectLonLat(this.mapObject.center);
|
||||||
|
var res = this.map.getResolution();
|
||||||
|
|
||||||
|
var delta_x = moPixel.x - (size.w / 2);
|
||||||
|
var delta_y = moPixel.y - (size.h / 2);
|
||||||
|
|
||||||
|
var lonlat = new OpenLayers.LonLat(
|
||||||
|
lon + delta_x * res,
|
||||||
|
lat - delta_y * res
|
||||||
|
);
|
||||||
|
|
||||||
|
if (this.wrapDateLine) {
|
||||||
|
lonlat = lonlat.wrapDateLine(this.maxExtent);
|
||||||
|
}
|
||||||
|
return this.getMapObjectLonLatFromLonLat(lonlat.lon, lonlat.lat);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APIMethod: getMapObjectPixelFromMapObjectLonLat
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* moLonLat - {Object} MapObject LonLat format
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* {Object} MapObject Pixel transtlated from MapObject LonLat
|
||||||
|
*/
|
||||||
|
getMapObjectPixelFromMapObjectLonLat: function(moLonLat) {
|
||||||
|
var lon = this.getLongitudeFromMapObjectLonLat(moLonLat);
|
||||||
|
var lat = this.getLatitudeFromMapObjectLonLat(moLonLat);
|
||||||
|
var res = this.map.getResolution();
|
||||||
|
var extent = this.map.getExtent();
|
||||||
|
px = new OpenLayers.Pixel(
|
||||||
|
(1/res * (lon - extent.left)),
|
||||||
|
(1/res * (extent.top - lat))
|
||||||
|
);
|
||||||
|
return this.getMapObjectPixelFromXY(px.x, px.y);
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APIMethod: setMapObjectCenter
|
||||||
|
* Set the mapObject to the specified center and zoom
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* center - {Object} MapObject LonLat format
|
||||||
|
* zoom - {int} MapObject zoom format
|
||||||
|
*/
|
||||||
|
setMapObjectCenter: function(center, zoom) {
|
||||||
|
this.mapObject.setOptions({
|
||||||
|
center: center,
|
||||||
|
zoom: zoom
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
// Bounds
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APIMethod: getMapObjectZoomFromMapObjectBounds
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* moBounds - {Object} MapObject Bounds format
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* {Object} MapObject Zoom for specified MapObject Bounds
|
||||||
|
*/
|
||||||
|
getMapObjectZoomFromMapObjectBounds: function(moBounds) {
|
||||||
|
return this.mapObject.getBoundsZoomLevel(moBounds);
|
||||||
|
},
|
||||||
|
|
||||||
|
/************************************
|
||||||
|
* *
|
||||||
|
* MapObject Primitives *
|
||||||
|
* *
|
||||||
|
************************************/
|
||||||
|
|
||||||
|
|
||||||
|
// LonLat
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APIMethod: getMapObjectLonLatFromLonLat
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* lon - {Float}
|
||||||
|
* lat - {Float}
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* {Object} MapObject LonLat built from lon and lat params
|
||||||
|
*/
|
||||||
|
getMapObjectLonLatFromLonLat: function(lon, lat) {
|
||||||
|
var gLatLng;
|
||||||
|
if(this.sphericalMercator) {
|
||||||
|
var lonlat = this.inverseMercator(lon, lat);
|
||||||
|
gLatLng = new google.maps.LatLng(lonlat.lat, lonlat.lon);
|
||||||
|
} else {
|
||||||
|
gLatLng = new google.maps.LatLng(lat, lon);
|
||||||
|
}
|
||||||
|
return gLatLng;
|
||||||
|
},
|
||||||
|
|
||||||
|
// Pixel
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APIMethod: getMapObjectPixelFromXY
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* x - {Integer}
|
||||||
|
* y - {Integer}
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* {Object} MapObject Pixel from x and y parameters
|
||||||
|
*/
|
||||||
|
getMapObjectPixelFromXY: function(x, y) {
|
||||||
|
return new google.maps.Point(x, y);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APIMethod: destroy
|
||||||
|
* Clean up this layer.
|
||||||
|
*/
|
||||||
|
destroy: function() {
|
||||||
|
if (this.repositionListener) {
|
||||||
|
google.maps.event.removeListener(this.repositionListener);
|
||||||
|
}
|
||||||
|
if (this.repositionTimer) {
|
||||||
|
window.clearTimeout(this.repositionTimer);
|
||||||
|
}
|
||||||
|
OpenLayers.Layer.Google.prototype.destroy.apply(this, arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
|
||||||
|
* license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the
|
||||||
|
* full text of the license. */
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @requires OpenLayers/Layer/Google.js
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constant: OpenLayers.Layer.Google.v3
|
||||||
|
*
|
||||||
|
* Mixin providing functionality specific to the Google Maps API v3. Note that
|
||||||
|
*/
|
||||||
|
OpenLayers.Layer.Google.v3 = {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constant: DEFAULTS
|
||||||
|
* {Object} It is not recommended to change the properties set here. Note
|
||||||
|
* that Google.v3 layers only work when sphericalMercator is set to true.
|
||||||
|
*
|
||||||
|
* (code)
|
||||||
|
* {
|
||||||
|
* maxExtent: new OpenLayers.Bounds(
|
||||||
|
* -128 * 156543.0339,
|
||||||
|
* -128 * 156543.0339,
|
||||||
|
* 128 * 156543.0339,
|
||||||
|
* 128 * 156543.0339
|
||||||
|
* ),
|
||||||
|
* sphericalMercator: true,
|
||||||
|
* maxResolution: 156543.0339,
|
||||||
|
* units: "m",
|
||||||
|
* projection: "EPSG:900913"
|
||||||
|
* }
|
||||||
|
* (end)
|
||||||
|
*/
|
||||||
|
DEFAULTS: {
|
||||||
|
maxExtent: new OpenLayers.Bounds(
|
||||||
|
-128 * 156543.0339,
|
||||||
|
-128 * 156543.0339,
|
||||||
|
128 * 156543.0339,
|
||||||
|
128 * 156543.0339
|
||||||
|
),
|
||||||
|
sphericalMercator: true,
|
||||||
|
maxResolution: 156543.0339,
|
||||||
|
units: "m",
|
||||||
|
projection: "EPSG:900913"
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method: loadMapObject
|
||||||
|
* Load the GMap and register appropriate event listeners. If we can't
|
||||||
|
* load GMap2, then display a warning message.
|
||||||
|
*/
|
||||||
|
loadMapObject:function() {
|
||||||
|
if (!this.type) {
|
||||||
|
this.type = google.maps.MapTypeId.ROADMAP;
|
||||||
|
}
|
||||||
|
var mapObject, termsOfUse, poweredBy;
|
||||||
|
var cache = OpenLayers.Layer.Google.cache[this.map.id];
|
||||||
|
if (cache) {
|
||||||
|
// there are already Google layers added to this map
|
||||||
|
mapObject = cache.mapObject;
|
||||||
|
// increment the layer count
|
||||||
|
++cache.count;
|
||||||
|
} else {
|
||||||
|
// this is the first Google layer for this map
|
||||||
|
|
||||||
|
var container = this.map.viewPortDiv;
|
||||||
|
var div = document.createElement("div");
|
||||||
|
div.id = this.map.id + "_GMapContainer";
|
||||||
|
div.style.position = "absolute";
|
||||||
|
div.style.width = "100%";
|
||||||
|
div.style.height = "100%";
|
||||||
|
container.appendChild(div);
|
||||||
|
|
||||||
|
// create GMap and shuffle elements
|
||||||
|
var center = this.map.getCenter();
|
||||||
|
mapObject = new google.maps.Map(div, {
|
||||||
|
center: center ?
|
||||||
|
new google.maps.LatLng(center.lat, center.lon) :
|
||||||
|
new google.maps.LatLng(0, 0),
|
||||||
|
zoom: this.map.getZoom() || 0,
|
||||||
|
mapTypeId: this.type,
|
||||||
|
disableDefaultUI: true,
|
||||||
|
keyboardShortcuts: false,
|
||||||
|
draggable: false,
|
||||||
|
disableDoubleClickZoom: true,
|
||||||
|
scrollwheel: false
|
||||||
|
});
|
||||||
|
|
||||||
|
// cache elements for use by any other google layers added to
|
||||||
|
// this same map
|
||||||
|
cache = {
|
||||||
|
mapObject: mapObject,
|
||||||
|
count: 1
|
||||||
|
};
|
||||||
|
OpenLayers.Layer.Google.cache[this.map.id] = cache;
|
||||||
|
var layer = this;
|
||||||
|
this._googleOnIdle = google.maps.event.addListenerOnce(mapObject, "idle", function() {
|
||||||
|
var div = mapObject.getDiv().firstChild;
|
||||||
|
|
||||||
|
// move the ToS and branding stuff up to the container div
|
||||||
|
var termsOfUse = div.lastChild;
|
||||||
|
container.appendChild(termsOfUse);
|
||||||
|
termsOfUse.style.zIndex = "1100";
|
||||||
|
termsOfUse.style.bottom = "";
|
||||||
|
termsOfUse.className = "olLayerGoogleCopyright olLayerGoogleV3";
|
||||||
|
cache.termsOfUse = termsOfUse;
|
||||||
|
|
||||||
|
var poweredBy = div.lastChild;
|
||||||
|
container.appendChild(poweredBy);
|
||||||
|
poweredBy.style.zIndex = "1100";
|
||||||
|
poweredBy.style.bottom = "";
|
||||||
|
poweredBy.className = "olLayerGooglePoweredBy olLayerGoogleV3 gmnoprint";
|
||||||
|
cache.poweredBy = poweredBy;
|
||||||
|
|
||||||
|
layer.setGMapVisibility(layer.div.style.display !== "none");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
this.mapObject = mapObject;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APIMethod: onMapResize
|
||||||
|
*/
|
||||||
|
onMapResize: function() {
|
||||||
|
// workaround for resizing of invisible or not yet fully loaded layers
|
||||||
|
// where GMap2.checkResize() does not work. We need to load the GMap
|
||||||
|
// for the old div size, then checkResize(), and then call
|
||||||
|
// layer.moveTo() to trigger GMap.setCenter() (which will finish
|
||||||
|
// the GMap initialization).
|
||||||
|
if(this.visibility) {
|
||||||
|
google.maps.event.trigger(this.mapObject, 'resize');
|
||||||
|
} else {
|
||||||
|
if(!this._resized) {
|
||||||
|
var layer = this;
|
||||||
|
google.maps.event.addListenerOnce(this.mapObject, "tilesloaded", function() {
|
||||||
|
delete layer._resized;
|
||||||
|
google.maps.event.trigger(layer.mapObject, 'resize');
|
||||||
|
layer.moveTo(layer.map.getCenter(), layer.map.getZoom());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
this._resized = true;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method: setGMapVisibility
|
||||||
|
* Display the GMap container and associated elements.
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* visible - {Boolean} Display the GMap elements.
|
||||||
|
*/
|
||||||
|
setGMapVisibility: function(visible) {
|
||||||
|
var cache = OpenLayers.Layer.Google.cache[this.map.id];
|
||||||
|
if (cache) {
|
||||||
|
var container = this.mapObject.getDiv();
|
||||||
|
if (visible === true) {
|
||||||
|
this.mapObject.setMapTypeId(this.type);
|
||||||
|
container.style.display = "";
|
||||||
|
if(cache.termsOfUse) {
|
||||||
|
cache.termsOfUse.style.left = "";
|
||||||
|
cache.termsOfUse.style.display = "";
|
||||||
|
cache.poweredBy.style.display = "";
|
||||||
|
}
|
||||||
|
cache.displayed = this.id;
|
||||||
|
} else {
|
||||||
|
if (cache.displayed === this.id) {
|
||||||
|
delete cache.displayed;
|
||||||
|
}
|
||||||
|
if (!cache.displayed) {
|
||||||
|
container.style.display = "none";
|
||||||
|
if(cache.termsOfUse) {
|
||||||
|
cache.termsOfUse.style.display = "none";
|
||||||
|
// move ToU far to the left in addition to setting
|
||||||
|
// display to "none", because at the end of the GMap
|
||||||
|
// load sequence, display: none will be unset and ToU
|
||||||
|
// would be visible after loading a map with a google
|
||||||
|
// layer that is initially hidden.
|
||||||
|
cache.termsOfUse.style.left = "-9999px";
|
||||||
|
cache.poweredBy.style.display = "none";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method: getMapContainer
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* {DOMElement} the GMap container's div
|
||||||
|
*/
|
||||||
|
getMapContainer: function() {
|
||||||
|
return this.mapObject.getDiv();
|
||||||
|
},
|
||||||
|
|
||||||
|
//
|
||||||
|
// TRANSLATION: MapObject Bounds <-> OpenLayers.Bounds
|
||||||
|
//
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APIMethod: getMapObjectBoundsFromOLBounds
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* olBounds - {<OpenLayers.Bounds>}
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* {Object} A MapObject Bounds, translated from olBounds
|
||||||
|
* Returns null if null value is passed in
|
||||||
|
*/
|
||||||
|
getMapObjectBoundsFromOLBounds: function(olBounds) {
|
||||||
|
var moBounds = null;
|
||||||
|
if (olBounds != null) {
|
||||||
|
var sw = this.sphericalMercator ?
|
||||||
|
this.inverseMercator(olBounds.bottom, olBounds.left) :
|
||||||
|
new OpenLayers.LonLat(olBounds.bottom, olBounds.left);
|
||||||
|
var ne = this.sphericalMercator ?
|
||||||
|
this.inverseMercator(olBounds.top, olBounds.right) :
|
||||||
|
new OpenLayers.LonLat(olBounds.top, olBounds.right);
|
||||||
|
moBounds = new google.maps.LatLngBounds(
|
||||||
|
new google.maps.LatLng(sw.lat, sw.lon),
|
||||||
|
new google.maps.LatLng(ne.lat, ne.lon)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return moBounds;
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/************************************
|
||||||
|
* *
|
||||||
|
* MapObject Interface Controls *
|
||||||
|
* *
|
||||||
|
************************************/
|
||||||
|
|
||||||
|
|
||||||
|
// LonLat - Pixel Translation
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APIMethod: getMapObjectLonLatFromMapObjectPixel
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* moPixel - {Object} MapObject Pixel format
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* {Object} MapObject LonLat translated from MapObject Pixel
|
||||||
|
*/
|
||||||
|
getMapObjectLonLatFromMapObjectPixel: function(moPixel) {
|
||||||
|
var size = this.map.getSize();
|
||||||
|
var lon = this.getLongitudeFromMapObjectLonLat(this.mapObject.center);
|
||||||
|
var lat = this.getLatitudeFromMapObjectLonLat(this.mapObject.center);
|
||||||
|
var res = this.map.getResolution();
|
||||||
|
|
||||||
|
var delta_x = moPixel.x - (size.w / 2);
|
||||||
|
var delta_y = moPixel.y - (size.h / 2);
|
||||||
|
|
||||||
|
var lonlat = new OpenLayers.LonLat(
|
||||||
|
lon + delta_x * res,
|
||||||
|
lat - delta_y * res
|
||||||
|
);
|
||||||
|
|
||||||
|
if (this.wrapDateLine) {
|
||||||
|
lonlat = lonlat.wrapDateLine(this.maxExtent);
|
||||||
|
}
|
||||||
|
return this.getMapObjectLonLatFromLonLat(lonlat.lon, lonlat.lat);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APIMethod: getMapObjectPixelFromMapObjectLonLat
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* moLonLat - {Object} MapObject LonLat format
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* {Object} MapObject Pixel transtlated from MapObject LonLat
|
||||||
|
*/
|
||||||
|
getMapObjectPixelFromMapObjectLonLat: function(moLonLat) {
|
||||||
|
var lon = this.getLongitudeFromMapObjectLonLat(moLonLat);
|
||||||
|
var lat = this.getLatitudeFromMapObjectLonLat(moLonLat);
|
||||||
|
var res = this.map.getResolution();
|
||||||
|
var extent = this.map.getExtent();
|
||||||
|
px = new OpenLayers.Pixel(
|
||||||
|
(1/res * (lon - extent.left)),
|
||||||
|
(1/res * (extent.top - lat))
|
||||||
|
);
|
||||||
|
return this.getMapObjectPixelFromXY(px.x, px.y);
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APIMethod: setMapObjectCenter
|
||||||
|
* Set the mapObject to the specified center and zoom
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* center - {Object} MapObject LonLat format
|
||||||
|
* zoom - {int} MapObject zoom format
|
||||||
|
*/
|
||||||
|
setMapObjectCenter: function(center, zoom) {
|
||||||
|
this.mapObject.setOptions({
|
||||||
|
center: center,
|
||||||
|
zoom: zoom
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
// Bounds
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APIMethod: getMapObjectZoomFromMapObjectBounds
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* moBounds - {Object} MapObject Bounds format
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* {Object} MapObject Zoom for specified MapObject Bounds
|
||||||
|
*/
|
||||||
|
getMapObjectZoomFromMapObjectBounds: function(moBounds) {
|
||||||
|
return this.mapObject.getBoundsZoomLevel(moBounds);
|
||||||
|
},
|
||||||
|
|
||||||
|
/************************************
|
||||||
|
* *
|
||||||
|
* MapObject Primitives *
|
||||||
|
* *
|
||||||
|
************************************/
|
||||||
|
|
||||||
|
|
||||||
|
// LonLat
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APIMethod: getMapObjectLonLatFromLonLat
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* lon - {Float}
|
||||||
|
* lat - {Float}
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* {Object} MapObject LonLat built from lon and lat params
|
||||||
|
*/
|
||||||
|
getMapObjectLonLatFromLonLat: function(lon, lat) {
|
||||||
|
var gLatLng;
|
||||||
|
if(this.sphericalMercator) {
|
||||||
|
var lonlat = this.inverseMercator(lon, lat);
|
||||||
|
gLatLng = new google.maps.LatLng(lonlat.lat, lonlat.lon);
|
||||||
|
} else {
|
||||||
|
gLatLng = new google.maps.LatLng(lat, lon);
|
||||||
|
}
|
||||||
|
return gLatLng;
|
||||||
|
},
|
||||||
|
|
||||||
|
// Pixel
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APIMethod: getMapObjectPixelFromXY
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* x - {Integer}
|
||||||
|
* y - {Integer}
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* {Object} MapObject Pixel from x and y parameters
|
||||||
|
*/
|
||||||
|
getMapObjectPixelFromXY: function(x, y) {
|
||||||
|
return new google.maps.Point(x, y);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APIMethod: destroy
|
||||||
|
* Clean up this layer.
|
||||||
|
*/
|
||||||
|
destroy: function() {
|
||||||
|
this._googleOnIdle &&
|
||||||
|
google.maps.event.removeListener(this._googleOnIdle);
|
||||||
|
OpenLayers.Layer.Google.prototype.destroy.apply(this, arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
448
tests/Layer/Google/v3.html
Normal file
448
tests/Layer/Google/v3.html
Normal file
@@ -0,0 +1,448 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<script src="http://maps.google.com/maps/api/js?sensor=false"></script>
|
||||||
|
<script src="../../../lib/OpenLayers.js"></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
var layer;
|
||||||
|
|
||||||
|
function test_Layer_Google_constructor (t) {
|
||||||
|
t.plan( 5 );
|
||||||
|
|
||||||
|
var map = new OpenLayers.Map('map');
|
||||||
|
var layer = new OpenLayers.Layer.Google('Goog Layer');
|
||||||
|
map.addLayer(layer);
|
||||||
|
|
||||||
|
|
||||||
|
t.ok( layer instanceof OpenLayers.Layer.Google, "new OpenLayers.Layer.Google returns object" );
|
||||||
|
t.eq( layer.CLASS_NAME, "OpenLayers.Layer.Google", "CLASS_NAME variable set correctly");
|
||||||
|
|
||||||
|
t.eq( layer.name, "Goog Layer", "layer.name is correct" );
|
||||||
|
|
||||||
|
t.ok ( layer.mapObject != null, "GMap Object correctly loaded");
|
||||||
|
|
||||||
|
t.eq(layer.version, "3", "API version 3 detected.");
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_clone(t) {
|
||||||
|
t.plan(2);
|
||||||
|
var layer, clone;
|
||||||
|
|
||||||
|
// test default layer
|
||||||
|
layer = new OpenLayers.Layer.Google();
|
||||||
|
clone = layer.clone();
|
||||||
|
t.ok(clone instanceof OpenLayers.Layer.Google, "[default] good instance");
|
||||||
|
|
||||||
|
layer.destroy();
|
||||||
|
clone.destroy();
|
||||||
|
|
||||||
|
// test with alt type
|
||||||
|
layer = new OpenLayers.Layer.Google(null, {type: google.maps.MapTypeId.SATELLITE});
|
||||||
|
clone = layer.clone();
|
||||||
|
t.ok(clone.type === google.maps.MapTypeId.SATELLITE, "[sat] correct type");
|
||||||
|
|
||||||
|
layer.destroy();
|
||||||
|
clone.destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_Layer_Google_isBaseLayer (t) {
|
||||||
|
t.plan(1);
|
||||||
|
|
||||||
|
var layer = new OpenLayers.Layer.Google('Goog Layer');
|
||||||
|
|
||||||
|
t.ok(layer.isBaseLayer, "a default load of google layer responds as a base layer");
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_Layer_Google_Translation_lonlat (t) {
|
||||||
|
t.plan( 4 );
|
||||||
|
|
||||||
|
var map = new OpenLayers.Map('map');
|
||||||
|
var layer = new OpenLayers.Layer.Google('Goog Layer');
|
||||||
|
map.addLayer(layer);
|
||||||
|
|
||||||
|
// these two lines specify an appropriate translation.
|
||||||
|
// the code afterwards works by itself to test that translation
|
||||||
|
// works correctly both ways.
|
||||||
|
var gLatLng = new google.maps.LatLng(50,100);
|
||||||
|
// v3 uses sphericalMercator by default
|
||||||
|
var correspondingOLLonLat = new OpenLayers.LonLat(100,50).transform(
|
||||||
|
new OpenLayers.Projection("EPSG:4326"),
|
||||||
|
map.getProjectionObject()
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
olLonLat = layer.getOLLonLatFromMapObjectLonLat(gLatLng);
|
||||||
|
t.ok(olLonLat.equals(correspondingOLLonLat), "Translation from GLatLng to OpenLayers.LonLat works");
|
||||||
|
|
||||||
|
var transGLatLng = layer.getMapObjectLonLatFromOLLonLat(olLonLat);
|
||||||
|
t.ok( transGLatLng.equals(gLatLng), "Translation from OpenLayers.LonLat to GLatLng works");
|
||||||
|
|
||||||
|
t.ok( layer.getMapObjectLonLatFromOLLonLat(null) == null, "getGLatLngFromOLLonLat(null) returns null");
|
||||||
|
t.ok( layer.getOLLonLatFromMapObjectLonLat(null) == null, "getOLLonLatFromGLatLng(null) returns null");
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_Layer_Google_Translation_pixel (t) {
|
||||||
|
t.plan( 4 );
|
||||||
|
|
||||||
|
var map = new OpenLayers.Map('map');
|
||||||
|
var layer = new OpenLayers.Layer.Google('Goog Layer');
|
||||||
|
map.addLayer(layer);
|
||||||
|
|
||||||
|
// these two lines specify an appropriate translation.
|
||||||
|
// the code afterwards works by itself to test that translation
|
||||||
|
// works correctly both ways.
|
||||||
|
var gPoint = new google.maps.Point(50,100);
|
||||||
|
var correspondingOLPixel = new OpenLayers.Pixel(50, 100);
|
||||||
|
|
||||||
|
|
||||||
|
olPixel = layer.getOLPixelFromMapObjectPixel(gPoint);
|
||||||
|
t.ok( olPixel.equals(correspondingOLPixel), "Translation from GPoint to OpenLayers.Pixel works");
|
||||||
|
|
||||||
|
var transGPoint = layer.getMapObjectPixelFromOLPixel(olPixel);
|
||||||
|
t.ok( transGPoint.equals(gPoint), "Translation from OpenLayers.Pixel to GPoint works");
|
||||||
|
|
||||||
|
t.ok( layer.getMapObjectPixelFromOLPixel(null) == null, "getGPointFromOLPixel(null) returns null");
|
||||||
|
t.ok( layer.getOLPixelFromMapObjectPixel(null) == null, "getOLPixelFromGPoint(null) returns null");
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_Layer_destroy (t) {
|
||||||
|
t.plan( 5 );
|
||||||
|
|
||||||
|
var map = new OpenLayers.Map('map');
|
||||||
|
|
||||||
|
layer = new OpenLayers.Layer.Google('Test Layer');
|
||||||
|
map.addLayer(layer);
|
||||||
|
|
||||||
|
layer.destroy();
|
||||||
|
|
||||||
|
t.eq( layer.name, null, "layer.name is null after destroy" );
|
||||||
|
t.eq( layer.div, null, "layer.div is null after destroy" );
|
||||||
|
t.eq( layer.map, null, "layer.map is null after destroy" );
|
||||||
|
t.eq( layer.options, null, "layer.options is null after destroy" );
|
||||||
|
t.eq( layer.gmap, null, "layer.gmap is null after destroy" );
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_Layer_Goole_forwardMercator(t){
|
||||||
|
t.plan(2);
|
||||||
|
//Just test that the fowardMercator function still exists.
|
||||||
|
var layer = new OpenLayers.Layer.Google('Test Layer', {'sphericalMercator': true});
|
||||||
|
layer.forwardMercator = function(evt) {
|
||||||
|
t.ok(true,
|
||||||
|
"GoogleMercator.forwardMercator was called and executed." );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
layer.forwardMercator();
|
||||||
|
//Now test the fowardMercator returns the expected LonLat object
|
||||||
|
var layer = new OpenLayers.Layer.Google('Test Layer', {'sphericalMercator': true});
|
||||||
|
var lonlat2 = new OpenLayers.LonLat(Math.random(),Math.random());
|
||||||
|
var result = layer.forwardMercator(lonlat2.lon, lonlat2.lat);
|
||||||
|
t.ok(result instanceof OpenLayers.LonLat, "OpenLayers.Google.fowardMercator returns LonLat object" );
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_Layer_Google_overlay(t) {
|
||||||
|
// Test for #849.
|
||||||
|
t.plan(1);
|
||||||
|
var map = new OpenLayers.Map( 'map' ,
|
||||||
|
{ controls: [] , 'numZoomLevels':20});
|
||||||
|
|
||||||
|
var satellite = new OpenLayers.Layer.Google( "Google Satellite" , {type: google.maps.MapTypeId.SATELLITE, 'maxZoomLevel':18} );
|
||||||
|
var layer = new OpenLayers.Layer.WMS.Untiled( "OpenLayers WMS",
|
||||||
|
"http://labs.metacarta.com/wms/vmap0", {layers: 'basic', 'transparent':true},
|
||||||
|
{isBaseLayer: false} );
|
||||||
|
|
||||||
|
map.addLayers([satellite, layer]);
|
||||||
|
map.setCenter(new OpenLayers.LonLat(10.205188,48.857593), 5);
|
||||||
|
map.zoomIn();
|
||||||
|
var size = map.getSize();
|
||||||
|
var px = new OpenLayers.Pixel(size.w, size.h);
|
||||||
|
var br = map.getLonLatFromPixel(px);
|
||||||
|
t.ok(layer.grid[0][0].bounds.containsLonLat(br), "Bottom right pixel is covered by untiled WMS layer");
|
||||||
|
}
|
||||||
|
function test_Layer_Google_isBaseLayer (t) {
|
||||||
|
t.plan(3);
|
||||||
|
var map = new OpenLayers.Map( 'map' ,
|
||||||
|
{ controls: [] , 'numZoomLevels':20});
|
||||||
|
|
||||||
|
var satellite = new OpenLayers.Layer.Google( "Google Satellite" , {type: google.maps.MapTypeId.SATELLITE, 'maxZoomLevel':18} );
|
||||||
|
map.addLayers([satellite]);
|
||||||
|
map.zoomToMaxExtent();
|
||||||
|
|
||||||
|
t.eq(satellite.div.style.display, "", "Satellite layer is visible.");
|
||||||
|
satellite.setVisibility(false);
|
||||||
|
t.eq(satellite.div.style.display, "none", "Satellite layer is not visible.");
|
||||||
|
satellite.setVisibility(true);
|
||||||
|
t.eq(satellite.div.style.display, "block", "Satellite layer is visible.");
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_Layer_Google_setGMapVisibility(t) {
|
||||||
|
t.plan(4);
|
||||||
|
|
||||||
|
var map = new OpenLayers.Map('map');
|
||||||
|
var gmap = new OpenLayers.Layer.Google("Google Streets");
|
||||||
|
var dummy = new OpenLayers.Layer("Dummy", {isBaseLayer: true});
|
||||||
|
map.addLayers([dummy, gmap]);
|
||||||
|
map.zoomToMaxExtent();
|
||||||
|
|
||||||
|
// In v3, the terms of use and powered by elements are not available
|
||||||
|
// until the layer loads. This can occur before the layer is visible,
|
||||||
|
// but we don't try to access these elements until after the layer is
|
||||||
|
// made visible for the first time.
|
||||||
|
var cache = OpenLayers.Layer.Google.cache[map.id];
|
||||||
|
t.ok(!cache.termsOfUse, "termsOfUse is not yet cached");
|
||||||
|
t.ok(!cache.poweredBy, "poweredBy is not yet cached");
|
||||||
|
|
||||||
|
map.setBaseLayer(gmap);
|
||||||
|
t.delay_call(4, function() {
|
||||||
|
var cache = OpenLayers.Layer.Google.cache[map.id];
|
||||||
|
t.eq(cache.termsOfUse.style.display, "", "termsOfUse is visible");
|
||||||
|
t.eq(cache.poweredBy.style.display, "", "poweredBy is visible");
|
||||||
|
map.destroy();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_Layer_Google_setGMapVisibility_allOverlays(t) {
|
||||||
|
t.plan(4);
|
||||||
|
|
||||||
|
var map = new OpenLayers.Map('map', {allOverlays: true});
|
||||||
|
var gmap = new OpenLayers.Layer.Google("Google Streets", {visibility: false});
|
||||||
|
var dummy = new OpenLayers.Layer("Dummy");
|
||||||
|
map.addLayers([gmap, dummy]);
|
||||||
|
map.zoomToMaxExtent();
|
||||||
|
|
||||||
|
// In v3, the terms of use and powered by elements are not available
|
||||||
|
// until the layer loads. This can occur before the layer is visible,
|
||||||
|
// but we don't try to access these elements until after the layer is
|
||||||
|
// made visible for the first time.
|
||||||
|
var cache = OpenLayers.Layer.Google.cache[map.id];
|
||||||
|
t.ok(!cache.termsOfUse, "termsOfUse is not yet cached");
|
||||||
|
t.ok(!cache.poweredBy, "poweredBy is not yet cached");
|
||||||
|
|
||||||
|
gmap.setVisibility(true);
|
||||||
|
t.delay_call(4, function() {
|
||||||
|
var cache = OpenLayers.Layer.Google.cache[map.id];
|
||||||
|
t.eq(cache.termsOfUse.style.display, "", "termsOfUse is visible");
|
||||||
|
t.eq(cache.poweredBy.style.display, "", "poweredBy is visible");
|
||||||
|
map.destroy();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="map" style="width:500px; height: 500px"></div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<script src="http://maps.google.com/maps/api/js?sensor=false"></script>
|
||||||
|
<script src="../../../lib/OpenLayers.js"></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
var layer;
|
||||||
|
|
||||||
|
function test_Layer_Google_constructor (t) {
|
||||||
|
t.plan( 5 );
|
||||||
|
|
||||||
|
var map = new OpenLayers.Map('map');
|
||||||
|
var layer = new OpenLayers.Layer.Google('Goog Layer');
|
||||||
|
map.addLayer(layer);
|
||||||
|
|
||||||
|
|
||||||
|
t.ok( layer instanceof OpenLayers.Layer.Google, "new OpenLayers.Layer.Google returns object" );
|
||||||
|
t.eq( layer.CLASS_NAME, "OpenLayers.Layer.Google", "CLASS_NAME variable set correctly");
|
||||||
|
|
||||||
|
t.eq( layer.name, "Goog Layer", "layer.name is correct" );
|
||||||
|
|
||||||
|
t.ok ( layer.mapObject != null, "GMap Object correctly loaded");
|
||||||
|
|
||||||
|
t.eq(layer.version, "3", "API version 3 detected.");
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_clone(t) {
|
||||||
|
t.plan(2);
|
||||||
|
var layer, clone;
|
||||||
|
|
||||||
|
// test default layer
|
||||||
|
layer = new OpenLayers.Layer.Google();
|
||||||
|
clone = layer.clone();
|
||||||
|
t.ok(clone instanceof OpenLayers.Layer.Google, "[default] good instance");
|
||||||
|
|
||||||
|
layer.destroy();
|
||||||
|
clone.destroy();
|
||||||
|
|
||||||
|
// test with alt type
|
||||||
|
layer = new OpenLayers.Layer.Google(null, {type: google.maps.MapTypeId.SATELLITE});
|
||||||
|
clone = layer.clone();
|
||||||
|
t.ok(clone.type === google.maps.MapTypeId.SATELLITE, "[sat] correct type");
|
||||||
|
|
||||||
|
layer.destroy();
|
||||||
|
clone.destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_Layer_Google_isBaseLayer (t) {
|
||||||
|
t.plan(1);
|
||||||
|
|
||||||
|
var layer = new OpenLayers.Layer.Google('Goog Layer');
|
||||||
|
|
||||||
|
t.ok(layer.isBaseLayer, "a default load of google layer responds as a base layer");
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_Layer_Google_Translation_lonlat (t) {
|
||||||
|
t.plan( 4 );
|
||||||
|
|
||||||
|
var map = new OpenLayers.Map('map');
|
||||||
|
var layer = new OpenLayers.Layer.Google('Goog Layer');
|
||||||
|
map.addLayer(layer);
|
||||||
|
|
||||||
|
// these two lines specify an appropriate translation.
|
||||||
|
// the code afterwards works by itself to test that translation
|
||||||
|
// works correctly both ways.
|
||||||
|
var gLatLng = new google.maps.LatLng(50,100);
|
||||||
|
// v3 uses sphericalMercator by default
|
||||||
|
var correspondingOLLonLat = new OpenLayers.LonLat(100,50).transform(
|
||||||
|
new OpenLayers.Projection("EPSG:4326"),
|
||||||
|
map.getProjectionObject()
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
olLonLat = layer.getOLLonLatFromMapObjectLonLat(gLatLng);
|
||||||
|
t.ok(olLonLat.equals(correspondingOLLonLat), "Translation from GLatLng to OpenLayers.LonLat works");
|
||||||
|
|
||||||
|
var transGLatLng = layer.getMapObjectLonLatFromOLLonLat(olLonLat);
|
||||||
|
t.ok( transGLatLng.equals(gLatLng), "Translation from OpenLayers.LonLat to GLatLng works");
|
||||||
|
|
||||||
|
t.ok( layer.getMapObjectLonLatFromOLLonLat(null) == null, "getGLatLngFromOLLonLat(null) returns null");
|
||||||
|
t.ok( layer.getOLLonLatFromMapObjectLonLat(null) == null, "getOLLonLatFromGLatLng(null) returns null");
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_Layer_Google_Translation_pixel (t) {
|
||||||
|
t.plan( 4 );
|
||||||
|
|
||||||
|
var map = new OpenLayers.Map('map');
|
||||||
|
var layer = new OpenLayers.Layer.Google('Goog Layer');
|
||||||
|
map.addLayer(layer);
|
||||||
|
|
||||||
|
// these two lines specify an appropriate translation.
|
||||||
|
// the code afterwards works by itself to test that translation
|
||||||
|
// works correctly both ways.
|
||||||
|
var gPoint = new google.maps.Point(50,100);
|
||||||
|
var correspondingOLPixel = new OpenLayers.Pixel(50, 100);
|
||||||
|
|
||||||
|
|
||||||
|
olPixel = layer.getOLPixelFromMapObjectPixel(gPoint);
|
||||||
|
t.ok( olPixel.equals(correspondingOLPixel), "Translation from GPoint to OpenLayers.Pixel works");
|
||||||
|
|
||||||
|
var transGPoint = layer.getMapObjectPixelFromOLPixel(olPixel);
|
||||||
|
t.ok( transGPoint.equals(gPoint), "Translation from OpenLayers.Pixel to GPoint works");
|
||||||
|
|
||||||
|
t.ok( layer.getMapObjectPixelFromOLPixel(null) == null, "getGPointFromOLPixel(null) returns null");
|
||||||
|
t.ok( layer.getOLPixelFromMapObjectPixel(null) == null, "getOLPixelFromGPoint(null) returns null");
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_Layer_destroy (t) {
|
||||||
|
t.plan( 5 );
|
||||||
|
|
||||||
|
var map = new OpenLayers.Map('map');
|
||||||
|
|
||||||
|
layer = new OpenLayers.Layer.Google('Test Layer');
|
||||||
|
map.addLayer(layer);
|
||||||
|
|
||||||
|
layer.destroy();
|
||||||
|
|
||||||
|
t.eq( layer.name, null, "layer.name is null after destroy" );
|
||||||
|
t.eq( layer.div, null, "layer.div is null after destroy" );
|
||||||
|
t.eq( layer.map, null, "layer.map is null after destroy" );
|
||||||
|
t.eq( layer.options, null, "layer.options is null after destroy" );
|
||||||
|
t.eq( layer.gmap, null, "layer.gmap is null after destroy" );
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_Layer_Goole_forwardMercator(t){
|
||||||
|
t.plan(2);
|
||||||
|
//Just test that the fowardMercator function still exists.
|
||||||
|
var layer = new OpenLayers.Layer.Google('Test Layer', {'sphericalMercator': true});
|
||||||
|
layer.forwardMercator = function(evt) {
|
||||||
|
t.ok(true,
|
||||||
|
"GoogleMercator.forwardMercator was called and executed." );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
layer.forwardMercator();
|
||||||
|
//Now test the fowardMercator returns the expected LonLat object
|
||||||
|
var layer = new OpenLayers.Layer.Google('Test Layer', {'sphericalMercator': true});
|
||||||
|
var lonlat2 = new OpenLayers.LonLat(Math.random(),Math.random());
|
||||||
|
var result = layer.forwardMercator(lonlat2.lon, lonlat2.lat);
|
||||||
|
t.ok(result instanceof OpenLayers.LonLat, "OpenLayers.Google.fowardMercator returns LonLat object" );
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_Layer_Google_overlay(t) {
|
||||||
|
// Test for #849.
|
||||||
|
t.plan(1);
|
||||||
|
var map = new OpenLayers.Map( 'map' ,
|
||||||
|
{ controls: [] , 'numZoomLevels':20});
|
||||||
|
|
||||||
|
var satellite = new OpenLayers.Layer.Google( "Google Satellite" , {type: google.maps.MapTypeId.SATELLITE, 'maxZoomLevel':18} );
|
||||||
|
var layer = new OpenLayers.Layer.WMS.Untiled( "OpenLayers WMS",
|
||||||
|
"http://labs.metacarta.com/wms/vmap0", {layers: 'basic', 'transparent':true},
|
||||||
|
{isBaseLayer: false} );
|
||||||
|
|
||||||
|
map.addLayers([satellite, layer]);
|
||||||
|
map.setCenter(new OpenLayers.LonLat(10.205188,48.857593), 5);
|
||||||
|
map.zoomIn();
|
||||||
|
var size = map.getSize();
|
||||||
|
var px = new OpenLayers.Pixel(size.w, size.h);
|
||||||
|
var br = map.getLonLatFromPixel(px);
|
||||||
|
t.ok(layer.grid[0][0].bounds.containsLonLat(br), "Bottom right pixel is covered by untiled WMS layer");
|
||||||
|
}
|
||||||
|
function test_Layer_Google_isBaseLayer (t) {
|
||||||
|
t.plan(3);
|
||||||
|
var map = new OpenLayers.Map( 'map' ,
|
||||||
|
{ controls: [] , 'numZoomLevels':20});
|
||||||
|
|
||||||
|
var satellite = new OpenLayers.Layer.Google( "Google Satellite" , {type: google.maps.MapTypeId.SATELLITE, 'maxZoomLevel':18} );
|
||||||
|
map.addLayers([satellite]);
|
||||||
|
map.zoomToMaxExtent();
|
||||||
|
|
||||||
|
t.eq(satellite.div.style.display, "", "Satellite layer is visible.");
|
||||||
|
satellite.setVisibility(false);
|
||||||
|
t.eq(satellite.div.style.display, "none", "Satellite layer is not visible.");
|
||||||
|
satellite.setVisibility(true);
|
||||||
|
t.eq(satellite.div.style.display, "block", "Satellite layer is visible.");
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_Layer_Google_setGMapVisibility(t) {
|
||||||
|
t.plan(2);
|
||||||
|
|
||||||
|
var map = new OpenLayers.Map('map');
|
||||||
|
var gmap = new OpenLayers.Layer.Google("Google Streets");
|
||||||
|
var dummy = new OpenLayers.Layer("Dummy", {isBaseLayer: true});
|
||||||
|
map.addLayers([dummy, gmap]);
|
||||||
|
map.zoomToMaxExtent();
|
||||||
|
|
||||||
|
t.delay_call(4, function() {
|
||||||
|
var cache = OpenLayers.Layer.Google.cache[map.id];
|
||||||
|
t.ok(cache.termsOfUse.style.display == "none" || cache.termsOfUse.style.left == "-9999px", "termsOfUse is not visible");
|
||||||
|
t.eq(cache.poweredBy.style.display, "none", "poweredBy is not visible");
|
||||||
|
map.destroy();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_Layer_Google_setGMapVisibility_allOverlays(t) {
|
||||||
|
t.plan(2);
|
||||||
|
|
||||||
|
var map = new OpenLayers.Map('map', {allOverlays: true});
|
||||||
|
var gmap = new OpenLayers.Layer.Google("Google Streets", {visibility: false});
|
||||||
|
var dummy = new OpenLayers.Layer("Dummy");
|
||||||
|
map.addLayers([gmap, dummy]);
|
||||||
|
map.zoomToMaxExtent();
|
||||||
|
|
||||||
|
t.delay_call(4, function() {
|
||||||
|
var cache = OpenLayers.Layer.Google.cache[map.id];
|
||||||
|
t.ok(cache.termsOfUse.style.display == "none" || cache.termsOfUse.style.left == "-9999px", "allOverlays:true - termsOfUse is not visible");
|
||||||
|
t.eq(cache.poweredBy.style.display, "none", "allOverlays:true - poweredBy is not visible");
|
||||||
|
map.destroy();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="map" style="width:500px; height: 500px"></div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -129,6 +129,7 @@
|
|||||||
<li>Layer/GeoRSS.html</li>
|
<li>Layer/GeoRSS.html</li>
|
||||||
<li>Layer/GML.html</li>
|
<li>Layer/GML.html</li>
|
||||||
<li>Layer/Google.html</li>
|
<li>Layer/Google.html</li>
|
||||||
|
<li>Layer/Google/v3.html</li>
|
||||||
<li>Layer/Grid.html</li>
|
<li>Layer/Grid.html</li>
|
||||||
<li>Layer/HTTPRequest.html</li>
|
<li>Layer/HTTPRequest.html</li>
|
||||||
<li>Layer/Image.html</li>
|
<li>Layer/Image.html</li>
|
||||||
|
|||||||
Reference in New Issue
Block a user