-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
398 lines (362 loc) · 12.2 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
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width,initial-scale=1" />
<link
rel="stylesheet"
href="https://unpkg.com/[email protected]/dist/leaflet.css"
integrity="sha256-sA+zWATbFveLLNqWO2gtiw3HL/lh1giY/Inf1BJ0z14="
crossorigin=""
/>
<script
src="https://unpkg.com/[email protected]/dist/leaflet.js"
integrity="sha256-o9N1jGDZrf5tS+Ft4gbIK7mYMipq9lqpVJ91xHSyKhg="
crossorigin=""
></script>
<script src="https://unpkg.com/@turf/turf@6/turf.min.js"></script>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Open+Sans&family=Playfair+Display:wght@500&display=swap"
rel="stylesheet"
/>
<style>
main {
display: flex;
flex-direction: column;
margin: 20px auto;
max-width: 1500px;
color: #444;
padding: 0 25px;
font-family: "Open Sans", sans-serif !important;
position: relative;
}
h1,
h2 {
font-family: "Playfair Display", serif;
margin: 0.2rem 0rem;
}
#map {
width: 100%;
height: 70vh;
}
#legend {
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: space-around;
margin-bottom: 1rem;
}
.col {
display: flex;
flex-direction: column;
}
.icon {
width: auto;
height: 1rem;
}
.triangle {
height: inherit;
width: inherit;
display: inherit;
transform: rotate(180deg);
}
.circle-1 {
border-radius: 16px;
display: inline-block;
margin-right: 0.3rem;
margin-left: 0.05rem;
/* border: 1px solid #fff; */
}
.circle-2 {
border-radius: 16px;
display: inline-block;
margin-right: 0.5rem;
margin-left: 0.3rem;
margin-bottom: 0.2em;
/* border: 1px solid #fff; */
}
.buffer {
width: 0.8em;
height: 0.8em;
display: inline-block;
margin-right: 0.2rem;
}
.leaflet-popup-content p {
margin: 0.5rem 0;
}
.not-highlight {
background-color: #ff214f;
color: white;
font-weight: 600;
}
</style>
</head>
<body>
<main>
<h1>Expanding Open Space</h1>
<h2>Schoolyards to Playgrounds</h2>
<hr />
<div id="legend">
<div class="col">
<label class="checkbox"
><input type="checkbox" checked data-layer="isInProgram" />
<span
style="background-color: #084eff; width: 0.8em; height: 0.8em"
class="circle-1"
></span
>Schoolyard in program</label
>
<label class="checkbox"
><input type="checkbox" checked data-layer="notInProgram" />
<span style="width: 0.8em; height: 0.8em">
<svg class="triangle" viewBox="0 0 100 100">
<polygon fill="#f9466b" points="50 15, 100 100, 0 100" />
</svg> </span
>Schoolyard <strong>NOT</strong> in program</label
>
<label class="checkbox"
><input type="checkbox" data-layer="playgrounds" />
<span
style="background-color: #007600; width: 0.4em; height: 0.4em"
class="circle-2"
></span
>NYC Parks Playground</label
>
</div>
<div class="col">
<h4
style="
margin: 0.1rem 0 0 0;
padding-top: 0.1rem;
border-top: solid 1px rgba(100, 100, 100, 0.2);
"
>
Within 5 mins
<img class="icon" src="walking.png" alt="walking" />(1/4 mile)
</h4>
<label class="checkbox"
><input type="checkbox" checked data-layer="isInProgramBuffer" />
<span style="background-color: #9bb5f3" class="buffer"></span
>Schoolyard in program</label
>
<label class="checkbox"
><input type="checkbox" checked data-layer="notInProgramBuffer" />
<span style="background-color: #ffbfcc" class="buffer"></span
>Schoolyard in <strong>NOT</strong> program</label
>
</div>
</div>
<div id="map"></div>
<p style="font-size: small">
Produced by the Civic Innovation Lab at
<a href="https://beta.nyc/">BetaNYC.</a>
<b> Data Sources:</b>
<a
href="https://data.cityofnewyork.us/dataset/Schoolyard-to-Playgrounds/dbmp-698d"
>Schoolyard to Playgrounds</a
>, <a
href="https://data.cityofnewyork.us/Environment/Directory-of-Playgrounds/59gn-q4ai"
>Playgrounds</a
>
#OpenData. Read more about the previous Schoolyards to Playgrounds
program
<a href="https://www.nycgovparks.org/greening/planyc/schoolyards"
>here</a
>.
</p>
<p style="font-size: small">
<strong>Note: </strong> Some points might be offset from school by a few
yards. This is due to some errors in the dataset. Last updated January 16, 2025.
</p>
</main>
<script src="data/isInProgram_0.js"></script>
<script src="data/hasSchoolYardNotInProgramActual_3.js"></script>
<script src="data/playgrounds_coords_7.js"></script>
<script>
// ASK ZHI-- not sure what's wrong with this code but something is breaking the map from loading
// is it because I didn't return map at the end?
//ZHI: you need to init mapContainer so
// const mapContainer = document.getElementById('map')
// const settings = {
// maxZoom: 20,
// minZoom: 11,
// bounds: L.latLngBounds([40.496133, -74.2555913], [40.9155327, -73.30078125])
// };
// const map = L.map(mapContainer, { ...settings }).setView([40.67, -73.85], 11);
// L.tileLayer(
// 'https://cartodb-basemaps-{s}.global.ssl.fastly.net/rastertiles/voyager_labels_under/{z}/{x}/{y}{r}.png',
// {
// ...settings,
// attribution:
// 'Carto | © <a href="http://osm.org/copyright">OSM</a> contributors'
// }
// ).addTo(map);
const map = L.map("map").setView([40.7831, -73.949], 13);
let baseMap = L.tileLayer(
"https://api.mapbox.com/styles/v1/zhik/cl9ellgx3000v15mqnndy3zoh/tiles/256/{z}/{x}/{y}@2x?access_token=pk.eyJ1IjoiemhpayIsImEiOiJjaW1pbGFpdHQwMGNidnBrZzU5MjF5MTJiIn0.N-EURex2qvfEiBsm-W9j7w",
{
attribution:
'© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors © Mapbox',
maxZoom: 18,
minZoom: 11,
bounds: L.latLngBounds(
[40.496133, -74.5555913],
[40.9155327, -73.30078125]
),
attribution:
'Carto | © <a href="http://osm.org/copyright">OSM</a> contributors',
}
).addTo(map);
// you can't see them markers with this code
function createTriangleMarker(feature, latlng) {
const icon = L.divIcon({
className: "leaflet-icon",
html: `<svg class="triangle" viewBox="0 0 100 100">
<polygon fill="#f9466b" points="50 15, 100 100, 0 100"/>
</svg>`,
iconSize: [12, 12],
iconAnchor: [6, 12],
});
return L.marker(latlng, { icon });
}
// let layer = L.geoJSON(json_isInProgram_0.features, {
// pointToLayer: createMarker,
// onEachFeature: (feature, layer) => {
// if (feature.properties && feature.properties.label) {
// layer.bindPopup(feature.properties.label, {
// closeButton: false,
// autoPan: false,
// offset: L.point(0, 0)
// });
// }
// }
// }).addTo(map);
let isInProgramMarkerStyle = {
radius: 5,
fillColor: "#084eff",
color: "#000",
weight: 0,
opacity: 1,
fillOpacity: 0.8,
};
let playgroundsMarkerStyle = {
radius: 3,
fillColor: "#007600",
color: "#000",
weight: 0,
opacity: 1,
fillOpacity: 0.8,
};
function createSchoolPopup(feature, layer) {
if (feature.properties && feature.properties.Primary_Address) {
return layer.bindPopup(
`<h4>${feature.properties.Buidling_Name}</h4>
<p><a target="_blank" href="http://maps.google.com/?q=${
feature.properties.Primary_Address
};near=new+york">${feature.properties.Primary_Address}</a></p>
${
+feature.properties.isInProgram
? "<p>A part of the Schoolyards to Playgrounds program</p>"
: "<p><span class='not-highlight'>NOT</span> a part of the Schoolyards to Playgrounds program</p>"
}
`,
{
autoPan: false,
offset: L.point(0, 0),
}
);
}
}
let isInProgram = L.geoJSON(json_isInProgram_0.features, {
pointToLayer: function (feature, latlng) {
return L.circleMarker(latlng, isInProgramMarkerStyle);
},
onEachFeature: createSchoolPopup,
}).addTo(map);
let notInProgram = L.geoJSON(json_hasSchoolYardNotInProgramActual_3, {
pointToLayer: createTriangleMarker,
onEachFeature: createSchoolPopup,
}).addTo(map);
let playgrounds = L.geoJSON(json_playgrounds_coords_7, {
pointToLayer: function (feature, latlng) {
return L.circleMarker(latlng, playgroundsMarkerStyle);
},
onEachFeature: (feature, layer) => {
if (feature.properties && feature.properties.Name) {
layer.bindPopup(feature.properties.Name, {
autoPan: false,
offset: L.point(0, 0),
});
}
},
}); //.addTo(map);
//buffers
let isInProgramBuffer = L.geoJSON(
turf.dissolve(
turf.buffer(json_isInProgram_0, 0.25, { units: "miles" })
),
{
style: {
weight: 2,
opacity: 1,
color: "white",
fillColor: "#5d8afc",
dashArray: "3",
fillOpacity: 0.2,
},
}
);
//fix issue with buffer not working with an invaild geom
const notInSub = {
type: "FeatureCollection",
features: json_hasSchoolYardNotInProgramActual_3.features.filter(
(i) => i.geometry
),
};
let notInProgramBuffer = L.geoJSON(
turf.dissolve(turf.buffer(notInSub, 0.25, { units: "miles" })),
{
style: {
weight: 2,
opacity: 1,
color: "white",
fillColor: "#f9466b",
dashArray: "3",
fillOpacity: 0.2,
},
}
);
let baseMaps = {
"Carto Base Map": baseMap,
};
let overlayMaps = {
isInProgram: isInProgram,
notInProgram: notInProgram,
playgrounds: playgrounds,
isInProgramBuffer: isInProgramBuffer,
notInProgramBuffer: notInProgramBuffer,
};
// let layerControl = L.control.layers(baseMaps, overlayMaps).addTo(map);
//logic for legend inputs
const inputs = document.querySelectorAll("#legend input");
//reset inputs - refreshing doesn't reset them
Array.from(inputs).forEach((input) => {
const layer = input.dataset.layer;
if (["isInProgram", "notInProgram"].includes(layer)) {
input.checked = true;
} else {
input.checked = false;
}
});
//for each input add listen for change to toggle based on checked
Array.from(inputs).forEach((input) => {
input.addEventListener("change", (e) => {
const checked = e.target.checked;
const layer = overlayMaps[e.target.dataset.layer];
checked ? map.addLayer(layer) : map.removeLayer(layer);
});
});
</script>
</body>
</html>