-
Notifications
You must be signed in to change notification settings - Fork 0
/
index_pan.html
89 lines (71 loc) · 1.83 KB
/
index_pan.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
<!--http://bl.ocks.org/d3noob/5193723-->
<!DOCTYPE html>
<meta charset="utf-8">
<style>
path {
stroke: white;
stroke-width: 0.25px;
fill: grey;
}
.feature {
fill: #ccc;
cursor: pointer;
}
.feature.active {
fill: orange;
}
</style>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/topojson.v0.min.js"></script>
<script>
var width = 990,
height = 700
active = d3.select(null);
var projection = d3.geo.mercator()
//.center([0, 55])
// .rotate([-180,0]);
.scale(130)
.translate([width / 2, height / 1.5]);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
var path = d3.geo.path()
.projection(projection);
var g = svg.append("g");
// load and display the World
d3.json("refs/all.topojson", function(error, topology) {
g.selectAll("path")
.data(topojson.object(topology, topology.objects.Continents)
.geometries)
.enter()
.append("path")
.attr("d", path)
.attr("class", "feature")
.on("click", clicked);
});
// zoom and pan
var zoom = d3.behavior.zoom()
.on("zoom", zoomed);
svg.call(zoom)
function clicked(d) {
if (active.node() === this) return reset();
active.classed("active", false);
active = d3.select(this).classed("active", true);
}
function reset() {
active.classed("active", false);
active = d3.select(null);
}
function zoomed() {
console.log("d3.event: ", d3.event)
console.log("d3.event.scale: ", d3.event.scale)
console.log("d3.event.translate: ", d3.event.translate)
g.attr("transform","translate("+
d3.event.translate.join(",")+")scale("+d3.event.scale+")");
// g.selectAll("path")
// .attr("d", path.projection(projection));
}
</script>
</body>
</html>