2026-01-21 15:15:24 +00:00
|
|
|
var map = null;
|
|
|
|
|
// A map that shows multiple single point locations.
|
|
|
|
|
// Points have additional detail popups.
|
|
|
|
|
class MapMultipoint extends HTMLElement {
|
|
|
|
|
constructor() {
|
|
|
|
|
super();
|
|
|
|
|
|
|
|
|
|
// Create a shadow DOM
|
2026-03-05 02:13:36 +00:00
|
|
|
this.attachShadow({ mode: "open" });
|
2026-01-21 15:15:24 +00:00
|
|
|
|
|
|
|
|
// Initial render
|
|
|
|
|
this.render();
|
|
|
|
|
|
2026-03-07 01:45:53 +00:00
|
|
|
// Keep track of any 'on' calls to add to the map as soon as we create it.
|
|
|
|
|
this._preOns = [];
|
2026-01-21 15:15:24 +00:00
|
|
|
this._map = null;
|
2026-03-05 15:45:59 +00:00
|
|
|
this._markers = [];
|
2026-01-21 15:15:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Lifecycle: when element is added to the DOM
|
|
|
|
|
connectedCallback() {
|
|
|
|
|
// Initialize the map when the element is added to the DOM
|
|
|
|
|
setTimeout(() => this._initializeMap(), 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
disconnectedCallback() {
|
|
|
|
|
if (this._map) {
|
|
|
|
|
this._map.remove();
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-03-19 19:16:39 +00:00
|
|
|
_bounds() {
|
2026-03-05 13:27:16 +00:00
|
|
|
const xmin = parseFloat(this.getAttribute("xmin"));
|
|
|
|
|
const ymin = parseFloat(this.getAttribute("ymin"));
|
|
|
|
|
const xmax = parseFloat(this.getAttribute("xmax"));
|
|
|
|
|
const ymax = parseFloat(this.getAttribute("ymax"));
|
2026-03-14 16:55:40 +00:00
|
|
|
let bounds = [
|
2026-03-05 13:27:16 +00:00
|
|
|
[xmin, ymin],
|
|
|
|
|
[xmax, ymax],
|
|
|
|
|
];
|
2026-03-14 16:55:40 +00:00
|
|
|
if (xmin == 0 || xmax == 0 || ymin == 0 || ymax == 0) {
|
|
|
|
|
bounds = [
|
|
|
|
|
[-125, 25],
|
|
|
|
|
[-70, 50],
|
|
|
|
|
];
|
|
|
|
|
}
|
2026-03-19 19:16:39 +00:00
|
|
|
return bounds;
|
|
|
|
|
}
|
|
|
|
|
_initializeMap() {
|
|
|
|
|
const bounds = this._bounds();
|
|
|
|
|
const organization_id = Number(this.getAttribute("organization-id") || 0);
|
|
|
|
|
const tegola = this.getAttribute("tegola");
|
2026-01-21 15:15:24 +00:00
|
|
|
|
|
|
|
|
const mapElement = this.shadowRoot.querySelector("#map");
|
2026-03-05 02:13:36 +00:00
|
|
|
this._map = new maplibregl.Map({
|
2026-03-05 19:09:45 +00:00
|
|
|
bounds: bounds,
|
2026-01-21 15:15:24 +00:00
|
|
|
container: mapElement,
|
2026-03-05 02:13:36 +00:00
|
|
|
style: "https://tiles.stadiamaps.com/styles/osm_bright.json",
|
2026-01-21 15:15:24 +00:00
|
|
|
});
|
|
|
|
|
this._map.on("load", () => {
|
2026-03-05 13:27:16 +00:00
|
|
|
if (organization_id != 0) {
|
|
|
|
|
this._map.addSource("tegola", {
|
|
|
|
|
type: "vector",
|
|
|
|
|
tiles: [
|
|
|
|
|
`${tegola}maps/nidus/{z}/{x}/{y}?id=${organization_id}&organization_id=${organization_id}`,
|
|
|
|
|
],
|
|
|
|
|
});
|
|
|
|
|
this._map.addLayer({
|
|
|
|
|
id: "service-area",
|
|
|
|
|
source: "tegola",
|
|
|
|
|
"source-layer": "service-area-bounds",
|
|
|
|
|
type: "line",
|
|
|
|
|
paint: {
|
|
|
|
|
"line-color": "#f00",
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
2026-03-05 02:13:36 +00:00
|
|
|
this.dispatchEvent(new CustomEvent("load"), {
|
2026-01-21 15:15:24 +00:00
|
|
|
bubbles: true,
|
|
|
|
|
composed: true, // Allows event to cross shadow DOM boundary
|
|
|
|
|
detail: {
|
2026-03-05 02:13:36 +00:00
|
|
|
map: this,
|
|
|
|
|
},
|
2026-01-21 15:15:24 +00:00
|
|
|
});
|
|
|
|
|
});
|
2026-03-07 01:45:53 +00:00
|
|
|
for (const on of this._preOns) {
|
2026-03-20 16:37:46 +00:00
|
|
|
this._map.on(...on);
|
2026-03-07 01:45:53 +00:00
|
|
|
}
|
2026-01-21 15:15:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Initial render of component
|
|
|
|
|
render() {
|
|
|
|
|
this.shadowRoot.innerHTML = `
|
|
|
|
|
<style>
|
2026-03-05 15:45:59 +00:00
|
|
|
@import url("//unpkg.com/maplibre-gl@5.0.1/dist/maplibre-gl.css");
|
2026-01-21 15:15:24 +00:00
|
|
|
#map {
|
2026-03-05 02:13:36 +00:00
|
|
|
height: 100%;
|
2026-03-05 15:45:59 +00:00
|
|
|
width: 100%;
|
2026-01-21 15:15:24 +00:00
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|
|
2026-03-05 03:53:26 +00:00
|
|
|
<div id="map"></div>
|
2026-01-21 15:15:24 +00:00
|
|
|
`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
addLayer(a) {
|
|
|
|
|
return this._map.addLayer(a);
|
|
|
|
|
}
|
|
|
|
|
addSource(a, b) {
|
|
|
|
|
return this._map.addSource(a, b);
|
|
|
|
|
}
|
2026-03-11 15:50:12 +00:00
|
|
|
flyTo(a, b) {
|
|
|
|
|
return this._map.flyTo(a, b);
|
|
|
|
|
}
|
2026-03-20 16:37:46 +00:00
|
|
|
getCanvas(...args) {
|
|
|
|
|
return this._map.getCanvas(...args);
|
|
|
|
|
}
|
|
|
|
|
getContainer(...args) {
|
|
|
|
|
return this._map.getContainer(...args);
|
|
|
|
|
}
|
2026-01-21 15:15:24 +00:00
|
|
|
jumpTo(args) {
|
|
|
|
|
return this._map.jumpTo(args);
|
|
|
|
|
}
|
2026-03-20 16:37:46 +00:00
|
|
|
on(...args) {
|
2026-03-07 01:45:53 +00:00
|
|
|
if (this._map != null) {
|
2026-03-20 16:37:46 +00:00
|
|
|
return this._map.on(...args);
|
2026-03-07 01:45:53 +00:00
|
|
|
} else {
|
2026-03-20 16:37:46 +00:00
|
|
|
this._preOns.push(args);
|
2026-03-07 01:45:53 +00:00
|
|
|
}
|
2026-01-21 15:15:24 +00:00
|
|
|
}
|
2026-02-05 01:22:47 +00:00
|
|
|
once(a, b) {
|
|
|
|
|
return this._map.once(a, b);
|
|
|
|
|
}
|
2026-03-11 15:50:12 +00:00
|
|
|
panTo(a, b) {
|
|
|
|
|
return this._map.panTo(a, b);
|
|
|
|
|
}
|
2026-01-21 15:15:24 +00:00
|
|
|
queryRenderedFeatures(a) {
|
|
|
|
|
return this._map.queryRenderedFeatures(a);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-19 19:16:39 +00:00
|
|
|
ClearMarkers() {
|
|
|
|
|
this._markers.forEach((marker) => marker.remove());
|
|
|
|
|
}
|
2026-03-05 16:04:58 +00:00
|
|
|
FitBounds(bounds, options) {
|
|
|
|
|
return this._map.fitBounds(bounds, options);
|
|
|
|
|
}
|
2026-03-19 19:16:39 +00:00
|
|
|
// Reset the view back to whatever the html properties define
|
|
|
|
|
ResetCamera() {
|
|
|
|
|
const bounds = this._bounds();
|
|
|
|
|
this.FitBounds(bounds, {
|
|
|
|
|
linear: false,
|
|
|
|
|
});
|
|
|
|
|
}
|
2026-02-04 23:57:44 +00:00
|
|
|
SetLayoutProperty(layout, property, value) {
|
|
|
|
|
return this._map.setLayoutProperty(layout, property, value);
|
|
|
|
|
}
|
2026-03-05 15:45:59 +00:00
|
|
|
SetMarkers(markers) {
|
|
|
|
|
console.log("Setting map markers", markers);
|
|
|
|
|
this._markers.forEach((marker) => marker.remove());
|
2026-03-10 04:20:55 +00:00
|
|
|
this._markers = markers;
|
|
|
|
|
for (let m of markers) {
|
|
|
|
|
m.addTo(this._map);
|
|
|
|
|
}
|
2026-03-05 15:45:59 +00:00
|
|
|
}
|
2026-01-21 15:15:24 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-05 02:13:36 +00:00
|
|
|
customElements.define("map-multipoint", MapMultipoint);
|