Skip to content

Commit

Permalink
add wwa map
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-does-weather committed Nov 7, 2024
1 parent 36cf5aa commit 66860c3
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 0 deletions.
3 changes: 3 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
<li>
<a href="point-lookup/index.html">Point lookup</a>
</li>
<li>
<a href="wa-wa/index.html">WWA map</a>
</li>
</ul>
</body>
</html>
40 changes: 40 additions & 0 deletions wa-wa/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!doctype html>
<html lang="en-US">
<head>
<title>Wa Wa</title>
<link
rel="stylesheet"
href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css"
type="text/css"
/>
<style type="text/css">
body {
margin: 0;
padding: 0;
}

#switcher {
position: fixed;
top: 0;
right: 0;
padding: 8px;
background: white;
border-radius: 0 0 0 10px;
z-index: 1000;
}

#map {
height: 100vh;
width: 100vw;
}
</style>
</head>
<body>
<div id="switcher">
<button data-product="wwa">WWA</button> |
<button data-product="radar">Radar</button>
</div>
<div id="map"></div>
<script type="module" src="main.js"></script>
</body>
</html>
74 changes: 74 additions & 0 deletions wa-wa/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import * as leaflet from "https://unpkg.com/leaflet@1.9.4/dist/leaflet-src.esm.js";

var map = leaflet.map("map").setView([39.8282, -98.5696], 5);

leaflet
.tileLayer("https://tile.openstreetmap.org/{z}/{x}/{y}.png", {
maxZoom: 19,
attribution:
'&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
})
.addTo(map);

const layers = new Map([
[
"wwa",
leaflet.tileLayer.wms(
"https://mapservices.weather.noaa.gov/eventdriven/services/WWA/watch_warn_adv/MapServer/WMSServer",
{
layers: "0,1",
format: "image/png",
transparent: true,
},
),
],
[
"radar",
leaflet.tileLayer.wms(
"https://opengeo.ncep.noaa.gov/geoserver/conus/conus_bref_qcd/ows",
{
layers: "conus_bref_qcd",
format: "image/png",
transparent: true,
},
),
],
]);

let activeLayer = layers.get("wwa");
activeLayer.addTo(map);

map.on("click", (e) => {
const { latlng } = e;

const lat = Math.round(latlng.lat * 10_000) / 10_000;
const lng = Math.round(latlng.lng * 10_000) / 10_000;

leaflet
.popup(latlng, {
content: `<a href="https://beta.weather.gov/point/${lat}/${lng}">Open on beta</a><br><a href="https://weathergov-staging.app.cloud.gov/point/${lat}/${lng}">Open on staging</a>`,
})
.openOn(map);
});

Array.from(document.querySelectorAll("button[data-product]")).forEach(
(button) => {
button.addEventListener(
"click",
({
target: {
dataset: { product },
},
}) => {
const layer = layers.get(product);
if (layer) {
if (activeLayer) {
activeLayer.remove(map);
}
activeLayer = layer;
layer.addTo(map);
}
},
);
},
);

0 comments on commit 66860c3

Please sign in to comment.