Skip to content

Instantly share code, notes, and snippets.

@donSchoe
Created July 2, 2015 07:24
Show Gist options
  • Select an option

  • Save donSchoe/f12fffb3584ee2b9042d to your computer and use it in GitHub Desktop.

Select an option

Save donSchoe/f12fffb3584ee2b9042d to your computer and use it in GitHub Desktop.

Revisions

  1. donSchoe created this gist Jul 2, 2015.
    9 changes: 9 additions & 0 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    // JavaScript

    // converts lat/lon to pixel x/y at zoom level 0 for 256*256 tile size , inverts y coord
    function latLonToPixels(lat, lon) { // lat, lon: epsg:4326
    var sinLat = Math.sin(lat * Math.PI / 180.0);
    var pixelX = ((lon + 180) / 360) * 256;
    var pixelY = (0.5 - Math.log((1 + sinLat) / (1 - sinLat)) / (Math.PI * 4)) * 256;
    return { x: pixelX, y: pixelY }; // object with .x and .y
    }