Skip to content

Commit 2261a15

Browse files
stepankuzmingithub-actions[bot]
authored andcommitted
Add PMTiles render tests
GitOrigin-RevId: 4aae95db98313e817615880db3c9888429372909
1 parent 28d25fc commit 2261a15

File tree

11 files changed

+190
-5
lines changed

11 files changed

+190
-5
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ jobs:
5858
- run: npm run build -w vite-build-test
5959
- run: npm run build -w webpack-build-test
6060
- run: npm run size
61+
- run: npm run build-pmtiles
6162
- run: npm run prepare-release-pages
6263
if: ${{ always() }}
6364

debug/pmtiles.html

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<title>Mapbox GL JS debug page</title>
6+
<meta charset="utf-8">
7+
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
8+
<link rel="stylesheet" href="../dist/mapbox-gl.css" />
9+
<style>
10+
body {
11+
margin: 0;
12+
padding: 0;
13+
}
14+
15+
html,
16+
body,
17+
#map {
18+
height: 100%;
19+
}
20+
</style>
21+
</head>
22+
23+
<body>
24+
<div id="map"></div>
25+
26+
<script src="../dist/mapbox-gl-dev.js"></script>
27+
<script type="module">
28+
import {getAccessToken} from './access_token_generated.js';
29+
const accessToken = getAccessToken();
30+
mapboxgl.accessToken = accessToken;
31+
32+
mapboxgl.addTileProvider('pmtiles', new URL('../packages/pmtiles-provider/dist/mapbox-gl-pmtiles-provider.js', import.meta.url).href);
33+
34+
const style = await fetch(`https://api.mapbox.com/styles/v1/mapbox/light-v11?access_token=${accessToken}`).then(response => response.json());
35+
36+
style.sources = {
37+
composite: {
38+
type: 'vector',
39+
url: new URL('../test/integration/tiles/streets-v8-z0-z3.pmtiles', location.href).href
40+
}
41+
};
42+
43+
const map = window.map = new mapboxgl.Map({
44+
container: 'map',
45+
zoom: 1,
46+
center: [0, 20],
47+
hash: true,
48+
style
49+
});
50+
</script>
51+
</body>
52+
53+
</html>

packages/pmtiles-provider/test/pmtiles_provider.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,29 @@ describe('pmtiles_provider', () => {
3636
spy.mockRestore();
3737
});
3838

