Skip to content

Commit f3a6643

Browse files
stepankuzmingithub-actions[bot]
authored andcommitted
Add url property to the batched-model source type (internal-8827)
GitOrigin-RevId: 1716ad9190debd3d7e343aed80575a2c7e52dd01
1 parent a60f5c6 commit f3a6643

File tree

3 files changed

+86
-0
lines changed

3 files changed

+86
-0
lines changed

src/style-spec/reference/v8.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,6 +1441,10 @@
14411441
},
14421442
"doc": "Type of model source to be added. From single models to represent 2D layers to 3D tiled models covering a wide area."
14431443
},
1444+
"url": {
1445+
"type": "string",
1446+
"doc": "A URL to a TileJSON resource. Supported protocols are `http:`, `https:`, and `mapbox://<Tileset ID>`. Required if `tiles` is not provided."
1447+
},
14441448
"maxzoom": {
14451449
"type": "number",
14461450
"default": 18,

src/style-spec/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,7 @@ export type ImageSourceSpecification = {
525525

526526
export type ModelSourceSpecification = {
527527
"type": "model" | "batched-model",
528+
"url"?: string,
528529
"maxzoom"?: number,
529530
"minzoom"?: number,
530531
"tiles"?: Array<string>,
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
2+
// @ts-nocheck
3+
import {describe, test, expect, waitFor} from '../../util/vitest';
4+
import {mockFetch} from '../../util/network';
5+
import Tiled3DModelSource from '../../../3d-style/source/tiled_3d_model_source';
6+
import {Evented} from '../../../src/util/evented';
7+
import {RequestManager} from '../../../src/util/mapbox';
8+
import sourceFixture from '../../fixtures/source.json';
9+
10+
const wrapDispatcher = (dispatcher) => {
11+
return {
12+
getActor() {
13+
return dispatcher;
14+
},
15+
ready: true
16+
};
17+
};
18+
19+
const mockDispatcher = wrapDispatcher({
20+
send() {}
21+
});
22+
23+
function createSource(options) {
24+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
25+
const source = new Tiled3DModelSource('id', options, mockDispatcher, new Evented());
26+
27+
source.onAdd({
28+
getWorldview() { },
29+
_getMapId: () => 1,
30+
_requestManager: new RequestManager(),
31+
_language: null,
32+
style: {
33+
clearSource: () => {}
34+
}
35+
});
36+
37+
source.on('error', (e) => {
38+
throw e.error;
39+
});
40+
41+
return source;
42+
}
43+
44+
describe('Tiled3DModelSource', () => {
45+
test('can be constructed from TileJSON', async () => {
46+
const source = createSource({
47+
type: 'batched-model',
48+
minzoom: 1,
49+
maxzoom: 10,
50+
attribution: "Mapbox",
51+
tiles: ["http://example.com/{z}/{x}/{y}.glb"]
52+
});
53+
54+
const e = await waitFor(source, "data");
55+
if (e.sourceDataType === 'metadata') {
56+
expect(source.tiles).toEqual(["http://example.com/{z}/{x}/{y}.glb"]);
57+
expect(source.minzoom).toEqual(1);
58+
expect(source.maxzoom).toEqual(10);
59+
expect(source.attribution).toEqual("Mapbox");
60+
}
61+
});
62+
63+
test('can be constructed from a TileJSON URL', async () => {
64+
mockFetch({
65+
'/source.json': () => new Response(JSON.stringify(sourceFixture))
66+
});
67+
68+
const source = createSource({
69+
type: 'batched-model',
70+
url: "/source.json"
71+
});
72+
73+
const e = await waitFor(source, "data");
74+
if (e.sourceDataType === 'metadata') {
75+
expect(source.tiles).toEqual(["http://example.com/{z}/{x}/{y}.png"]);
76+
expect(source.minzoom).toEqual(1);
77+
expect(source.maxzoom).toEqual(10);
78+
expect(source.attribution).toEqual("Mapbox");
79+
}
80+
});
81+
});

0 commit comments

Comments
 (0)