Skip to content

richardzcode/worldMap.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

worldMap.js

Draw world map on canvas

##Inroduction

Spent quite some time searching on web on converting latitude/longitude to pixel. Pretty common question I thought. Amazingly, no simple answer. Everybody wanted to write either a academic paper, or a gmap tutorial.

WTF, I just wanted to draw a small world map and plot some stuff on top! What projection? Well, the one that commonly used by 3rd party ip to lat/lon translation.

Until somebody mentioned, for small size map, lat/lon are quite linear...

So, here is the magic formula:

var x = ((lng / 360) + 0.5) * width;
var y = (1 - ((lat / 180) + 0.5)) * height;

Then get lands shapfile from Natural Earth. Extract out lat/lon by using shpdump. We got a map.

##Screenshot

demo

About

Draw world map on canvas

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published