bringing all changes from sandbox/euzuro/LayersReworking down into the trunk. this is a merge of r656:HEAD http://svn.openlayers.org/sandbox/euzuro/LayersReworking

git-svn-id: http://svn.openlayers.org/trunk/openlayers@806 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
euzuro
2006-06-27 23:16:26 +00:00
parent 63bd624827
commit ff0e83d0a0
24 changed files with 1262 additions and 467 deletions
+232 -27
View File
@@ -14,7 +14,7 @@ OpenLayers.Layer.Google = Class.create();
OpenLayers.Layer.Google.prototype = Object.extend( new OpenLayers.Layer(), {
/** @type Boolean */
viewPortLayer: true,
isFixed: true,
/** @type GMap2 gmap stores the Google Map element */
gmap:null,
@@ -27,8 +27,18 @@ OpenLayers.Layer.Google.prototype = Object.extend( new OpenLayers.Layer(), {
*
* @param {String} name
*/
initialize: function(name) {
OpenLayers.Layer.prototype.initialize.apply(this, [name]);
initialize: function(name, options) {
OpenLayers.Layer.prototype.initialize.apply(this, arguments);
if (this.minZoomLevel == null) {
this.minZoomLevel = -1;
}
if (this.maxZoomLevel == null) {
this.maxZoomLevel = 16;
}
if (this.maxExtent == null) {
this.maxExtent = new OpenLayers.Bounds(-180, -90, 180, 90);
}
},
/**
@@ -50,21 +60,29 @@ OpenLayers.Layer.Google.prototype = Object.extend( new OpenLayers.Layer(), {
/**
* @param {OpenLayers.Bounds} bounds
* @param {int} zoomChanged
* @param {Boolean} zoomChanged
*/
moveTo:function(bounds,zoomChanged) {
moveTo:function(bounds, zoomChanged) {
if ((this.gmap != null) && (!this.dragging)) {
var olCenter = this.map.getCenter();
var gCenter = this.getGMapCenter();
var olZoom = this.map.getZoom();
var gZoom = this.gmap.getZoom();
if ((!olCenter.equals(gCenter)) || ((olZoom +1) != gZoom)) {
this.gmap.setCenter(new GLatLng(olCenter.lat, olCenter.lon),
olZoom + 1);
var newCenter = this.map.getCenter();
var newZoom = this.map.getZoom();
if (newCenter != null) {
var gCenter = this.gmap.getCenter();
var gZoom = this.gmap.getZoom();
var currentCenter = this.getOLLonLatFromGLatLng(gCenter);
var currentZoom = this.getOLZoomFromGZoom(gZoom);
if ( (!newCenter.equals(currentCenter)) ||
(newZoom != currentZoom) ) {
this.gmap.setCenter(this.getGLatLngFromOLLonLat(newCenter),
this.getGZoomFromOLZoom(newZoom));
}
}
}
},
@@ -73,6 +91,7 @@ OpenLayers.Layer.Google.prototype = Object.extend( new OpenLayers.Layer(), {
*
*/
loadGMap:function() {
// create div and set to same size as map
var gDiv = OpenLayers.Util.createDiv(this.name);
var sz = this.map.getSize();
@@ -82,6 +101,8 @@ OpenLayers.Layer.Google.prototype = Object.extend( new OpenLayers.Layer(), {
// create GMap, hide nav controls
this.gmap = new GMap2(this.div);
// this causes the GMap to set itself to Map's center/zoom
this.moveTo();
// catch pans and zooms from GMap
@@ -101,6 +122,11 @@ OpenLayers.Layer.Google.prototype = Object.extend( new OpenLayers.Layer(), {
"dragend",
this.dragEnd.bindAsEventListener(this));
// catch pans and zooms from GMap
GEvent.addListener(this.gmap,
"drag",
this.catchPanZoom.bindAsEventListener(this));
},
/**
@@ -123,30 +149,209 @@ OpenLayers.Layer.Google.prototype = Object.extend( new OpenLayers.Layer(), {
* @param {event} e
*/
catchPanZoom: function(e) {
var olCenter = this.getGMapCenter();
var gCenter = this.gmap.getCenter();
var gZoom = this.gmap.getZoom();
this.map.setCenter(olCenter, gZoom - 1);
var olCenter = this.getOLLonLatFromGLatLng(gCenter);
var olZoom = this.getOLZoomFromGZoom(gZoom);
this.map.setCenter(olCenter, olZoom);
},
/**
* @param {OpenLayers.Pixel} viewPortPx
*
* @returns An OpenLayers.LonLat which is the passed-in view port
* OpenLayers.Pixel, translated into lon/lat by GMAPS
* @type OpenLayers.LonLat
*/
getLonLatFromViewPortPx: function (viewPortPx) {
var gPoint = this.getGPointFromOLPixel(viewPortPx);
var gLatLng = this.gmap.fromDivPixelToLatLng(gPoint)
return this.getOLLonLatFromGLatLng(gLatLng);
},
/**
* @param {OpenLayers.LonLat} lonlat
*
* @returns An OpenLayers.Pixel which is the passed-in OpenLayers.LonLat,
* translated into view port pixels BY GMAPS
* @type OpenLayers.Pixel
*/
getViewPortPxFromLonLat: function (lonlat) {
var gLatLng = this.getGLatLngFromOLLonLat(lonlat);
var gPoint = this.gmap.fromLatLngToDivPixel(gLatLng)
return this.getOLPixelFromGPoint(gPoint);
},
/**
* @private
* @param {OpenLayers.Bounds} bounds
*
* @return {int}
*/
getZoomForExtent: function (bounds) {
var gBounds = this.getGLatLngBoundsFromOLBounds(bounds);
var gZoom = this.gmap.getBoundsZoomLevel(gBounds);
return this.getOLZoomFromGZoom(gZoom);
},
/**
* @returns A Bounds object which represents the lon/lat bounds of the
* current viewPort.
* @type OpenLayers.Bounds
*/
getExtent: function () {
if (this.gmap.getCenter() == null) {
this.moveTo();
}
var gLatLngBounds = this.gmap.getBounds();
return this.getOLBoundsFromGLatLngBounds(gLatLngBounds);
},
/********************************************************/
/* */
/* Translation Functions */
/* */
/* The following functions translate GMaps and OL */
/* formats for Pixel, LonLat, Bounds, and Zoom */
/* */
/********************************************************/
//
// TRANSLATION: GZoom <-> OpenLayers Zoom
//
/**
* @param {int} gZoom
*
* @returns An OpenLayers.LonLat with the center of the gmap, or null if
* the GMap has not been centered yet
* @returns An OpenLayers Zoom level, translated from the passed in gZoom
* @type int
*/
getOLZoomFromGZoom: function(gZoom) {
return (gZoom - 1);
},
/**
* @param {int} olZoom
*
* @returns A GZoom level, translated from the passed in olZoom
* @type int
*/
getGZoomFromOLZoom: function(olZoom) {
return (olZoom + 1);
},
//
// TRANSLATION: GLatLng <-> LonLat
//
/**
* @param {GLatLng} gLatLng
*
* @returns An OpenLayers.LonLat, translated from the passed in GLatLng
* @type OpenLayers.LonLat
*/
getGMapCenter:function() {
var olCenter = null;
var gCenter = this.gmap.getCenter();
if (gCenter != null) {
olCenter = new OpenLayers.LonLat(gCenter.lng(), gCenter.lat());
getOLLonLatFromGLatLng: function(gLatLng) {
var olLonLat = null;
if (gLatLng != null) {
olLonLat = new OpenLayers.LonLat(gLatLng.lng(), gLatLng.lat());
}
return olCenter;
return olLonLat;
},
/**
* @param {OpenLayers.LonLat} olLonLat
*
* @returns A GLatLng, translated from the passed in OpenLayers.LonLat
* @type GLatLng
*/
getGLatLngFromOLLonLat: function(olLonLat) {
var gLatLng = null;
if (olLonLat != null) {
gLatLng = new GLatLng(olLonLat.lat, olLonLat.lon);
}
return gLatLng;
},
//
// TRANSLATION: GPoint <-> OpenLayers.Pixel
//
/**
* @param {GPoint} gPoint
*
* @returns An OpenLayers.Pixel, translated from the passed in GPoint
* @type OpenLayers.Pixel
*/
getOLPixelFromGPoint: function(gPoint) {
var olPixel = null;
if (gPoint != null) {
olPixel = new OpenLayers.Pixel(gPoint.x, gPoint.y);
}
return olPixel;
},
/**
* @param {OpenLayers.Pixel} olPixel
*
* @returns A GPoint, translated from the passed in OpenLayers.Pixel
* @type GPoint
*/
getGPointFromOLPixel: function(olPixel) {
var gPoint = null;
if (olPixel != null) {
gPoint = new GPoint(olPixel.x, olPixel.y);
}
return gPoint;
},
//
// TRANSLATION: GLatLngBounds <-> OpenLayers.Bounds
//
/**
* @param {GLatLngBounds} gLatLngBounds
*
* @returns An OpenLayers.Bounds, translated from gLatLngBounds
* @type OpenLayers.Bounds
*/
getOLBoundsFromGLatLngBounds: function(gLatLngBounds) {
var olBounds = null;
if (gLatLngBounds != null) {
var sw = gLatLngBounds.getSouthWest();
var ne = gLatLngBounds.getNorthEast();
olBounds = new OpenLayers.Bounds(sw.lng(),
sw.lat(),
ne.lng(),
ne.lat() );
}
return olBounds;
},
/**
* @param {OpenLayers.Bounds} olBounds
*
* @returns A GLatLngBounds, translated from olBounds
* @type GLatLngBounds
*/
getGLatLngBoundsFromOLBounds: function(olBounds) {
var gLatLngBounds = null;
if (olBounds != null) {
var sw = new GLatLng(olBounds.bottom, olBounds.left);
var ne = new GLatLng(olBounds.top, olBounds.right);
gLatLngBounds = new GLatLngBounds(sw, ne);
}
return gLatLngBounds;
},
/** @final @type String */
CLASS_NAME: "OpenLayers.Layer.Google"
});