With review from elem, and oversight from tschaub, rolling in
SphericalMercator changes. Note that this explicitly does *not* include r4182 , so as to keep changes to a single logical set: that should be filed in a seperate bug if it can be reproduced against trunk after this commit. Hooray for Tim, thanks for all the feedback, onward and upward! (Closes #686) git-svn-id: http://svn.openlayers.org/trunk/openlayers@4221 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
/**
|
||||
* @requires OpenLayers/Layer.js
|
||||
*
|
||||
* Class: OpenLayers.Layer.SphericalMercator
|
||||
* A mixin for layers that wraps up the pieces neccesary to have a coordinate
|
||||
* conversion for working with commercial APIs which use a spherical
|
||||
* mercator projection. Using this layer as a base layer, additional
|
||||
* layers can be used as overlays if they are in the same projection.
|
||||
*
|
||||
* A layer is given properties of this object by setting the sphericalMercator
|
||||
* property to true.
|
||||
*
|
||||
* More projection information:
|
||||
* - http://spatialreference.org/ref/user/google-projection/
|
||||
*
|
||||
* Proj4 Text:
|
||||
* +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0
|
||||
* +k=1.0 +units=m +nadgrids=@null +no_defs
|
||||
*
|
||||
* WKT:
|
||||
* 900913=PROJCS["WGS84 / Simple Mercator", GEOGCS["WGS 84",
|
||||
* DATUM["WGS_1984", SPHEROID["WGS_1984", 6378137.0, 298.257223563]],
|
||||
* PRIMEM["Greenwich", 0.0], UNIT["degree", 0.017453292519943295],
|
||||
* AXIS["Longitude", EAST], AXIS["Latitude", NORTH]],
|
||||
* PROJECTION["Mercator_1SP_Google"],
|
||||
* PARAMETER["latitude_of_origin", 0.0], PARAMETER["central_meridian", 0.0],
|
||||
* PARAMETER["scale_factor", 1.0], PARAMETER["false_easting", 0.0],
|
||||
* PARAMETER["false_northing", 0.0], UNIT["m", 1.0], AXIS["x", EAST],
|
||||
* AXIS["y", NORTH], AUTHORITY["EPSG","900913"]]
|
||||
*/
|
||||
OpenLayers.Layer.SphericalMercator = {
|
||||
|
||||
/**
|
||||
* Method: getExtent
|
||||
* Get the map's extent.
|
||||
*
|
||||
* Returns:
|
||||
* {<OpenLayers.Bounds>} The map extent.
|
||||
*/
|
||||
getExtent: function() {
|
||||
var extent = null;
|
||||
if (this.sphericalMercator) {
|
||||
extent = this.map.calculateBounds();
|
||||
} else {
|
||||
extent = OpenLayers.Layer.FixedZoomLevels.prototype.getExtent.apply(this);
|
||||
}
|
||||
return extent;
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: initMercatorParameters
|
||||
* Set up the mercator parameters on the layer: resolutions,
|
||||
* projection, units.
|
||||
*/
|
||||
initMercatorParameters: function() {
|
||||
// set up properties for Mercator - assume EPSG:900913
|
||||
this.RESOLUTIONS = [];
|
||||
var maxResolution = 156543.0339;
|
||||
for(var zoom=0; zoom<=this.MAX_ZOOM_LEVEL; ++zoom) {
|
||||
this.RESOLUTIONS[zoom] = maxResolution / Math.pow(2, zoom);
|
||||
}
|
||||
this.units = "m";
|
||||
this.projection = "EPSG:900913";
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: forwardMercator
|
||||
* Given a lon,lat in EPSG:4326, return a point in Spherical Mercator.
|
||||
*
|
||||
* Parameters:
|
||||
* lon - {float}
|
||||
* lat - {float}
|
||||
*
|
||||
* Returns:
|
||||
* {<OpenLayers.LonLat>} The coordinates transformed to Mercator.
|
||||
*/
|
||||
forwardMercator: function(lon, lat) {
|
||||
var x = lon * 20037508.34 / 180;
|
||||
var y = Math.log(Math.tan((90 + lat) * Math.PI / 360)) / (Math.PI / 180);
|
||||
|
||||
y = y * 20037508.34 / 180;
|
||||
|
||||
return new OpenLayers.LonLat(x, y);
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: inverseMercator
|
||||
* Given a x,y in Spherical Mercator, return a point in EPSG:4326.
|
||||
*
|
||||
* Parameters:
|
||||
* x - {float} A map x in Spherical Mercator.
|
||||
* y - {float} A map y in Spherical Mercator.
|
||||
*
|
||||
* Returns:
|
||||
* {<OpenLayers.LonLat>} The coordinates transformed to EPSG:4326.
|
||||
*/
|
||||
inverseMercator: function(x, y) {
|
||||
|
||||
var lon = (x / 20037508.34) * 180;
|
||||
var lat = (y / 20037508.34) * 180;
|
||||
|
||||
lat = 180/Math.PI * (2 * Math.atan(Math.exp(lat * Math.PI / 180)) - Math.PI / 2);
|
||||
|
||||
return new OpenLayers.LonLat(lon, lat);
|
||||
}
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user