Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add Google Mercator utility functions

  • Loading branch information...
commit 439be766b833c17cbda14664f6d333dfe7920df3 1 parent 907df6b
@geary authored
Showing with 41 additions and 2 deletions.
  1. +41 −2 code/polygonzo.js
View
43 code/polygonzo.js
@@ -228,8 +228,7 @@ PolyGonzo = {
var totalFeatures = 0, totalPolys = 0, totalPoints = 0;
for( var geo, iGeo = -1; geo = geos[++iGeo]; ) {
var features = geo.features;
- var crs = geo.crs && geo.crs.type == 'name' && geo.crs.properties.name || '';
- var mercator = /EPSG:+3857$/.test( crs );
+ var mercator = PolyGonzo.Mercator.isMercator( geo );
if( mercator ) {
}
else {
@@ -471,6 +470,46 @@ PolyGonzo = {
}
},
+ // TODO: refactor some other code to use these, but watch performance
+ Mercator: {
+ coordToPixel: function( coord, zoom ) {
+ var multX = Math.pow( 2, zoom ) / 156543.03392;
+ var multY = -multX;
+ return [
+ multX * coord[0],
+ multY * coord[1]
+ ];
+ },
+
+ fitBbox: function( bbox, pix ) {
+ return Math.min(
+ this.getZoom( Math.abs( bbox[0] - bbox[2] ), pix.width ),
+ this.getZoom( Math.abs( bbox[1] - bbox[3] ), pix.height )
+ );
+ },
+
+ getZoom: function( goog, pix ) {
+ function log2( n ) { return Math.log(n) / Math.LN2; }
+ return log2( pix / goog * 156543.03392 );
+ },
+
+ isMercator: function( geo ) {
+ var crs =
+ geo.crs &&
+ geo.crs.type == 'name' &&
+ geo.crs.properties.name || '';
+ return /EPSG:+3857$/.test( crs );
+ },
+
+ pixelToCoord: function( pixel, zoom ) {
+ //function log2( n ) { return Math.log(n) / Math.LN2; }
+ //
+ //
+ //multX = Math.pow( 2, zoom ) / 156543.03392,
+ //multY = -multX;
+ }
+ },
+
// PolyGonzo.PgOverlay() - Google Maps JavaScript API V2/V3 overlay
PgOverlay: function( a ) {
var map = a.map, pane, frame, canvas, markers, tracker, moveListener, zoomListener;
Please sign in to comment.
Something went wrong with that request. Please try again.