-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathexample_1_d3_canvas.html
49 lines (37 loc) · 1.31 KB
/
example_1_d3_canvas.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<!DOCTYPE html>
<html>
<head>
<title>D3 Canvas Map Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=0">
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<div id="loading">Loading...</div>
<script src="node_modules/d3/d3.js"></script>
<script src="node_modules/topojson/build/topojson.js"></script>
<script>
/*eslint-disable */
var projection = d3.geo.equirectangular()
.translate([512, 256]).scale(163);
d3.json('data/world.json', function (err, data) {
d3.select("#loading").transition().duration(500)
.style("opacity", 0).remove();
var countries = topojson.feature(data, data.objects.countries);
var canvas = d3.select("body").append("canvas")
.attr({width: "1024px", height: "512px"});
var context = canvas.node().getContext("2d");
var path = d3.geo.path()
.projection(projection).context(context);
context.strokeStyle = "#333";
context.lineWidth = 0.25;
context.fillStyle = "#fff";
context.beginPath();
path(countries);
context.fill();
context.stroke();
console.log(canvas.node().toDataURL());
});
</script>
</body>
</html>