-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcities.html
99 lines (93 loc) · 3.43 KB
/
cities.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Cities</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, // data has some really small towns!
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: 'cities',
type: 'circle',
source: 'citiesData',
'source-layer': 'cities',
filter: [
'all',
['>=', ['get', 'population'], minPopulation],
['<=', ['get', 'population'], maxPopulation],
],
layout: {},
paint: {
'circle-color': 'red',
// 'circle-radius': [
// '*',
// 0.5,
// ['log10', ['get', 'population']],
// ],
// Cody's nifty interpolation:
'circle-radius': [
'interpolate',
['linear'],
['get', 'population'],
0,
2,
1e6,
8,
],
},
})
})
</script>
</body>
</html>