Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add Mercator.coordToLngLat and lngLatToCoord

  • Loading branch information...
commit 99719dea0bfc3c76a2ab1bf000e87d578e060ec1 1 parent 5db0d03
@geary authored
Showing with 18 additions and 0 deletions.
  1. +18 −0 code/polygonzo.js
View
18 code/polygonzo.js
@@ -546,6 +546,15 @@ PolyGonzo = {
// TODO: refactor some other code to use these, but watch performance
Mercator: {
+ coordToLngLat: function( coord ) {
+ var pi = Math.PI, pi180 = pi / 180, radius = 6378137,
+ x = coord[0], y = coord[1];
+ return [
+ x / ( radius * pi180 ),
+ ( 2 * Math.atan( Math.exp( y / radius ) ) - pi / 2 ) / pi180
+ ];
+ },
+
coordToPixel: function( coord, zoom ) {
var multX = Math.pow( 2, zoom ) / 156543.03392;
var multY = -multX;
@@ -575,6 +584,15 @@ PolyGonzo = {
return /EPSG:+3857$/.test( crs );
},
+ lngLatToCoord: function( ll ) {
+ var pi = Math.PI, pi180 = pi / 180, radius = 6378137,
+ lng = ll[0], lat = ll[1];
+ return [
+ radius * pi180 * lng,
+ radius * Math.log( Math.tan( ( 90 + lat ) * pi180 / 2 ) )
+ ];
+ },
+
pixelToCoord: function( pixel, zoom ) {
//function log2( n ) { return Math.log(n) / Math.LN2; }
//
Please sign in to comment.
Something went wrong with that request. Please try again.