Skip to content

Commit

Permalink
Make regions w/o bulletin clickable
Browse files Browse the repository at this point in the history
Fixes #8.
  • Loading branch information
simon04 committed Apr 2, 2024
1 parent f70a042 commit 0afe073
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
nodeLinker: node-modules

npmScopes:
eaws:
npmRegistryServer: 'https://gitlab.com/api/v4/packages/npm/'
2 changes: 2 additions & 0 deletions bunfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[install.scopes]
"@eaws" = "https://gitlab.com/api/v4/packages/npm/"
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"vite": "^5.2.7"
},
"dependencies": {
"@eaws/outline_properties": "^6.2.0",
"ol": "^9.1.0",
"ol-ext": "^4.0.17",
"ol-pmtiles": "^0.4.0"
Expand Down
31 changes: 30 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import XYZ from "ol/source/XYZ";
import "ol/ol.css";
import "ol-ext/dist/ol-ext.css";
import "./style.css";
import eawsOutlineProperties from "@eaws/outline_properties/index.json";

import type {
FeatureProperties,
Expand Down Expand Up @@ -278,11 +279,22 @@ async function buildMarkerMap(bulletins: AvalancheBulletin[]) {

map.on("click", (e) => {
const regionID = findMicroRegionID(e);
if (!regionID) {
return;
}
const bulletin = bulletins.find((b) =>
b.regions?.some((r) => r.regionID === regionID),
);
if (regionID && bulletin) {
if (bulletin) {
popup.show(e.coordinate, formatBulletin(regionID, bulletin));
return;
}
const aws = eawsOutlineProperties
.filter((p) => regionID.startsWith(p.id))
.reduce((a, b) => (a.id.length > b.id.length ? a : b));
if (aws) {
popup.show(e.coordinate, formatEawsOutline(aws));
return;
}
});
}
Expand Down Expand Up @@ -365,3 +377,20 @@ function filterFeature(
(!properties.end_date || properties.end_date > today)
);
}

function formatEawsOutline(
aws: (typeof eawsOutlineProperties)[number],
): HTMLElement {
const result = document.createElement("dl");
for (const p of aws.aws) {
const provider = result.appendChild(document.createElement("dt"));
const providerLink = provider.appendChild(document.createElement("a"));
providerLink.innerText = p.name;
providerLink.href = Object.entries(p.url).find(
([id]) => id.length === 2,
)?.[1];
providerLink.target = "_blank";
providerLink.rel = "external";
}
return result;
}
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ __metadata:
version: 8
cacheKey: 10c0

"@eaws/outline_properties@npm:^6.2.0":
version: 6.2.0
resolution: "@eaws/outline_properties@npm:6.2.0::__archiveUrl=https%3A%2F%2Fgitlab.com%2Fapi%2Fv4%2Fprojects%2F25330421%2Fpackages%2Fnpm%2F%40eaws%2Foutline_properties%2F-%2F%40eaws%2Foutline_properties-6.2.0.tgz"
checksum: 10c0/e84bb3bbcece00d6f7ecfbb69dc7913c7a819e0c831b2a8940609b67108c23b4caa5cd9fc223c7ef20a87a471630d58b076cf22cae3a79093d6aae64ee650f0a
languageName: node
linkType: hard

"@esbuild/aix-ppc64@npm:0.20.2":
version: 0.20.2
resolution: "@esbuild/aix-ppc64@npm:0.20.2"
Expand Down Expand Up @@ -533,6 +540,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "eaws-bulletin-map@workspace:."
dependencies:
"@eaws/outline_properties": "npm:^6.2.0"
ol: "npm:^9.1.0"
ol-ext: "npm:^4.0.17"
ol-pmtiles: "npm:^0.4.0"
Expand Down

0 comments on commit 0afe073

Please sign in to comment.