|
| 1 | +import * as pmtiles from "https://esm.run/pmtiles@4.3.0"; |
| 2 | +import maplibre from "https://esm.run/maplibre-gl@5.6.1"; |
| 3 | +import { layers, namedFlavor } from "https://esm.run/@protomaps/basemaps@5.5.1"; |
| 4 | + |
1 | 5 | class BuildsInfo extends HTMLElement { |
2 | 6 | static get observedAttributes() { |
3 | 7 | return ["endpoint", "fake"]; |
@@ -62,11 +66,6 @@ class BuildsInfo extends HTMLElement { |
62 | 66 | </li>`, |
63 | 67 | ); |
64 | 68 |
|
65 | | - // const debug = [ |
66 | | - // `endpoint: ${this.endpoint}`, |
67 | | - // `version: ${data.meta.name}/${data.meta.version}`, |
68 | | - // ]; |
69 | | - |
70 | 69 | const debug = { |
71 | 70 | element: { |
72 | 71 | endpoint: this.endpoint, |
@@ -107,4 +106,70 @@ class BuildsInfo extends HTMLElement { |
107 | 106 | } |
108 | 107 | } |
109 | 108 |
|
| 109 | +class ExampleMap extends HTMLElement { |
| 110 | + get source() { |
| 111 | + return ( |
| 112 | + this.getAttribute("source") ?? |
| 113 | + "pmtiles://https://maps.openlab.dev/tiles/uk.pmtiles" |
| 114 | + ); |
| 115 | + } |
| 116 | + |
| 117 | + get mapStyle() { |
| 118 | + return { |
| 119 | + version: 8, |
| 120 | + glyphs: |
| 121 | + "https://protomaps.github.io/basemaps-assets/fonts/{fontstack}/{range}.pbf", |
| 122 | + sources: { |
| 123 | + protomaps: { |
| 124 | + type: "vector", |
| 125 | + url: this.source, |
| 126 | + }, |
| 127 | + }, |
| 128 | + layers: layers("protomaps", namedFlavor("light"), { lang: "en" }), |
| 129 | + }; |
| 130 | + } |
| 131 | + |
| 132 | + render() { |
| 133 | + const source = this.source; |
| 134 | + if (!source) throw new TypeError("<example-map> source not set"); |
| 135 | + |
| 136 | + if (!this.innerHTML) { |
| 137 | + this.innerHTML = ` |
| 138 | + <frame-layout ratio="16:9"> |
| 139 | + <div id="example_map"></div> |
| 140 | + </frame-layout> |
| 141 | + <p class="mapAttribution"> |
| 142 | + Attribution: |
| 143 | + <a href="https://maplibre.org/">MapLibre</a>, |
| 144 | + <a href="https://docs.protomaps.com/pmtiles/">PMTiles</a> |
| 145 | + & |
| 146 | + <a href="https://www.openstreetmap.org/about">OpenStreetMap</a> |
| 147 | + </p> |
| 148 | + `; |
| 149 | + } |
| 150 | + if (!this.map) { |
| 151 | + this.map = new maplibre.Map({ |
| 152 | + container: "example_map", |
| 153 | + style: this.mapStyle, |
| 154 | + center: [-1.615008, 54.971191], |
| 155 | + zoom: 13, |
| 156 | + attributionControl: false, |
| 157 | + }); |
| 158 | + this.map.once("styledata", () => this.render()); |
| 159 | + } |
| 160 | + } |
| 161 | + |
| 162 | + connectedCallback() { |
| 163 | + this.render(); |
| 164 | + } |
| 165 | + |
| 166 | + attributeChangedCallback() { |
| 167 | + this.render(); |
| 168 | + } |
| 169 | +} |
| 170 | + |
| 171 | +const protocol = new pmtiles.Protocol(); |
| 172 | +maplibre.addProtocol("pmtiles", protocol.tile); |
| 173 | + |
110 | 174 | window.customElements.define("builds-info", BuildsInfo); |
| 175 | +window.customElements.define("example-map", ExampleMap); |
0 commit comments