viewof map = {
let container = html`<div style='height:600px;' />`;
yield container;
const client = tgmCoreClient("westcentraleurope");
const mapRef = (container.value = new maplibre.Map({
container,
center: source,
zoom: 11.5,
style: client.basemaps.getGLStyleURL("Light"),
attributionControl: false
})
.addControl(new maplibre.NavigationControl())
.addControl(
new maplibre.AttributionControl({
compact: true,
customAttribution: attribution
})
));
mapRef.on("mouseenter", "hexes", function () {
mapRef.getCanvas().style.cursor = "pointer";
});
mapRef.on("mouseleave", "hexes", function () {
mapRef.getCanvas().style.cursor = "";
});
mapRef.on("click", "hexes", function (e) {
var { lng, lat } = e.lngLat;
const time = e.features[0].properties.value;
const html = `<strong>${e.features[0].properties.pointid}</strong><br>${time} seconds`;
new maplibre.Popup().setLngLat({ lng, lat }).setHTML(html).addTo(mapRef);
});
await new Promise((resolve, reject) => {
mapRef.on("load", async () => {
mapRef.addSource("hexes", {
type: "geojson",
data: turf.featureCollection([])
});
mapRef.addLayer(
{
id: "hexes",
type: "fill",
source: "hexes",
layout: {},
paint: {
"fill-color": ["get", "color"],
"fill-opacity": 0.65,
"fill-outline-color": "rgba(0, 0, 0, 0)"
}
},
"place_other"
);
mapRef.addSource("polygon", {
type: "geojson",
data: turf.featureCollection([])
});
mapRef.addLayer(
{
id: "polygon",
type: "line",
source: "polygon",
layout: {},
paint: {
"line-color": "#FF0",
"line-width": 2.5
}
},
"place_other"
);
resolve();
});
});
invalidation.then(() => mapRef.remove());
yield container;
}