-
Notifications
You must be signed in to change notification settings - Fork 4
/
3.chinamap.v3.html
64 lines (51 loc) · 1.34 KB
/
3.chinamap.v3.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<html>
<head>
<meta charset="utf-8">
<title>中国地图</title>
<script src="js/d3.v3.js"></script>
</head>
<style>
</style>
<body>
<script>
var width = 1000;
var height = 1000;
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height)
.append("g")
.attr("transform", "translate(0,0)");
var projection = d3.geo.mercator()
.center([107, 31])
.scale(850)
.translate([width / 2, height / 2]);
var path = d3.geo.path()
.projection(projection);
var color = d3.scale.category20();
d3.json("data/china.geojson", function (error, root) {
if (error)
return console.error(error);
// console.log(root.features);
svg.selectAll("path")
.data(root.features)
.enter()
.append("path")
.attr("stroke", "#000")
.attr("stroke-width", 1)
.attr("fill", function (d, i) {
return color(i);
})
.attr("d", path)
.on("mouseover", function (d, i) {
d3.select(this)
.attr("fill", "yellow");
})
.on("mouseout", function (d, i) {
d3.select(this)
.attr("fill", color(i));
});
});
// TODO 加入人口数据,作为颜色填充; 改为d3.v5
</script>
</body>
</html>