-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
116 lines (107 loc) · 3.95 KB
/
index.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<!DOCTYPE html>
<meta charset="utf-8">
<style>
/* CSS goes here. */
.subunit.TWN { fill: #cdc; }
.place-label {
fill:#555;
font-size: 5px;
}
.subunit-label {
fill: #777;
fill-opacity: .5;
font-size: 12px;
font-weight: 300;
text-anchor: middle;
}
</style>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/topojson.v0.min.js"></script>
<script>
var links = [
"http://www.lilychen.net/MKL/Various/Zhongli_Night_Market_02.jpg",//Zhongli
"http://tours.asialighttravel.com/wp-content/uploads/2011/03/keelung-taiwan.jpg",//Keelung
"http://us.123rf.com/400wm/400/400/huangcarlos/huangcarlos1104/huangcarlos110400252/9377532-changhua-grand-buddha.jpg",//Changhua
"http://townweb.cyhg.gov.tw/update_flies/Chiayi%281%29.jpg", //Chiayi
"http://upload.wikimedia.org/wikipedia/en/d/d9/Hsinchu-RR-Station.jpg",//Hsinchu
"http://www.mvmtravel.com/images/articleimages/2721/dimage3025.jpg", //Miaoli
"http://www.chinapost.com.tw/news_images/20080710/p9a.jpg", //Pingtung
"http://www.esldewey.com.tw/city/hualien/hualien.jpg" , //Hualien
"http://upload.wikimedia.org/wikipedia/commons/a/a6/New_Taipei_Bridge.jpg" , //New Taipei
"http://upload.wikimedia.org/wikipedia/commons/a/a5/Tainan_Butokuden.JPG" , //Tainan
"http://i604.photobucket.com/albums/tt126/mikechujournal/Taitung/train-taitung.jpg" , //Taitung
"http://gemvg.com/gallery/albums/image/aerofoto/200804/normal_20080425ponghuMagong.jpg" , //Magong
"http://photography.jargoned.com/wp-content/uploads/2012/09/P1110268.jpg" , //Taichung
"http://wikitravel.org/upload/en/thumb/b/b1/Kaohsiung.jpg/350px-Kaohsiung.jpg" , //Kaohsiung
"http://tw.chinahotel.com.cn/hotel_images/2244_5_1.jpg" //taipei
]
function show_info(d , i){
svg.select("#pop_rect").attr("width" , 100 )
.attr("height" , 100 )
.attr("xlink:href" , links[i] )
.attr("transform", "translate(" + projection(d.coordinates) + ")" )
;
}
function hidden_info(){
svg.select("#pop_rect").attr("width" , 0 )
.attr("height" , 0 )
.attr("xlink:href" , null )
;
}
/* JavaScript goes here. */
var width = 960,
height = 1160;
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
var projection = d3.geo.albers()
//taiwan 121°E 23.8°N
.center([0, 23.8])
.rotate([-121, 0])
.parallels([50, 60])
.scale(5000)
.translate([width / 2, height / 2]);
d3.json("tw.json", function(error, tw) {
var path = d3.geo.path().projection( projection ).pointRadius(2);
svg.append("path")
.datum(topojson.object(tw, tw.objects.subunit))
.attr("d", path);
svg.selectAll(".subunit").data( topojson.object(tw, tw.objects.subunit).geometries )
.enter()
.append("path")
.attr("class" , function( d ){ return "subunit " + d.id; } )
.attr("d" , path );
svg.selectAll(".subunit-label")
.data(topojson.object(tw, tw.objects.subunit).geometries)
.enter().append("text")
.attr("class", function(d) { return "subunit-label " + d.id; })
.attr("transform", function(d) { return "translate(" + path.centroid(d) + ")"; })
.attr("dy", ".35em")
.text(function(d) { return d.properties.name; });
svg.selectAll(".loc-label")
.data(topojson.object(tw, tw.objects.places).geometries)
.enter()
.append("circle")
.attr("class" , function(d) { return ".loc-label " + d.properties.name;} )
.attr("transform", function(d) { return "translate(" + projection(d.coordinates) + ")"; })
.attr("r" , 3 )
.style("fill" , "black")
.on('mouseover' , function(d , i){
show_info( d , i);
})
.on("mouseout" , function(d){
hidden_info();
});
svg.selectAll(".place-label")
.data(topojson.object(tw, tw.objects.places).geometries)
.enter().append("text")
.attr("class", "place-label")
.attr("transform", function(d) { return "translate(" + projection(d.coordinates) + ")"; })
.attr("dx" , ".35em" )
.attr("dy", ".35em")
.text(function(d) { return d.properties.name; });
svg.append("image").attr("id" , "pop_rect" );
});
</script>
</body>