-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
146 lines (121 loc) · 4.74 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<!DOCTYPE html>
<!-- Original code from
Nelson Minar https://github.com/NelsonMinar/vector-river-map
and Mike Bostock http://bl.ocks.org/mbostock/5593150
Adapted by [email protected] for Moscow vector tile server with data-->
<meta charset="utf-8">
<style>
body { margin: 0; overflow: hidden;
font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
font-size: 11px; line-height: 16px; color:#fff; background-color: #222}
.map { position: relative; overflow: hidden; }
.info { position: absolute; bottom: 0px; right: 20px; background-color: rgba(255, 255, 255, 0.7) }
.layer { position: absolute; }
.tile { position: absolute; width: 256px; height: 256px; }
.tile path {
fill: #ddd;
}
#slide {
width:50%;
}
</style>
<body>
<div id="slider_cont">
<input style="width:50%;" id="slide" type="range" min="1800" max="2010" step="1" value="2011" onchange="updateYear(this.value)"/><span id="yeartext">1800...2010</span>
</div>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/d3.geo.tile.v0.min.js"></script>
<script>
var width = Math.max(960, window.innerWidth),
height = Math.max(500, window.innerHeight),
prefix = prefixMatch(["webkit", "ms", "Moz", "O"]);
var tile = d3.geo.tile()
.size([width, height]);
var projection = d3.geo.mercator()
.scale((1 << 20) / 2 / Math.PI)
.translate([-width / 2, -height / 2]); // just temporary
var tileProjection = d3.geo.mercator();
var tilePath = d3.geo.path()
.projection(tileProjection);
var zoom = d3.behavior.zoom()
.scale(projection.scale() * 2 * Math.PI)
.scaleExtent([1<<12,1<<23])
.translate(projection([37.6, 55.75]).map(function(x) { return -x; }))
.on("zoom", zoomed);
var map = d3.select("body").append("div")
.attr("class", "map")
.style("width", width + "px")
.style("height", height + "px")
.call(zoom)
.on("mousemove", mousemoved);
var layer = map.append("div")
.attr("class", "layer");
var info = map.append("div")
.attr("class", "info");
zoomed();
updateYear(2010);
function updateYear(year) {
d3.selectAll('path').style('display',function(d){ if (d.properties.year<=year) {return null} else return 'none' ;});
d3.select('#yeartext').text('1800...'+year);
}
function zoomed() {
var tiles = tile
.scale(zoom.scale())
.translate(zoom.translate())
();
projection
.scale(zoom.scale() / 2 / Math.PI)
.translate(zoom.translate());
var image = layer
.style(prefix + "transform", matrix3d(tiles.scale, tiles.translate))
.selectAll(".tile")
.data(tiles, function(d) { return d; });
image.exit()
.each(function(d) { this._xhr.abort(); })
.remove();
image.enter().append("svg")
.attr("class", "tile")
.style("left", function(d) { return d[0] * 256 + "px"; })
.style("top", function(d) { return d[1] * 256 + "px"; })
.each(function(d) {
var svg = d3.select(this);
this._xhr = d3.json("http://54.72.144.192:8001/moscow/" + d[2] + "/" + d[0] + "/" + d[1] + ".json", function(error, json) {
var k = Math.pow(2, d[2]) * 256; // size of the world in pixels
tilePath.projection()
.translate([k / 2 - d[0] * 256, k / 2 - d[1] * 256]) // [0°,0°] in pixels
.scale(k / 2 / Math.PI);
svg.selectAll("path")
.data(json.features)
.enter().append("path")
//.attr("style", function(d) { return "stroke-width: " + d.properties.strahler/2 + "px;" })
.attr("d", function(d) { return tilePath(d); })
.style("class",function(d){
if (d.properties.year>1991) return "#21f3f1"
if (d.properties.year>1982) return "#21f321"
if (d.properties.year>1964) return "#f3f121"
if (d.properties.year>1953) return "#ffa349"
if (d.properties.year>1917) return "#f65252"
if (d.properties.year>0) return "#f652f4"
return "#444"
});
});
});
}
function mousemoved() {
info.text(formatLocation(projection.invert(d3.mouse(this)), zoom.scale()));
}
function matrix3d(scale, translate) {
var k = scale / 256, r = scale % 1 ? Number : Math.round;
return "matrix3d(" + [k, 0, 0, 0, 0, k, 0, 0, 0, 0, k, 0, r(translate[0] * scale), r(translate[1] * scale), 0, 1 ] + ")";
}
function prefixMatch(p) {
var i = -1, n = p.length, s = document.body.style;
while (++i < n) if (p[i] + "Transform" in s) return "-" + p[i].toLowerCase() + "-";
return "";
}
function formatLocation(p, k) {
var format = d3.format("." + Math.floor(Math.log(k) / 2 - 2) + "f");
return (p[1] < 0 ? format(-p[1]) + "°S" : format(p[1]) + "°N") + " "
+ (p[0] < 0 ? format(-p[0]) + "°W" : format(p[0]) + "°E");
}
</script>