-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheatmap.html
117 lines (111 loc) · 4.17 KB
/
heatmap.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Heatmap</title>
<meta
name="viewport"
content="initial-scale=1,maximum-scale=1,user-scalable=no"
/>
<script src="https://api.mapbox.com/mapbox-gl-js/v1.9.0/mapbox-gl.js"></script>
<link
href="https://api.mapbox.com/mapbox-gl-js/v1.9.0/mapbox-gl.css"
rel="stylesheet"
/>
<style>
body {
margin: 10;
padding: 10;
}
#map {
position: absolute;
top: 0;
bottom: 0;
/* height: 800px; */
width: 95%;
}
</style>
</head>
<body>
<div id="map"></div>
<script type="module">
// cities data: https://simplemaps.com/data/us-cities as csv file
// geojson converrsion: https://www.convertcsv.com/csv-to-geojson.htm
import util from 'https://backspaces.github.io/agentscript/src/util.js'
// import gis from 'https://backspaces.github.io/agentscript/src/gis.js'
// util.toWindow({ util, gis })
util.toWindow({ util })
const params = util.RESTapi({
min: 0,
max: Infinity,
})
const { min: minPopulation, max: maxPopulation } = params
console.log(minPopulation, maxPopulation, params)
// const circleRadius = Math.max(1, Math.log10(minPopulation))
mapboxgl.accessToken =
'pk.eyJ1IjoiYmFja3NwYWNlcyIsImEiOiJjanVrbzI4dncwOXl3M3ptcGJtN3oxMmhoIn0.x9iSCrtm0iADEqixVgPwqQ'
const map = new mapboxgl.Map({
container: 'map', // container id
style: 'mapbox://styles/mapbox/streets-v11',
center: [-100.334228, 40.236557], // https://www.latlong.net/
zoom: 3,
renderWorldCopies: false,
})
util.toWindow({ map })
map.on('load', function () {
map.addSource('citiesData', {
type: 'vector',
url: 'mapbox://backspaces.4bfnuolo',
})
map.addLayer({
id: `canned-heat`,
type: 'heatmap',
source: 'citiesData',
'source-layer': 'cities',
filter: [
'all',
['>=', ['get', 'population'], minPopulation],
['<=', ['get', 'population'], maxPopulation],
],
maxzoom: 16,
paint: {
// Increase the heatmap weight based on frequency and property magnitude
'heatmap-weight': 0.5,
'heatmap-intensity': 0.5,
'heatmap-color': [
'interpolate-lab',
['linear'],
['heatmap-density'],
0,
'rgba(0,0,0,0)',
0.01,
'rgba(0,64,0,0.4)',
1,
'rgba(255,0,0,0.8)',
],
// Adjust the heatmap radius by zoom level
'heatmap-radius': [
'interpolate',
['linear'],
['get', 'population'],
0,
1,
15000,
30,
],
// Transition from heatmap to circle layer by zoom level
'heatmap-opacity': [
'interpolate',
['linear'],
['zoom'],
7,
1,
9,
0,
],
},
})
})
</script>
</body>
</html>