-
-
Save enjoylife/6236851 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
var po = org.polymaps; | |
po.canvas = function() { | |
var canvas = po.layer(load, unload), | |
image = po.svg("image"), // dummy image | |
url; | |
function load(tile) { | |
var size = canvas.map().tileSize(), | |
o = tile.element = po.svg("foreignObject"), | |
c = o.appendChild(document.createElement("canvas")), | |
w = size.x, | |
h = size.y; | |
o.setAttribute("width", w); | |
o.setAttribute("height", h); | |
c.setAttribute("width", w); | |
c.setAttribute("height", h); | |
tile.request = po.queue.image(image, url(tile), function(img) { | |
var g = c.getContext("2d"), | |
d = g.createImageData(w, h), | |
e; | |
delete tile.request; | |
tile.ready = true; | |
g.drawImage(img, 0, 0); | |
e = g.getImageData(0, 0, w, h); | |
for (var i = 0, n = w * h * 4; i < n; i++) d.data[i] = e.data[i] / 2; // e.g. | |
g.putImageData(d, 0, 0); | |
canvas.dispatch({type: "load", tile: tile}); | |
}); | |
} | |
function unload(tile) { | |
if (tile.request) tile.request.abort(true); | |
} | |
canvas.url = function(x) { | |
if (!arguments.length) return url; | |
url = po.url(x); | |
return canvas.reload(); | |
}; | |
return canvas; | |
}; | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<script type="text/javascript" src="http://github.com/simplegeo/polymaps/raw/v2.3.0/polymaps.min.js"></script> | |
<script type="text/javascript" src="canvas.js"></script> | |
<style type="text/css"> | |
@import url("http://github.com/simplegeo/polymaps/raw/v2.3.0/examples/example.css"); | |
</style> | |
</head> | |
<body> | |
<script type="text/javascript"> | |
var po = org.polymaps; | |
var map = po.map() | |
.container(document.body.appendChild(po.svg("svg"))) | |
.tileSize({x: 149, y: 149}) | |
.add(po.interact()); | |
map.add(po.canvas() | |
.url("http://bl.ocks.org/forkme.png")); | |
map.add(po.compass() | |
.pan("none")); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment