-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
143 lines (95 loc) · 3.34 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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>React App</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src="https://d3js.org/d3.v3.min.js"></script>
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.20.1/mapbox-gl.js'></script>
<script src='https://api.tiles.mapbox.com/mapbox.js/plugins/turf/v2.0.0/turf.min.js'></script>
<!-- <script src='https://api.tiles.mapbox.com/mapbox.js/plugins/turf/v3.0.11/turf.min.js'></script> -->
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.20.1/mapbox-gl.css' rel='stylesheet' />
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }
</style>
</head>
<body>
<div id="map"></div>
<script type="text/javascript">
mapboxgl.accessToken = 'pk.eyJ1Ijoib25hIiwiYSI6IlVYbkdyclkifQ.0Bz-QOOXZZK01dq4MuMImQ';
var bbox = [40.21,-2.54,52.69,12.46];
var cellWidth = 50;
var units = 'kilometers';
//var hex_url = 'https://raw.githubusercontent.com/onaio/turf-experiments/gh-pages/data/somhex20.geojson';
var tpm_url = 'https://raw.githubusercontent.com/onaio/turf-experiments/gh-pages/data/tpm.geojson';
var tpm_csv = 'https://raw.githubusercontent.com/onaio/turf-experiments/gh-pages/data/tpm_activities.csv';
var somhexbin_url = 'https://raw.githubusercontent.com/onaio/turf-experiments/gh-pages/data/sombuf-hex25.geojson';
var map = new mapboxgl.Map({
container: 'map', // container id
style: 'mapbox://styles/mapbox/light-v9', //stylesheet location
center: [41.7035862, 5.1584164], // starting position
zoom: 5 // starting zoom
});
var aggregations = [
{
aggregation: 'count',
inField: '',
outField: 'point_count'
}
];
// see if we can load this dynamically!
d3.json(tpm_url, function (error, tpm_data) {
d3.json(somhexbin_url, function (error, bufhex) {
//console.log(JSON.stringify(bufhex));
// This is what needs to work v
//var cliphexgrid = turf.intersect(bufhex,hexgrid);
// aggregate is for turf 2.0
var hexagg = turf.aggregate(bufhex,tpm_data,aggregations);
// collect is for turf 3.0
//var hexagg = turf.collect(bufhex,tpm_data,'','point_count');
//console.log(JSON.stringify(hexagg));
map.addSource('tpm_data', {
type: 'geojson',
data: tpm_data
});
var points_layer = map.addLayer({
'id': 'tpm_data',
'type': 'circle',
'source': 'tpm_data',
'paint': {
'circle-opacity': 1,
'circle-color': '#334d4d',
'circle-radius': 2
}
}, 'waterway-label');
map.on('load', function () {
map.addSource('somhex', {
'type': 'geojson',
'data': hexagg
}
);
map.addLayer({
'id': 'route',
'type': 'fill',
'source': 'somhex',
'paint': {
'fill-outline-color': '#ccc',
'fill-color': {
property: 'point_count',
stops: [
[0, 'transparent'],
[1, '#eff3ff'],
[100, '#08519c']] // #f00
},
'fill-opacity': 0.9
}
}, 'waterway-label');
});
});
});
</script>
</script>
</body>
</html>