webdial

Incomplete JS port of moondial.
git clone https://code.literati.org/webdial.git
Log | Files | Refs

commit c5a3eea3189c292dcb3ad37a4733cc01a563a9a3
parent f728bbbc0966457539186ffabd3c09a0dc9af3d3
Author: Sean Lynch <seanl@literati.org>
Date:   Wed,  7 Sep 2011 21:29:13 -0700

Initial commit of webdial js

Diffstat:
Awebdial.js | 39+++++++++++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+), 0 deletions(-)

diff --git a/webdial.js b/webdial.js @@ -0,0 +1,38 @@ +function WebDial(canvas) { + var continents; + + function drawMap() { + var w = canvas.width(); + var h = canvas.height(); + function lon2x(lon) { + return (lon + 180.0) * w / 360.0; + } + + function lat2y(lat) { + return (90.0 - lat) * h / 180.0; + } + + var ctx = canvas[0].getContext("2d"); + ctx.fillStyle = "rgb(0, 192, 0)"; + $.each(continents, function(continent, polygons) { + $.each(polygons, function(i, points) { + ctx.beginPath(); + ctx.moveTo(points[points.length-1]); + $.each(points, function(j, point) { + ctx.lineTo(lon2x(point[0]), lat2y(point[1])); + }); + ctx.fill(); + }); + }); + } + + function mapCallback(data) { + continents = data; + drawMap(); + } + + this.go = function() { + $.ajax("https://raw.github.com/seanlynch/webdial/master/continent.json", + {success: mapCallback}); + } +}+ \ No newline at end of file