forked from Wheels-of-Steel/wheels-of-steel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
map.html
130 lines (113 loc) · 4.38 KB
/
map.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
<html lang="en">
<head>
<title>Bootstrap 5 Website Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://api.mapbox.com/mapbox-gl-js/v3.2.0/mapbox-gl.css" rel="stylesheet">
<script src="https://api.mapbox.com/mapbox-gl-js/v3.2.0/mapbox-gl.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<style>
.fakeimg {
height: 200px;
background: #aaa;
}
body { margin: 0; padding: 0; }
#map { position: relative; top: 0; bottom: 0; width: 100%; height: 600px;}
</style>
</head>
<body>
<div class="container mt-5">
<div class="row">
<div class="col-sm-8" id="map">
</div>
</div>
</div>
<a id="downloadLink" href="" download="map.png">Download ↓</a>
<!-- <div class="mt-5 p-4 bg-dark text-white text-center">
<p>Footer</p>
</div> -->
<script>
mapboxgl.accessToken = 'pk.eyJ1IjoiZW1lcnlqNiIsImEiOiJjbHU0dGRkZzUxYWxwMm5wZHJ4em50M2czIn0.oLZ_d-htIuYQbIhVuiV_JA';
const map = new mapboxgl.Map({
container: 'map', // container ID
center: [ -113.49856196994591,53.540920434717556], // starting position [lng, lat]
zoom: 9, // starting zoom
style: 'mapbox://styles/mapbox/streets-v9',
preserveDrawingBuffer: true
});
function filterMap(layer_name, property_name, values) {
map.setFilter(layer_name, ['match', ['get', property_name], values, true, false]);
}
map.on('load', () => {
map.addSource('wards', {
type: 'geojson',
// Can also use a URL for the value for the `data` property.
data: 'backend/data_sets/Edmonton_wards.geojson'
});
map.addSource('routes', {
type: 'geojson',
data: 'backend/data_sets/ETS_routes.geojson'
});
map.addSource('stops', {
type: 'geojson',
data: 'backend/data_sets/ETS_stops.geojson'
});
map.addLayer({
'id': 'wards-layer',
'type': 'fill',
'source': 'wards',
'paint': {
'fill-color': {
type: 'identity',
property: 'color',
},
//'fill-opacity': 0.4
}
});
map.addLayer({
'id': 'wards-layer-outline',
'type': 'line',
'source': 'wards',
'paint': {
'line-color': 'rgba(0, 0, 0, 1)',
'line-width': 2
}
});
map.addLayer({
'id': 'routes-layer',
'type': 'line',
'source': 'routes',
'paint': {
'line-color': 'rgba(0, 0, 255, 1)',
'line-width': 2
}
});
map.addLayer({
'id': 'stops-layer',
'type': 'circle',
'source': 'stops',
'paint': {
'circle-color': 'rgba(255, 0, 0, 1)'
}
});
let layer_name = 'wards-layer';
let property_name = 'name_2';
//let values = ['Anirniq Ward', 'Dene Ward'];
let values = [];
filterMap(layer_name, property_name, values);
filterMap('wards-layer-outline', property_name, values);
filterMap('routes-layer', 'route_id', ['']);
filterMap('stops-layer', 'stop_id', ['']);
// const style = map.getStyle();
// style.layers.find(({ id }) => id === "wards-layer").paint['fill-color']['type'] = 'identity';
// style.layers.find(({ id }) => id === "wards-layer").paint['fill-color']['property'] = 'rgb(0, 255, 0)';
// map.setStyle(style);
});
// $('#downloadLink').click(function() {
// var img = map.getCanvas().toDataURL('image/png')
// this.href = img
// });
</script>
</body>