Skip to content

Commit 0fec6bc

Browse files
committed
switch to watchduty
1 parent 8352aef commit 0fec6bc

File tree

1 file changed

+147
-12
lines changed

1 file changed

+147
-12
lines changed

src/components/wildfireMap.ts

+147-12
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,32 @@ async function make_fire_names(map: maplibregl.Map) {
3232
});
3333
}
3434

35+
function generateArrayInFormat(key: string, array: string[]) {
36+
/*[
37+
"in",
38+
[
39+
"get",
40+
"name"
41+
],
42+
[
43+
"literal",
44+
["Kenneth Fire"]
45+
]
46+
]
47+
*/
48+
49+
return ["in", ["get", key], ["literal", array]];
50+
51+
}
52+
53+
3554
export function makeFireMap(map: maplibregl.Map, chateaus_in_frame: Writable<string[]>) {
3655
console.log('load wildfire data');
3756

3857
const darkMode = determineDarkModeToBool();
3958

59+
const watchduty_proxy = "https://birch.catenarymaps.org/watchduty_tiles_proxy/{z}/{x}/{y}";
60+
4061
const evacuation_fire_url = "https://fireboundscache.catenarymaps.org/data/evac_california.json";
4162

4263
const modis_url = "https://raw.githubusercontent.com/catenarytransit/fire-bounds-cache/refs/heads/main/data/modis.json";
@@ -49,13 +70,77 @@ export function makeFireMap(map: maplibregl.Map, chateaus_in_frame: Writable<str
4970

5071
const fire_evac_manual = 'https://fireboundscache.catenarymaps.org/manual_data/evac.json';
5172

52-
//fire section
73+
const fire_evac_codes_california = "https://fireboundscache.catenarymaps.org/data/watchduty_events.json";
5374

5475
// map.addSource('arcgisfire', {
5576
// type: 'geojson',
5677
// data: national_usa_fire_arcgis_url
5778
//});
79+
80+
map.addSource("watchduty_proxy", {
81+
'type': 'vector',
82+
'tiles': [watchduty_proxy],
83+
});
5884

85+
function refresh_watchduty_source() {
86+
/*
87+
map.removeSource('watchduty_proxy');
88+
89+
map.addSource("watchduty_proxy", {
90+
'type': 'vector',
91+
'tiles': [watchduty_proxy + '?t=' + Date.now()],
92+
});
93+
94+
*/
95+
96+
}
97+
98+
function refresh_watchduty_evacs() {
99+
fetch(fire_evac_codes_california)
100+
.then(async (data) => await data.json())
101+
.then((cleaned_data: any) => {
102+
//combine all evacuation_orders_arr in every object in the array into a single array
103+
104+
console.log('refreshing evac sources from watchduty')
105+
106+
let combined_evacuation_orders_arr = cleaned_data.map((fire) => fire.evacuation_orders_arr).flat().filter((x) => typeof x === 'string');
107+
108+
let combined_evacuation_warnings_arr = cleaned_data.map((fire) => fire.evacuation_warnings_arr).flat().filter((x) => typeof x === 'string');
109+
110+
console.log('set evac to ', generateArrayInFormat("zone_name", combined_evacuation_orders_arr))
111+
112+
map.setFilter('zones-fill-watchduty-go', generateArrayInFormat("zone_name", combined_evacuation_orders_arr));
113+
map.setFilter('zones-fill-watchduty-warning', generateArrayInFormat("zone_name", combined_evacuation_warnings_arr));
114+
115+
map.setFilter('zones-fill-watchduty-go-txt', generateArrayInFormat("zone_name", combined_evacuation_orders_arr));
116+
map.setFilter('zones-fill-watchduty-warning-txt', generateArrayInFormat("zone_name", combined_evacuation_warnings_arr));
117+
});
118+
}
119+
120+
map.addLayer({
121+
'id': 'zones-fill-watchduty-go',
122+
source: "watchduty_proxy",
123+
'source-layer': 'zones',
124+
'type': 'fill',
125+
'paint': {
126+
'fill-color': '#dd3300',
127+
"fill-opacity": 0.2
128+
},
129+
filter: ["==", "a", "b"]
130+
});
131+
132+
map.addLayer({
133+
'id': 'zones-fill-watchduty-warning',
134+
source: "watchduty_proxy",
135+
'source-layer': 'zones',
136+
'type': 'fill',
137+
'paint': {
138+
'fill-color': '#cc9900',
139+
"fill-opacity": 0.2
140+
},
141+
filter: ["==", "a", "b"]
142+
});
143+
59144
function fetch_and_update_layer(source_id:string, url:string) {
60145
fetch(url)
61146
.then(async (data) => await data.json())
@@ -69,10 +154,10 @@ export function makeFireMap(map: maplibregl.Map, chateaus_in_frame: Writable<str
69154
.catch((err) => console.error(err));
70155
}
71156

72-
map.addSource('evacuation_ca_fire', {
73-
type: 'geojson',
74-
data: evacuation_fire_url
75-
});
157+
// map.addSource('evacuation_ca_fire', {
158+
// type: 'geojson',
159+
// data: evacuation_fire_url
160+
//});
76161

77162
map.addSource('los_angeles_city_fire_evac', {
78163
type: 'geojson',
@@ -117,23 +202,25 @@ export function makeFireMap(map: maplibregl.Map, chateaus_in_frame: Writable<str
117202
.catch((err) => console.error(err));
118203
}*/
119204

120-
205+
refresh_watchduty_evacs();
121206

122207
setInterval(() => {
123-
124-
fetch_and_update_layer('evacuation_ca_fire', evacuation_fire_url);
208+
refresh_watchduty_evacs();
209+
//fetch_and_update_layer('evacuation_ca_fire', evacuation_fire_url);
125210

126211
fetch_and_update_layer('los_angeles_city_fire_evac', los_angeles_fire_evac);
127212

128213
fetch_and_update_layer('firenames', firenamesurl);
129214

130215
fetch_and_update_layer('fire_evac_manual', fire_evac_manual);
216+
217+
refresh_watchduty_source();
131218

132219
}, 30_000);
133220

134221
setInterval(() => {
135222
fetch_and_update_layer('modis', modis_url)
136-
}, 60_000);
223+
}, 120_000);
137224

138225
/*
139226
map.addLayer({
@@ -241,7 +328,7 @@ export function makeFireMap(map: maplibregl.Map, chateaus_in_frame: Writable<str
241328
},
242329
minzoom: 5
243330
});
244-
331+
/*
245332
map.addLayer({
246333
source: 'evacuation_ca_fire',
247334
id: 'evacuation_ca_fire_bounds',
@@ -270,7 +357,7 @@ export function makeFireMap(map: maplibregl.Map, chateaus_in_frame: Writable<str
270357
]
271358
},
272359
minzoom: 5
273-
});
360+
});*/
274361

275362
map.addLayer({
276363
source: 'los_angeles_city_fire_evac',
@@ -359,6 +446,7 @@ export function makeFireMap(map: maplibregl.Map, chateaus_in_frame: Writable<str
359446
minzoom: 5
360447
});
361448
*/
449+
/*
362450
map.addLayer({
363451
source: 'evacuation_ca_fire',
364452
id: 'evacuation_ca_fire_txt',
@@ -380,7 +468,7 @@ export function makeFireMap(map: maplibregl.Map, chateaus_in_frame: Writable<str
380468
'text-font': ['Barlow Bold']
381469
},
382470
minzoom: 6
383-
});
471+
});*/
384472

385473
map.addLayer({
386474
source: 'los_angeles_city_fire_evac',
@@ -412,6 +500,53 @@ export function makeFireMap(map: maplibregl.Map, chateaus_in_frame: Writable<str
412500
minzoom: 6
413501
});
414502

503+
map.addLayer({
504+
'id': 'zones-fill-watchduty-go-txt',
505+
source: "watchduty_proxy",
506+
'source-layer': 'zones',
507+
type: 'symbol',
508+
'layout': {
509+
'text-field': "Mandatory Evacuation",
510+
'text-size': [
511+
"interpolate",
512+
["linear"],
513+
['zoom'],
514+
7,
515+
9,
516+
9,
517+
13
518+
],
519+
'text-font': ['Barlow Bold']
520+
},
521+
paint: {
522+
'text-color': darkMode ? '#ccaaaa' : '#cc0000'
523+
},
524+
filter: ["==", "a", "b"]
525+
});
526+
527+
map.addLayer({
528+
'id': 'zones-fill-watchduty-warning-txt',
529+
source: "watchduty_proxy",
530+
'source-layer': 'zones',
531+
type: 'symbol',
532+
'layout': {
533+
'text-field': "Evacuation Warning",
534+
'text-size': [
535+
"interpolate",
536+
["linear"],
537+
['zoom'],
538+
7,
539+
9,
540+
9,
541+
13
542+
],
543+
'text-font': ['Barlow Bold']
544+
},
545+
paint: {
546+
'text-color': darkMode ? '#ccaaaa' : '#cc0000'
547+
},
548+
filter: ["==", "a", "b"]
549+
});
415550
map.addLayer({
416551
source: 'fire_evac_manual',
417552
id: 'fire_evac_manual_txt',

0 commit comments

Comments
 (0)