-
Notifications
You must be signed in to change notification settings - Fork 2
/
example3.html
113 lines (84 loc) · 2.21 KB
/
example3.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
<!DOCTYPE html>
<meta charset="utf-8">
<body>
<style>
path {
fill: none;
stroke: #000;
stroke-width: 3px;
}
circle {
fill: steelblue;
stroke: #fff;
stroke-width: 3px;
}
</style>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/queue.v1.min.js"></script>
<script>
var width = 960,
height = 1160;
var projection = d3.geo.mercator().center([-73.98,40.75])
.scale(500000),
path = d3.geo.path().projection(projection);
function ready(error,json) {
var section = d3.select("body")
.append("svg")
.attr("width", width)
.attr("height", height)
.attr("id","svg");
var path2 = section.append("g")
.selectAll("path")
.data(json.features)
.enter()
.append("path").attr("class","thepath")
.style("stroke", "#333")
.style("stroke-dasharray","2,2")
.style('stroke-width',".9px")
.style("opacity",".5")
.attr("d", path)
.attr("fill", "none");
var pathz = section.append("g")
.selectAll("path")
.data(json.features)
.enter()
.append("path").attr("class","thepath")
.style("stroke", "#999")
.style('stroke-width',"1.5px")
.call(transition2)
var circle = d3.select("#svg").append("circle")
.attr("r", 7);
pathz
.attr("d", path)
.attr("fill", "none")
.call(transition)
function transition2(paths) {
paths.transition()
.duration(8500)
.attrTween("stroke-dasharray", tweenDash);
}
function transition() {
circle.transition()
.duration(8500)
.attrTween("transform", translateAlong(pathz.node()));
}
function translateAlong(paths) {
var l = paths.getTotalLength();
return function(d,i) {
return function(t) {
var p = paths.getPointAtLength(t * l);
return "translate(" + p.x + "," + p.y + ")";
};
};
}
function tweenDash() {
var l = this.getTotalLength(),
i = d3.interpolateString(0 + "," + l, l + "," + l);
return function(t) { return i(t); };
}
}
queue()
.defer(d3.json,'./data/test10.geojson').await(
ready
)
</script>