39+
test('loadTile returns data with cache headers', async () => {
40+
const {default: PMTilesProvider} = await import('../src/pmtiles_provider');
41+
const {PMTiles} = await import('pmtiles');
42+
const data = new ArrayBuffer(16);
43+
const spy = vi.spyOn(PMTiles.prototype, 'getZxy').mockResolvedValue({
44+
data, cacheControl: 'max-age=300', expires: 'Thu, 01 Jan 2099 00:00:00 GMT',
45+
});
46+
const provider = new PMTilesProvider({type: 'vector', url: 'http://example.com/test.pmtiles'});
47+
const result = await provider.loadTile({z: 1, x: 0, y: 0}, {signal: new AbortController().signal});
48+
expect(result).toEqual({data, cacheControl: 'max-age=300', expires: 'Thu, 01 Jan 2099 00:00:00 GMT'});
49+
spy.mockRestore();
50+
});
51+
52+
test('loadTile propagates getZxy errors', async () => {
53+
const {default: PMTilesProvider} = await import('../src/pmtiles_provider');
54+
const {PMTiles} = await import('pmtiles');
55+
const spy = vi.spyOn(PMTiles.prototype, 'getZxy').mockRejectedValue(new Error('network error'));
56+
const provider = new PMTilesProvider({type: 'vector', url: 'http://example.com/test.pmtiles'});
57+
await expect(provider.loadTile({z: 0, x: 0, y: 0}, {signal: new AbortController().signal}))
58+
.rejects.toThrow('network error');
59+
spy.mockRestore();
60+
});
61+
3962
test('getZxy returns null → loadTile returns null', async () => {
4063
const {default: PMTilesProvider} = await import('../src/pmtiles_provider');
4164
const {PMTiles} = await import('pmtiles');
68.2 KB
Loading
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"version": 8,
3+
"metadata": {
4+
"test": {
5+
"width": 512,
6+
"height": 512,
7+
"allowed": 0.005,
8+
"debug": true
9+
}
10+
},
11+
"center": [10, 48],
12+
"zoom": 6,
13+
"pitch": 0,
14+
"bearing": 0,
15+
"sources": {
16+
"pmtiles": {
17+
"type": "vector",
18+
"url": "local://tiles/streets-v8-z0-z3.pmtiles"
19+
}
20+
},
21+
"layers": [
22+
{
23+
"id": "background",
24+
"type": "background",
25+
"paint": {
26+
"background-color": "#fff"
27+
}
28+
},
29+
{
30+
"id": "water",
31+
"type": "fill",
32+
"source": "pmtiles",
33+
"source-layer": "water",
34+
"paint": {
35+
"fill-color": "#4488cc"
36+
}
37+
},
38+
{
39+
"id": "admin",
40+
"type": "line",
41+
"source": "pmtiles",
42+
"source-layer": "admin",
43+
"paint": {
44+
"line-color": "#9e9e9e",
45+
"line-width": 1
46+
}
47+
},
48+
{
49+
"id": "road",
50+
"type": "line",
51+
"source": "pmtiles",
52+
"source-layer": "road",
53+
"paint": {
54+
"line-color": "#bbb",
55+
"line-width": 1
56+
}
57+
}
58+
]
59+
}
18 KB
Loading
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"version": 8,
3+
"metadata": {
4+
"test": {
5+
"width": 512,
6+
"height": 512,
7+
"allowed": 0.005,
8+
"debug": true
9+
}
10+
},
11+
"center": [-135, 45],
12+
"zoom": 4,
13+
"pitch": 0,
14+
"bearing": 0,
15+
"sources": {
16+
"pmtiles": {
17+
"type": "vector",
18+
"url": "local://tiles/streets-v8-z0-z3.pmtiles"
19+
}
20+
},
21+
"layers": [
22+
{
23+
"id": "background",
24+
"type": "background",
25+
"paint": {
26+
"background-color": "#fff"
27+
}
28+
},
29+
{
30+
"id": "water",
31+
"type": "fill",
32+
"source": "pmtiles",
33+
"source-layer": "water",
34+
"paint": {
35+
"fill-color": "#4488cc"
36+
}
37+
}
38+
]
39+
}
-14.4 KB
Loading

test/integration/render-tests/tile-providers/pmtiles-vector/style.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"id": "background",
2323
"type": "background",
2424
"paint": {
25-
"background-color": "lightgray"
25+
"background-color": "#ededed"
2626
}
2727
},
2828
{
@@ -31,7 +31,7 @@
3131
"source": "pmtiles",
3232
"source-layer": "water",
3333
"paint": {
34-
"fill-color": "lightblue"
34+
"fill-color": "#4488cc"
3535
}
3636
},
3737
{
@@ -40,17 +40,17 @@
4040
"source": "pmtiles",
4141
"source-layer": "road",
4242
"paint": {
43-
"line-color": "#888",
43+
"line-color": "#fff",
4444
"line-width": 2
4545
}
4646
},
4747
{
48-
"id": "extrusion",
48+
"id": "building",
4949
"type": "fill-extrusion",
5050
"source": "pmtiles",
5151
"source-layer": "building",
5252
"paint": {
53-
"fill-extrusion-color": "white",
53+
"fill-extrusion-color": "#ddd",
5454
"fill-extrusion-height": ["get", "height"],
5555
"fill-extrusion-opacity": 1.0
5656
}
2.11 MB
Binary file not shown.

0 commit comments

Comments
 (0)