Skip to content

Commit 15819c7

Browse files
Merge pull request #75 from CURENT/master
impactzone_v0
2 parents f7628ab + 3bef98a commit 15819c7

File tree

2 files changed

+107
-5
lines changed

2 files changed

+107
-5
lines changed

agvis/static/js/ZoneLayer.js

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
*/
2525
L.ZoneLayer = L.GeoJSON.extend({
2626
options: {
27+
geojsonUrls: [
28+
"/js/nerc_regions.geojson",
29+
"/js/us_states.geojson",
30+
"/js/impactzone.geojson",
31+
],
2732
/**
2833
* Determines which colors are assigned to what zones based on the GeoJSON data. Adjusting the return values of the switch statement
2934
* can change the colors of the zones. The cases for the switch statement will most likely have to be changed if a different
@@ -43,6 +48,14 @@ L.ZoneLayer = L.GeoJSON.extend({
4348
case 'TRE': return {color: "#0000ff"};
4449
case 'WECC': return {color: "#8000ff"};
4550
case '-': return {color: "#808080"};
51+
default:
52+
// Fallback style for non-NERC geojsons (e.g. US state boundaries, impactzone)
53+
return {
54+
color: "#666666",
55+
weight: 1,
56+
fill: false,
57+
opacity: 0.7,
58+
};
4659
}
4760
}
4861
},
@@ -57,13 +70,28 @@ L.ZoneLayer = L.GeoJSON.extend({
5770
initialize(options) {
5871
L.GeoJSON.prototype.initialize.call(this, null, options);
5972
this._render = false;
60-
this._geojson = null;
73+
this._geojsons = [];
6174

6275
(async function(zonelayer) {
63-
let geojson = await fetch("/js/nerc_regions.geojson");
64-
geojson = await geojson.json();
76+
const urls = zonelayer.options.geojsonUrls || [];
77+
const requests = urls.map((url) => fetch(url));
78+
const responses = await Promise.allSettled(requests);
6579

66-
zonelayer._geojson = geojson;
80+
const loaded = [];
81+
for (let i = 0; i < responses.length; i++) {
82+
const result = responses[i];
83+
const url = urls[i];
84+
85+
if (result.status !== "fulfilled" || !result.value.ok) {
86+
console.warn("ZoneLayer failed to load:", url);
87+
continue;
88+
}
89+
90+
const geojson = await result.value.json();
91+
loaded.push(geojson);
92+
}
93+
94+
zonelayer._geojsons = loaded;
6795
zonelayer.toggleRender();
6896
})(this);
6997
},
@@ -109,7 +137,9 @@ L.ZoneLayer = L.GeoJSON.extend({
109137
console.log("Zone rendering: ", this._render);
110138

111139
if (this._render) {
112-
this.addData(this._geojson);
140+
for (let i = 0; i < this._geojsons.length; i++) {
141+
this.addData(this._geojsons[i]);
142+
}
113143
} else {
114144
this.clearLayers();
115145
}

agvis/static/js/impactzone.geojson

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
"type": "FeatureCollection",
3+
"features": [
4+
{
5+
"type": "Feature",
6+
"properties": {
7+
"name": "impactzone"
8+
},
9+
"geometry": {
10+
"type": "MultiPolygon",
11+
"coordinates": [
12+
[
13+
[
14+
[
15+
-83.935916,
16+
35.963107
17+
],
18+
[
19+
-83.943495,
20+
35.960709
21+
],
22+
[
23+
-83.956714,
24+
35.956398
25+
],
26+
[
27+
-83.965312,
28+
35.950685
29+
],
30+
[
31+
-83.972884,
32+
35.945126
33+
],
34+
[
35+
-83.973782,
36+
35.941542
37+
],
38+
[
39+
-83.969804,
40+
35.940295
41+
],
42+
[
43+
-83.961398,
44+
35.944659
45+
],
46+
[
47+
-83.956265,
48+
35.948918
49+
],
50+
[
51+
-83.947795,
52+
35.951204
53+
],
54+
[
55+
-83.941955,
56+
35.956866
57+
],
58+
[
59+
-83.935218,
60+
35.960657
61+
],
62+
[
63+
-83.935916,
64+
35.963107
65+
]
66+
]
67+
]
68+
]
69+
}
70+
}
71+
]
72+
}

0 commit comments

Comments
 (0)