-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
205 lines (184 loc) · 5.61 KB
/
index.html
File metadata and controls
205 lines (184 loc) · 5.61 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<title>Show and hide layers</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.53.1/mapbox-gl.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.53.1/mapbox-gl.css' rel='stylesheet' />
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }
</style>
</head>
<body>
<style>
#menu {
background: #fff;
position: absolute;
z-index: 1;
top: 10px;
right: 10px;
border-radius: 3px;
width: 120px;
border: 1px solid rgba(0,0,0,0.4);
font-family: 'Open Sans', sans-serif;
}
#menu a {
font-size: 13px;
color: #404040;
display: block;
margin: 0;
padding: 0;
padding: 10px;
text-decoration: none;
border-bottom: 1px solid rgba(0,0,0,0.25);
text-align: center;
}
#menu a:last-child {
border: none;
}
#menu a:hover {
background-color: #f8f8f8;
color: #404040;
}
#menu a.active {
background-color: #3887be;
color: #ffffff;
}
#menu a.active:hover {
background: #3074a4;
}
</style>
<nav id="menu"></nav>
<div id="map"></div>
<script>
mapboxgl.accessToken = 'pk.eyJ1IjoiZWFydGhhZGFtIiwiYSI6ImNpenJpcTFkbjAwODUyd21mcXhhN3NscG4ifQ.5aXKquX7sLeQr6xFLdghFg';
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/dark-v9',
center: [-83.006448, 39.960111],
zoom: 13
});
map.on('load', function () {
map.addLayer({
"id": "sites",
"type": "circle",
"source": {
type: 'vector',
url: 'mapbox://smrtcbus.6z2iqsoc'
},
'source-layer': 'pantries-c99fm5',
"paint": {
'circle-radius': {
'base': 20,
'stops': [[12, 5], [22, 180]]
},
'circle-color': ['match',
['get', 'ACTIVE_FLAG'],
'Y', '#00ff00',
'N', '#ffff00',
/* other */ '#fff']
}
});
// Create a popup, but don't add it to the map yet.
var popup = new mapboxgl.Popup({
closeButton: false,
closeOnClick: false
});
map.addLayer({
'id': 'stores',
'type': 'circle',
'source': {
type: 'vector',
url: 'mapbox://smrtcbus.cficgu1f'
},
'source-layer': 'Stores-0pwhm7',
'paint': {
// make circles larger as the user zooms from z12 to z22
'circle-radius': {
'base': 50,
'stops': [[12, 10], [22, 180]]
},
// color circles by ethnicity, using a match expression
// https://docs.mapbox.com/mapbox-gl-js/style-spec/#expressions-match
'circle-color': '#e55e5e'
}
});
map.addLayer({
'id': 'routes',
'type': 'line',
'source': {
type: 'vector',
url: 'mapbox://smrtcbus.8lukhiwf'
},
'source-layer': 'COTA_Lines-7qn21h',
'layout': {
'visibility': 'visible',
'line-join': 'round',
'line-cap': 'round'
},
'paint': {
'line-color': '#877b59',
'line-width': 1
}
});
map.on('mouseover', 'sites', function(e) {
// Change the cursor style as a UI indicator.
map.getCanvas().style.cursor = 'pointer';
// Populate the popup and set its coordinates
// based on the feature found.
popup.setLngLat(e.features[0].geometry.coordinates)
.setHTML(
"<h2>"+e.features[0].properties["NAME"]+"</h2>"+
"<b>Phone:</b> "+e.features[0].properties["Phone"]+"<br>"+
"<b>Address:</b> "+e.features[0].properties["Address"]+"<br>"+
"<b>Active?</b> "+e.features[0].properties["ACTIVE_FLAG"]
)
//.setHTML(e.features[0].properties.description)
.addTo(map);
});
map.on('mouseover', 'stores', function(e) {
// Change the cursor style as a UI indicator.
map.getCanvas().style.cursor = 'pointer';
// Populate the popup and set its coordinates
// based on the feature found.
popup.setLngLat(e.features[0].geometry.coordinates)
.setHTML(
"<h2>Donatos: "+ e.features[0].properties["Store Name"]+"</h2>"+
"<b>Address:</b> "+e.features[0].properties["Address"]+", "+e.features[0].properties["City"]
)
//.setHTML(e.features[0].properties.description)
.addTo(map);
});
map.on('click', function() {
map.getCanvas().style.cursor = '';
popup.remove();
});
});
var toggleableLayerIds = [ 'sites', 'stores','routes' ];
for (var i = 0; i < toggleableLayerIds.length; i++) {
var id = toggleableLayerIds[i];
var link = document.createElement('a');
link.href = '#';
link.className = 'active';
link.textContent = id;
link.onclick = function (e) {
var clickedLayer = this.textContent;
e.preventDefault();
e.stopPropagation();
var visibility = map.getLayoutProperty(clickedLayer, 'visibility');
if (visibility === 'visible') {
map.setLayoutProperty(clickedLayer, 'visibility', 'none');
this.className = '';
} else {
this.className = 'active';
map.setLayoutProperty(clickedLayer, 'visibility', 'visible');
}
};
var layers = document.getElementById('menu');
layers.appendChild(link);
}
</script>
</body>
</html>