Skip to content

Commit ae0ef02

Browse files
committed
add example map
1 parent 6606746 commit ae0ef02

File tree

3 files changed

+92
-5
lines changed

3 files changed

+92
-5
lines changed

website/_assets/app.js

Lines changed: 70 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
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+
15
class BuildsInfo extends HTMLElement {
26
static get observedAttributes() {
37
return ["endpoint", "fake"];
@@ -62,11 +66,6 @@ class BuildsInfo extends HTMLElement {
6266
</li>`,
6367
);
6468

65-
// const debug = [
66-
// `endpoint: ${this.endpoint}`,
67-
// `version: ${data.meta.name}/${data.meta.version}`,
68-
// ];
69-
7069
const debug = {
7170
element: {
7271
endpoint: this.endpoint,
@@ -107,4 +106,70 @@ class BuildsInfo extends HTMLElement {
107106
}
108107
}
109108

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+
&amp;
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+
110174
window.customElements.define("builds-info", BuildsInfo);
175+
window.customElements.define("example-map", ExampleMap);

website/_assets/style.css

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
@import "https://cdn.jsdelivr.net/npm/maplibre-gl@5.6.1/dist/maplibre-gl.css";
2+
13
:root {
24
--font-main: "Rubik var", Rubik, Inter, system-ui, sans-serif;
5+
--anchor: #259f25;
36
}
47
html {
58
scroll-behavior: smooth;
@@ -28,3 +31,20 @@ body > header nav a {
2831
display: inline;
2932
}
3033
/* end labcoat candidates */
34+
35+
example-map {
36+
display: block;
37+
}
38+
example-map > frame-layout > div {
39+
width: 100%;
40+
height: 100%;
41+
}
42+
43+
.mapAttribution {
44+
text-align: center;
45+
}
46+
.mapAttribution a {
47+
color: currentColor;
48+
opacity: 0.8;
49+
font-style: italic;
50+
}

website/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ layout: html.njk
77
This website hosts protomap tiles (pmtiles) for use accress Open Lab projects.
88
There is a brief description of the format and a guide for using them.
99

10+
<example-map></example-map>
11+
1012
## about
1113

1214
This site contains information about using Open Lab's [PMTiles](https://github.com/protomaps/PMTiles) in your app's maps.

0 commit comments

Comments
 (0)