Ticket #1019: spherical.patch
| File spherical.patch, 11.9 kB (added by euzuro, 1 year ago) |
|---|
-
lib/OpenLayers/Layer/SphericalMercator.js
old new 30 30 */ 31 31 OpenLayers.Layer.SphericalMercator = { 32 32 33 /**34 * Method: getExtent35 * Get the map's extent.36 *37 * Returns:38 * {<OpenLayers.Bounds>} The map extent.39 */40 getExtent: function() {41 var extent = null;42 if (this.sphericalMercator) {43 extent = this.map.calculateBounds();44 } else {45 extent = OpenLayers.Layer.FixedZoomLevels.prototype.getExtent.apply(this);46 }47 return extent;48 },49 50 33 /** 51 34 * Method: initMercatorParameters 52 35 * Set up the mercator parameters on the layer: resolutions, … … 61 44 } 62 45 this.units = "m"; 63 46 this.projection = "EPSG:900913"; 64 },65 47 48 49 50 //translation functions 51 52 53 //instead of using FixedZoomLevels to calculate bounds, use map 54 this.getExtent = this.map.calculateBounds; 55 56 //lon from maplonlat 57 var oldGetLon = this.getLongitudeFromMapObjectLonLat; 58 this.getLongitudeFromMapObjectLonLat = function(moLonLat) { 59 var lon = oldGetLon(moLonLat); 60 return this.mercatorLonToX(lon); 61 }; 62 63 //lat from maplonlat 64 var oldGetLat = this.getLatitudeFromMapObjectLonLat; 65 this.getLatitudeFromMapObjectLonLat = function(moLonLat) { 66 var lat = oldGetLat(moLonLat); 67 return this.mercatorLatToY(lat); 68 }; 69 70 //maplonlat from lonlat 71 var oldGetLonLat = this.getMapObjectLonLatFromLonLat; 72 this.getMapObjectLonLatFromLonLat = function(lon, lat) { 73 var newLon = this.mercatorXToLon(lon); 74 var newLat = this.mercatorYToLat(lat); 75 return oldGetLonLat(newLon, newLat); 76 }; 77 78 }, 79 66 80 /** 67 81 * Method: forwardMercator 68 * Given a lon ,lat in EPSG:4326, return a pointin Spherical Mercator.82 * Given a lon in EPSG:4326, return an X in Spherical Mercator. 69 83 * 70 84 * Parameters: 71 85 * lon - {float} 86 * 87 * Returns: 88 * {Float} The lon coordinate transformed to Mercator. 89 */ 90 mercatorLonToX: function(lon) { 91 var x = lon * 20037508.34 / 180; 92 return x; 93 }, 94 95 /** 96 * Method: mercatorLatToY 97 * Given a lat in EPSG:4326, return a Y in Spherical Mercator. 98 * 99 * Parameters: 72 100 * lat - {float} 73 101 * 74 102 * Returns: 75 * { <OpenLayers.LonLat>} The coordinatestransformed to Mercator.103 * {Float} The lat coordinate transformed to Mercator. 76 104 */ 77 forwardMercator: function(lon, lat) { 78 var x = lon * 20037508.34 / 180; 105 mercatorLatToY: function(lat) { 79 106 var y = Math.log(Math.tan((90 + lat) * Math.PI / 360)) / (Math.PI / 180); 80 81 107 y = y * 20037508.34 / 180; 82 108 83 return new OpenLayers.LonLat(x, y);109 return y; 84 110 }, 85 111 86 112 /** 87 * Method: inverseMercator88 * Given a x ,y in Spherical Mercator, return a pointin EPSG:4326.113 * Method: mercatorXToLon 114 * Given a x in Spherical Mercator, return a lon in EPSG:4326. 89 115 * 90 116 * Parameters: 91 * x - {float} A map x in Spherical Mercator. 117 * x - {Float} A map x in Spherical Mercator. 118 * 119 * Returns: 120 * {Float} The x coordinate transformed to EPSG:4326. 121 */ 122 mercatorXToLon: function(x) { 123 var lon = (x / 20037508.34) * 180; 124 return lon; 125 }, 126 127 /** 128 * Method: mercatorYToLat 129 * Given a y in Spherical Mercator, return a lat in EPSG:4326. 130 * 131 * Parameters: 92 132 * y - {float} A map y in Spherical Mercator. 93 133 * 94 134 * Returns: 95 * { <OpenLayers.LonLat>} The coordinatestransformed to EPSG:4326.135 * {Float} The y coordinate transformed to EPSG:4326. 96 136 */ 97 inverseMercator: function(x, y) { 98 99 var lon = (x / 20037508.34) * 180; 137 mercatorYToLat: function(y) { 100 138 var lat = (y / 20037508.34) * 180; 101 139 102 lat = 180/Math.PI * (2 * Math.atan(Math.exp(lat * Math.PI / 180)) - Math.PI / 2); 140 lat = 180/Math.PI * 141 (2 * Math.atan(Math.exp(lat * Math.PI / 180)) - Math.PI / 2); 103 142 104 return new OpenLayers.LonLat(lon, lat);143 return lat; 105 144 } 106 145 107 146 }; -
lib/OpenLayers/Layer/VirtualEarth.js
old new 228 228 * {Float} Longitude of the given MapObject LonLat 229 229 */ 230 230 getLongitudeFromMapObjectLonLat: function(moLonLat) { 231 return this.sphericalMercator ? 232 this.forwardMercator(moLonLat.Longitude, moLonLat.Latitude).lon : 233 moLonLat.Longitude; 231 return moLonLat.Longitude; 234 232 }, 235 233 236 234 /** … … 243 241 * {Float} Latitude of the given MapObject LonLat 244 242 */ 245 243 getLatitudeFromMapObjectLonLat: function(moLonLat) { 246 return this.sphericalMercator ? 247 this.forwardMercator(moLonLat.Longitude, moLonLat.Latitude).lat : 248 moLonLat.Latitude; 244 return moLonLat.Latitude; 249 245 }, 250 246 251 247 /** … … 259 255 * {Object} MapObject LonLat built from lon and lat params 260 256 */ 261 257 getMapObjectLonLatFromLonLat: function(lon, lat) { 262 var veLatLong; 263 if(this.sphericalMercator) { 264 var lonlat = this.inverseMercator(lon, lat); 265 veLatLong = new VELatLong(lonlat.lat, lonlat.lon); 266 } else { 267 veLatLong = new VELatLong(lat, lon); 268 } 258 var veLatLong = new VELatLong(lat, lon); 269 259 return veLatLong; 270 260 }, 271 261 -
lib/OpenLayers/Layer/Google.js
old new 211 211 getOLBoundsFromMapObjectBounds: function(moBounds) { 212 212 var olBounds = null; 213 213 if (moBounds != null) { 214 214 215 var sw = moBounds.getSouthWest(); 216 left = this.getLongitudeFromMapObjectLonLat(sw); 217 bottom = this.getLatitudeFromMapObjectLonLat(sw); 218 215 219 var ne = moBounds.getNorthEast(); 216 if (this.sphericalMercator) { 217 sw = this.forwardMercator(sw.lng(), sw.lat()); 218 ne = this.forwardMercator(ne.lng(), ne.lat()); 219 } else { 220 sw = new OpenLayers.LonLat(sw.lng(), sw.lat()); 221 ne = new OpenLayers.LonLat(ne.lng(), ne.lat()); 222 } 223 olBounds = new OpenLayers.Bounds(sw.lon, 224 sw.lat, 225 ne.lon, 226 ne.lat ); 220 right = this.getLongitudeFromMapObjectLonLat(ne); 221 top = this.getLatitudeFromMapObjectLonLat(ne); 222 223 olBounds = new OpenLayers.Bounds(left, bottom, right, top); 227 224 } 228 225 return olBounds; 229 226 }, … … 241 238 getMapObjectBoundsFromOLBounds: function(olBounds) { 242 239 var moBounds = null; 243 240 if (olBounds != null) { 244 var sw = this.sphericalMercator ? 245 this.inverseMercator(olBounds.bottom, olBounds.left) : 246 new OpenLayers.LonLat(olBounds.bottom, olBounds.left); 247 var ne = this.sphericalMercator ? 248 this.inverseMercator(olBounds.top, olBounds.right) : 249 new OpenLayers.LonLat(olBounds.top, olBounds.right); 250 moBounds = new GLatLngBounds(new GLatLng(sw.lat, sw.lon), 251 new GLatLng(ne.lat, ne.lon)); 241 var sw = new OpenLayers.LonLat(olBounds.bottom, olBounds.left); 242 var gSw = this.getMapObjectLonLatFromLonLat(sw); 243 244 var ne = new OpenLayers.LonLat(olBounds.top, olBounds.right); 245 var gNe = this.getMapObjectLonLatFromLonLat(ne); 246 247 moBounds = new GLatLngBounds(sw, ne); 252 248 } 253 249 return moBounds; 254 250 }, … … 418 414 * {Float} Longitude of the given MapObject LonLat 419 415 */ 420 416 getLongitudeFromMapObjectLonLat: function(moLonLat) { 421 return this.sphericalMercator ? 422 this.forwardMercator(moLonLat.lng(), moLonLat.lat()).lon : 423 moLonLat.lng(); 417 return moLonLat.lng(); 424 418 }, 425 419 426 420 /** … … 433 427 * {Float} Latitude of the given MapObject LonLat 434 428 */ 435 429 getLatitudeFromMapObjectLonLat: function(moLonLat) { 436 var lat = this.sphericalMercator ? 437 this.forwardMercator(moLonLat.lng(), moLonLat.lat()).lat : 438 moLonLat.lat(); 439 return lat; 430 return moLonLat.lat(); 440 431 }, 441 432 442 433 /** … … 450 441 * {Object} MapObject LonLat built from lon and lat params 451 442 */ 452 443 getMapObjectLonLatFromLonLat: function(lon, lat) { 453 var gLatLng; 454 if(this.sphericalMercator) { 455 var lonlat = this.inverseMercator(lon, lat); 456 gLatLng = new GLatLng(lonlat.lat, lonlat.lon); 457 } else { 458 gLatLng = new GLatLng(lat, lon); 459 } 444 var gLatLng = new GLatLng(lat, lon); 460 445 return gLatLng; 461 446 }, 462 447 -
lib/OpenLayers/Layer/Yahoo.js
old new 306 306 * {Float} Longitude of the given MapObject LonLat 307 307 */ 308 308 getLongitudeFromMapObjectLonLat: function(moLonLat) { 309 return this.sphericalMercator ? 310 this.forwardMercator(moLonLat.Lon, moLonLat.Lat).lon : 311 moLonLat.Lon; 309 return moLonLat.Lon; 312 310 }, 313 311 314 312 /** … … 321 319 * {Float} Latitude of the given MapObject LonLat 322 320 */ 323 321 getLatitudeFromMapObjectLonLat: function(moLonLat) { 324 return this.sphericalMercator ? 325 this.forwardMercator(moLonLat.Lon, moLonLat.Lat).lat : 326 moLonLat.Lat; 322 return moLonLat.Lat; 327 323 }, 328 324 329 325 /** … … 337 333 * {Object} MapObject LonLat built from lon and lat params 338 334 */ 339 335 getMapObjectLonLatFromLonLat: function(lon, lat) { 340 var yLatLong; 341 if(this.sphericalMercator) { 342 var lonlat = this.inverseMercator(lon, lat); 343 yLatLong = new YGeoPoint(lonlat.lat, lonlat.lon); 344 } else { 345 yLatLong = new YGeoPoint(lat, lon); 346 } 336 var yLatLong = new YGeoPoint(lat, lon); 347 337 return yLatLong; 348 338 }, 349 339 -
lib/OpenLayers/Layer/MultiMap.js
old new 208 208 * {Float} Longitude of the given MapObject LonLat 209 209 */ 210 210 getLongitudeFromMapObjectLonLat: function(moLonLat) { 211 return this.sphericalMercator ? 212 this.forwardMercator(moLonLat.lon, moLonLat.lat).lon : 213 moLonLat.lon; 211 return moLonLat.lon; 214 212 }, 215 213 216 214 /** … … 223 221 * {Float} Latitude of the given MapObject LonLat 224 222 */ 225 223 getLatitudeFromMapObjectLonLat: function(moLonLat) { 226 return this.sphericalMercator ? 227 this.forwardMercator(moLonLat.lon, moLonLat.lat).lat : 228 moLonLat.lat; 224 return moLonLat.lat; 229 225 }, 230 226 231 227 /** … … 239 235 * {Object} MapObject LonLat built from lon and lat params 240 236 */ 241 237 getMapObjectLonLatFromLonLat: function(lon, lat) { 242 var mmLatLon; 243 if(this.sphericalMercator) { 244 var lonlat = this.inverseMercator(lon, lat); 245 mmLatLon = new MMLatLon(lonlat.lat, lonlat.lon); 246 } else { 247 mmLatLon = new MMLatLon(lat, lon); 248 } 238 var mmLatLon = new MMLatLon(lat, lon); 249 239 return mmLatLon; 250 240 }, 251 241
