This repository was archived by the owner on Jun 3, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathindex.html
More file actions
151 lines (138 loc) · 4.96 KB
/
Copy pathindex.html
File metadata and controls
151 lines (138 loc) · 4.96 KB
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
147
148
149
150
151
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>OSM Activity</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }
#github-button { position: absolute; top: 15px; left: 15px; z-index: 1000; }
.mapboxgl-popup {
font: 12px/20px 'Helvetica Neue', Arial, Helvetica, sans-serif;
}
</style>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/Turf.js/3.0.14/turf.min.js'></script>
<script src='https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-supported/v1.2.0/mapbox-gl-supported.js'></script>
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.21.0/mapbox-gl.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.21.0/mapbox-gl.css' rel='stylesheet' />
</head>
<body>
<iframe id="github-button" src="https://ghbtns.com/github-btn.html?user=lukasmartinelli&repo=osm-activity&type=star&count=true&size=large" frameborder="0" scrolling="0" width="160px" height="30px"></iframe>
<div id='map'></div>
<script>
mapboxgl.accessToken = 'pk.eyJ1IjoibW9yZ2Vua2FmZmVlIiwiYSI6IjIzcmN0NlkifQ.0LRTNgCc-envt9d5MzR75w';
if (!mapboxgl.supported()) {
alert('Your browser does not support Mapbox GL');
}
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/morgenkaffee/cirypw54h004pgym67fet9chq',
center: [8.538961, 47.372476],
zoom: 1.1,
hash: true,
minZoom: 1,
maxZoom: 11,
});
map.addControl(new mapboxgl.Navigation());
function httpGetAsync(theUrl, callback) {
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
callback(xmlHttp.responseText);
}
xmlHttp.open("GET", theUrl, true); // true for asynchronous
xmlHttp.send(null);
}
google.charts.load('current', {
packages: ['corechart', 'line']
});
var bboxLayers = ['tile_updates_1', 'tile_updates_2', 'tile_updates_3', 'tile_updates_4', 'tile_updates_5', 'tile_updates_6', 'tile_updates_7'];
map.on('click', function(e) {
var features = map.queryRenderedFeatures(e.point, {
layers: bboxLayers
});
if (!features.length) {
return;
}
var feature = features[0];
var props = feature.properties;
var tile = [props.tile_x, props.tile_y, props.tile_z];
var ancestor = getAncestor(tile);
var centroid = turf.centroid(feature);
httpGetAsync('http://osm-activity.lukasmartinelli.ch/tiles/history/' + ancestor[2] + '/' + ancestor[0] + '/' + ancestor[1] + '.json', function(body) {
var tiles = JSON.parse(body);
var tileHistory = tiles[tile.join('/')];
var popup = new mapboxgl.Popup()
.setLngLat(centroid.geometry.coordinates)
.setHTML('<div id="chart_div"></div>')
.addTo(map);
var data = new google.visualization.DataTable();
data.addColumn('date', 'time');
data.addColumn('number', 'changes');
tileHistory.forEach(function(changes, idx) {
// Skip the beginnings
if (idx > 24) {
var date = new Date(2006 + (idx / 12), (idx) % 12);
console.log(date.toDateString());
data.addRow([date, changes])
}
});
var options = {
legend: 'none',
width: 550,
height: 300,
hAxis: {
title: 'Time'
},
vAxis: {
title: 'Changes'
},
colors: ['#238443'],
trendlines: {
0: {
type: 'linear',
color: '#addd8e',
opacity: .7
}
}
};
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, options);
});
});
// https://github.com/mapbox/tilebelt/blob/master/index.js
function getParent(tile) {
// top left
if (tile[0] % 2 === 0 && tile[1] % 2 === 0) {
return [tile[0] / 2, tile[1] / 2, tile[2] - 1];
}
// bottom left
if ((tile[0] % 2 === 0) && (!tile[1] % 2 === 0)) {
return [tile[0] / 2, (tile[1] - 1) / 2, tile[2] - 1];
}
// top right
if ((!tile[0] % 2 === 0) && (tile[1] % 2 === 0)) {
return [(tile[0] - 1) / 2, (tile[1]) / 2, tile[2] - 1];
}
// bottom right
return [(tile[0] - 1) / 2, (tile[1] - 1) / 2, tile[2] - 1];
}
function getAncestor(tile) {
var parent = getParent(tile);
if (parent[2] <= 5) {
return parent;
} else {
return this.getAncestor(parent);
}
}
map.on('mousemove', function(e) {
var features = map.queryRenderedFeatures(e.point, {
layers: bboxLayers
});
map.getCanvas().style.cursor = (features.length) ? 'pointer' : '';
});
</script>
</body>
</html>