@basemaps/lambda-tiler 6.31.0 → 6.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/build/__tests__/config.data.d.ts +6 -1
- package/build/__tests__/config.data.d.ts.map +1 -1
- package/build/__tests__/config.data.js +33 -2
- package/build/__tests__/config.data.js.map +1 -1
- package/build/__tests__/index.test.js +3 -13
- package/build/__tests__/index.test.js.map +1 -1
- package/build/__tests__/xyz.util.d.ts +7 -9
- package/build/__tests__/xyz.util.d.ts.map +1 -1
- package/build/__tests__/xyz.util.js +14 -20
- package/build/__tests__/xyz.util.js.map +1 -1
- package/build/index.d.ts +0 -2
- package/build/index.d.ts.map +1 -1
- package/build/index.js +57 -26
- package/build/index.js.map +1 -1
- package/build/routes/__tests__/attribution.test.js +350 -400
- package/build/routes/__tests__/attribution.test.js.map +1 -1
- package/build/routes/__tests__/fonts.test.js +11 -5
- package/build/routes/__tests__/fonts.test.js.map +1 -1
- package/build/routes/__tests__/health.test.js +16 -13
- package/build/routes/__tests__/health.test.js.map +1 -1
- package/build/routes/__tests__/sprites.test.js +6 -0
- package/build/routes/__tests__/sprites.test.js.map +1 -1
- package/build/routes/__tests__/tile.json.test.d.ts +2 -0
- package/build/routes/__tests__/tile.json.test.d.ts.map +1 -0
- package/build/routes/__tests__/tile.json.test.js +124 -0
- package/build/routes/__tests__/tile.json.test.js.map +1 -0
- package/build/routes/__tests__/tile.style.json.test.d.ts +2 -0
- package/build/routes/__tests__/tile.style.json.test.d.ts.map +1 -0
- package/build/routes/__tests__/tile.style.json.test.js +95 -0
- package/build/routes/__tests__/tile.style.json.test.js.map +1 -0
- package/build/routes/__tests__/wmts.test.js +5 -44
- package/build/routes/__tests__/wmts.test.js.map +1 -1
- package/build/{__tests__ → routes/__tests__}/xyz.test.d.ts +0 -0
- package/build/routes/__tests__/xyz.test.d.ts.map +1 -0
- package/build/routes/__tests__/xyz.test.js +99 -0
- package/build/routes/__tests__/xyz.test.js.map +1 -0
- package/build/routes/attribution.d.ts +7 -5
- package/build/routes/attribution.d.ts.map +1 -1
- package/build/routes/attribution.js +43 -81
- package/build/routes/attribution.js.map +1 -1
- package/build/routes/fonts.d.ts +1 -1
- package/build/routes/fonts.d.ts.map +1 -1
- package/build/routes/fonts.js +30 -15
- package/build/routes/fonts.js.map +1 -1
- package/build/routes/health.d.ts +3 -3
- package/build/routes/health.d.ts.map +1 -1
- package/build/routes/health.js +15 -13
- package/build/routes/health.js.map +1 -1
- package/build/routes/imagery.d.ts.map +1 -1
- package/build/routes/imagery.js +11 -10
- package/build/routes/imagery.js.map +1 -1
- package/build/routes/ping.d.ts +3 -0
- package/build/routes/ping.d.ts.map +1 -0
- package/build/routes/ping.js +7 -0
- package/build/routes/ping.js.map +1 -0
- package/build/routes/sprites.d.ts.map +1 -1
- package/build/routes/sprites.js +16 -10
- package/build/routes/sprites.js.map +1 -1
- package/build/routes/tile.json.d.ts +7 -1
- package/build/routes/tile.json.d.ts.map +1 -1
- package/build/routes/tile.json.js +18 -21
- package/build/routes/tile.json.js.map +1 -1
- package/build/routes/tile.style.json.d.ts +6 -1
- package/build/routes/tile.style.json.d.ts.map +1 -1
- package/build/routes/tile.style.json.js +10 -13
- package/build/routes/tile.style.json.js.map +1 -1
- package/build/routes/tile.wmts.d.ts +9 -3
- package/build/routes/tile.wmts.d.ts.map +1 -1
- package/build/routes/tile.wmts.js +26 -35
- package/build/routes/tile.wmts.js.map +1 -1
- package/build/routes/tile.xyz.d.ts +14 -4
- package/build/routes/tile.xyz.d.ts.map +1 -1
- package/build/routes/tile.xyz.js +21 -17
- package/build/routes/tile.xyz.js.map +1 -1
- package/build/routes/tile.xyz.raster.d.ts +11 -0
- package/build/routes/tile.xyz.raster.d.ts.map +1 -0
- package/build/routes/tile.xyz.raster.js +90 -0
- package/build/routes/tile.xyz.raster.js.map +1 -0
- package/build/routes/tile.xyz.vector.d.ts +8 -0
- package/build/routes/tile.xyz.vector.d.ts.map +1 -0
- package/build/routes/tile.xyz.vector.js +46 -0
- package/build/routes/tile.xyz.vector.js.map +1 -0
- package/build/routes/version.d.ts +3 -0
- package/build/routes/version.d.ts.map +1 -0
- package/build/routes/version.js +9 -0
- package/build/routes/version.js.map +1 -0
- package/build/util/__test__/validate.test.d.ts +2 -0
- package/build/util/__test__/validate.test.d.ts.map +1 -0
- package/build/util/__test__/validate.test.js +66 -0
- package/build/util/__test__/validate.test.js.map +1 -0
- package/build/{cotar.cache.d.ts → util/cotar.serve.d.ts} +3 -8
- package/build/util/cotar.serve.d.ts.map +1 -0
- package/build/util/cotar.serve.js +41 -0
- package/build/util/cotar.serve.js.map +1 -0
- package/build/util/etag.d.ts +6 -0
- package/build/util/etag.d.ts.map +1 -0
- package/build/util/etag.js +20 -0
- package/build/util/etag.js.map +1 -0
- package/build/util/response.d.ts +4 -0
- package/build/util/response.d.ts.map +1 -0
- package/build/util/response.js +4 -0
- package/build/util/response.js.map +1 -0
- package/build/util/source.cache.d.ts +28 -0
- package/build/util/source.cache.d.ts.map +1 -0
- package/build/util/source.cache.js +53 -0
- package/build/util/source.cache.js.map +1 -0
- package/build/{source.tracer.d.ts → util/source.tracer.d.ts} +1 -0
- package/build/util/source.tracer.d.ts.map +1 -0
- package/build/{source.tracer.js → util/source.tracer.js} +3 -0
- package/build/util/source.tracer.js.map +1 -0
- package/build/util/swapping.lru.d.ts +21 -0
- package/build/util/swapping.lru.d.ts.map +1 -0
- package/build/util/swapping.lru.js +56 -0
- package/build/util/swapping.lru.js.map +1 -0
- package/build/util/validate.d.ts +46 -0
- package/build/util/validate.d.ts.map +1 -0
- package/build/util/validate.js +107 -0
- package/build/util/validate.js.map +1 -0
- package/build/wmts.capability.d.ts +1 -1
- package/build/wmts.capability.d.ts.map +1 -1
- package/dist/index.js +62 -60
- package/dist/node_modules/.package-lock.json +1 -1
- package/dist/package-lock.json +2 -2
- package/dist/package.json +1 -1
- package/package.json +6 -6
- package/src/__tests__/config.data.ts +41 -3
- package/src/__tests__/index.test.ts +3 -19
- package/src/__tests__/xyz.util.ts +18 -21
- package/src/index.ts +66 -29
- package/src/routes/__tests__/attribution.test.ts +356 -403
- package/src/routes/__tests__/fonts.test.ts +11 -5
- package/src/routes/__tests__/health.test.ts +17 -13
- package/src/routes/__tests__/sprites.test.ts +6 -1
- package/src/routes/__tests__/tile.json.test.ts +145 -0
- package/src/routes/__tests__/tile.style.json.test.ts +105 -0
- package/src/routes/__tests__/wmts.test.ts +5 -55
- package/src/routes/__tests__/xyz.test.ts +119 -0
- package/src/routes/attribution.ts +53 -99
- package/src/routes/fonts.ts +29 -15
- package/src/routes/health.ts +17 -16
- package/src/routes/imagery.ts +10 -9
- package/src/routes/ping.ts +8 -0
- package/src/routes/sprites.ts +16 -10
- package/src/routes/tile.json.ts +24 -18
- package/src/routes/tile.style.json.ts +15 -12
- package/src/routes/tile.wmts.ts +30 -31
- package/src/routes/tile.xyz.raster.ts +106 -0
- package/src/routes/tile.xyz.ts +31 -16
- package/src/routes/tile.xyz.vector.ts +47 -0
- package/src/routes/version.ts +8 -0
- package/src/util/__test__/validate.test.ts +74 -0
- package/src/util/cotar.serve.ts +46 -0
- package/src/util/etag.ts +20 -0
- package/src/util/response.ts +4 -0
- package/src/util/source.cache.ts +71 -0
- package/src/{source.tracer.ts → util/source.tracer.ts} +4 -0
- package/src/util/swapping.lru.ts +63 -0
- package/src/util/validate.ts +126 -0
- package/src/wmts.capability.ts +1 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/build/__tests__/route.test.d.ts +0 -2
- package/build/__tests__/route.test.d.ts.map +0 -1
- package/build/__tests__/route.test.js +0 -21
- package/build/__tests__/route.test.js.map +0 -1
- package/build/__tests__/tiff.cache.test.d.ts +0 -2
- package/build/__tests__/tiff.cache.test.d.ts.map +0 -1
- package/build/__tests__/tiff.cache.test.js +0 -59
- package/build/__tests__/tiff.cache.test.js.map +0 -1
- package/build/__tests__/tile.cache.key.test.d.ts +0 -2
- package/build/__tests__/tile.cache.key.test.d.ts.map +0 -1
- package/build/__tests__/tile.cache.key.test.js +0 -49
- package/build/__tests__/tile.cache.key.test.js.map +0 -1
- package/build/__tests__/tile.set.cache.test.d.ts +0 -2
- package/build/__tests__/tile.set.cache.test.d.ts.map +0 -1
- package/build/__tests__/tile.set.cache.test.js +0 -72
- package/build/__tests__/tile.set.cache.test.js.map +0 -1
- package/build/__tests__/tile.set.test.d.ts +0 -2
- package/build/__tests__/tile.set.test.d.ts.map +0 -1
- package/build/__tests__/tile.set.test.js +0 -12
- package/build/__tests__/tile.set.test.js.map +0 -1
- package/build/__tests__/xyz.test.d.ts.map +0 -1
- package/build/__tests__/xyz.test.js +0 -275
- package/build/__tests__/xyz.test.js.map +0 -1
- package/build/api.key.d.ts +0 -2
- package/build/api.key.d.ts.map +0 -1
- package/build/api.key.js +0 -24
- package/build/api.key.js.map +0 -1
- package/build/cli/dump.d.ts +0 -2
- package/build/cli/dump.d.ts.map +0 -1
- package/build/cli/dump.js +0 -48
- package/build/cli/dump.js.map +0 -1
- package/build/cli/tile.set.local.d.ts +0 -12
- package/build/cli/tile.set.local.d.ts.map +0 -1
- package/build/cli/tile.set.local.js +0 -40
- package/build/cli/tile.set.local.js.map +0 -1
- package/build/cotar.cache.d.ts.map +0 -1
- package/build/cotar.cache.js +0 -50
- package/build/cotar.cache.js.map +0 -1
- package/build/router.d.ts +0 -15
- package/build/router.d.ts.map +0 -1
- package/build/router.js +0 -50
- package/build/router.js.map +0 -1
- package/build/routes/api.d.ts +0 -4
- package/build/routes/api.d.ts.map +0 -1
- package/build/routes/api.js +0 -14
- package/build/routes/api.js.map +0 -1
- package/build/routes/esri/rest.d.ts +0 -10
- package/build/routes/esri/rest.d.ts.map +0 -1
- package/build/routes/esri/rest.js +0 -88
- package/build/routes/esri/rest.js.map +0 -1
- package/build/routes/response.d.ts +0 -4
- package/build/routes/response.d.ts.map +0 -1
- package/build/routes/response.js +0 -4
- package/build/routes/response.js.map +0 -1
- package/build/routes/tile.d.ts +0 -3
- package/build/routes/tile.d.ts.map +0 -1
- package/build/routes/tile.etag.d.ts +0 -11
- package/build/routes/tile.etag.d.ts.map +0 -1
- package/build/routes/tile.etag.js +0 -30
- package/build/routes/tile.etag.js.map +0 -1
- package/build/routes/tile.js +0 -28
- package/build/routes/tile.js.map +0 -1
- package/build/source.tracer.d.ts.map +0 -1
- package/build/source.tracer.js.map +0 -1
- package/build/tiff.cache.d.ts +0 -17
- package/build/tiff.cache.d.ts.map +0 -1
- package/build/tiff.cache.js +0 -46
- package/build/tiff.cache.js.map +0 -1
- package/build/tile.set.cache.d.ts +0 -20
- package/build/tile.set.cache.d.ts.map +0 -1
- package/build/tile.set.cache.js +0 -72
- package/build/tile.set.cache.js.map +0 -1
- package/build/tile.set.d.ts +0 -4
- package/build/tile.set.d.ts.map +0 -1
- package/build/tile.set.js +0 -2
- package/build/tile.set.js.map +0 -1
- package/build/tile.set.raster.d.ts +0 -49
- package/build/tile.set.raster.d.ts.map +0 -1
- package/build/tile.set.raster.js +0 -189
- package/build/tile.set.raster.js.map +0 -1
- package/build/tile.set.vector.d.ts +0 -18
- package/build/tile.set.vector.d.ts.map +0 -1
- package/build/tile.set.vector.js +0 -54
- package/build/tile.set.vector.js.map +0 -1
- package/build/validate.d.ts +0 -16
- package/build/validate.d.ts.map +0 -1
- package/build/validate.js +0 -32
- package/build/validate.js.map +0 -1
- package/src/__tests__/route.test.ts +0 -24
- package/src/__tests__/tiff.cache.test.ts +0 -73
- package/src/__tests__/tile.cache.key.test.ts +0 -56
- package/src/__tests__/tile.set.cache.test.ts +0 -80
- package/src/__tests__/tile.set.test.ts +0 -12
- package/src/__tests__/xyz.test.ts +0 -318
- package/src/api.key.ts +0 -23
- package/src/cli/dump.ts +0 -61
- package/src/cli/tile.set.local.ts +0 -51
- package/src/cotar.cache.ts +0 -54
- package/src/router.ts +0 -58
- package/src/routes/api.ts +0 -15
- package/src/routes/esri/rest.ts +0 -90
- package/src/routes/response.ts +0 -4
- package/src/routes/tile.etag.ts +0 -36
- package/src/routes/tile.ts +0 -23
- package/src/tiff.cache.ts +0 -51
- package/src/tile.set.cache.ts +0 -84
- package/src/tile.set.raster.ts +0 -230
- package/src/tile.set.ts +0 -4
- package/src/tile.set.vector.ts +0 -61
- package/src/validate.ts +0 -32
|
@@ -1,318 +0,0 @@
|
|
|
1
|
-
import { ConfigProvider, StyleJson } from '@basemaps/config';
|
|
2
|
-
import { GoogleTms, Nztm2000QuadTms, TileMatrixSets } from '@basemaps/geo';
|
|
3
|
-
import { Config, Env, LogConfig } from '@basemaps/shared';
|
|
4
|
-
import { round } from '@basemaps/test/build/rounding.js';
|
|
5
|
-
import o from 'ospec';
|
|
6
|
-
import sinon from 'sinon';
|
|
7
|
-
import { handleRequest } from '../index.js';
|
|
8
|
-
import { TileEtag } from '../routes/tile.etag.js';
|
|
9
|
-
import { TileSets } from '../tile.set.cache.js';
|
|
10
|
-
import { TileComposer } from '../tile.set.raster.js';
|
|
11
|
-
import { Provider } from './config.data.js';
|
|
12
|
-
import { FakeTileSet, FakeTileSetVector, mockRequest } from './xyz.util.js';
|
|
13
|
-
|
|
14
|
-
const sandbox = sinon.createSandbox();
|
|
15
|
-
|
|
16
|
-
const TileSetNames = ['aerial', 'aerial@head', 'aerial@beta', '01E7PJFR9AMQFJ05X9G7FQ3XMW'];
|
|
17
|
-
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
18
|
-
o.spec('LambdaXyz', () => {
|
|
19
|
-
const host = 'https://tiles.test';
|
|
20
|
-
const origPublicUrlBase = process.env[Env.PublicUrlBase];
|
|
21
|
-
|
|
22
|
-
/** Generate mock ALBEvent */
|
|
23
|
-
|
|
24
|
-
let rasterMock = o.spy();
|
|
25
|
-
const generateMock = o.spy(() => 'foo');
|
|
26
|
-
const rasterMockBuffer = Buffer.from([1]);
|
|
27
|
-
const origTileEtag = TileEtag.generate;
|
|
28
|
-
const origCompose = TileComposer.compose;
|
|
29
|
-
|
|
30
|
-
const apiKey = 'd01f7w7rnhdzg0p7fyrc9v9ard1';
|
|
31
|
-
const apiKeyHeader = { 'x-linz-api-key': 'd01f7w7rnhdzg0p7fyrc9v9ard1' };
|
|
32
|
-
|
|
33
|
-
o.beforeEach(() => {
|
|
34
|
-
process.env[Env.PublicUrlBase] = host;
|
|
35
|
-
|
|
36
|
-
LogConfig.disable();
|
|
37
|
-
// tileMock = o.spy(() => tileMockData) as any;
|
|
38
|
-
rasterMock = o.spy(() => {
|
|
39
|
-
return {
|
|
40
|
-
buffer: rasterMockBuffer,
|
|
41
|
-
};
|
|
42
|
-
}) as any;
|
|
43
|
-
|
|
44
|
-
TileEtag.generate = generateMock;
|
|
45
|
-
TileComposer.compose = rasterMock as any;
|
|
46
|
-
|
|
47
|
-
const allMatrix = [...TileMatrixSets.All.values()];
|
|
48
|
-
for (const tileSetName of TileSetNames) {
|
|
49
|
-
for (const tileMatrix of allMatrix) {
|
|
50
|
-
const tileSet = new FakeTileSet(tileSetName, tileMatrix);
|
|
51
|
-
TileSets.add(tileSet);
|
|
52
|
-
tileSet.getTiffsForTile = (): [] => [];
|
|
53
|
-
tileSet.initTiffs = async () => [];
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
TileSets.add(new FakeTileSetVector('topographic', GoogleTms));
|
|
58
|
-
|
|
59
|
-
(Config.Provider as any).get = async (): Promise<ConfigProvider> => Provider;
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
o.afterEach(() => {
|
|
63
|
-
TileSets.cache.clear();
|
|
64
|
-
TileComposer.compose = origCompose;
|
|
65
|
-
TileEtag.generate = origTileEtag;
|
|
66
|
-
process.env[Env.PublicUrlBase] = origPublicUrlBase;
|
|
67
|
-
sandbox.restore();
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
o('should export handler', async () => {
|
|
71
|
-
const base = await import('../index.js');
|
|
72
|
-
o(typeof base.handler).equals('function');
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
TileSetNames.forEach((tileSetName) => {
|
|
76
|
-
o(`should generate a tile 0,0,0 for ${tileSetName}.png`, async () => {
|
|
77
|
-
o.timeout(200);
|
|
78
|
-
const request = mockRequest(`/v1/tiles/${tileSetName}/global-mercator/0/0/0.png`, 'get', apiKeyHeader);
|
|
79
|
-
const res = await handleRequest(request);
|
|
80
|
-
o(res.status).equals(200);
|
|
81
|
-
o(res.header('content-type')).equals('image/png');
|
|
82
|
-
o(res.header('eTaG')).equals('foo');
|
|
83
|
-
o(res.body).equals(rasterMockBuffer.toString('base64'));
|
|
84
|
-
|
|
85
|
-
// Validate the session information has been set correctly
|
|
86
|
-
o(request.logContext['tileSet']).equals(tileSetName);
|
|
87
|
-
o(request.logContext['xyz']).deepEquals({ x: 0, y: 0, z: 0 });
|
|
88
|
-
o(round(request.logContext['location'])).deepEquals({ lat: 0, lon: 0 });
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
o('should generate a tile 0,0,0 for webp', async () => {
|
|
93
|
-
const request = mockRequest('/v1/tiles/aerial/3857/0/0/0.webp', 'get', apiKeyHeader);
|
|
94
|
-
const res = await handleRequest(request);
|
|
95
|
-
o(res.status).equals(200);
|
|
96
|
-
o(res.header('content-type')).equals('image/webp');
|
|
97
|
-
o(res.header('eTaG')).equals('foo');
|
|
98
|
-
o(res.body).equals(rasterMockBuffer.toString('base64'));
|
|
99
|
-
|
|
100
|
-
// Validate the session information has been set correctly
|
|
101
|
-
o(request.logContext['xyz']).deepEquals({ x: 0, y: 0, z: 0 });
|
|
102
|
-
o(round(request.logContext['location'])).deepEquals({ lat: 0, lon: 0 });
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
['png', 'webp', 'jpeg'].forEach((fmt) => {
|
|
106
|
-
o(`should 200 with empty ${fmt} if a tile is out of bounds`, async () => {
|
|
107
|
-
// tiler.tile = async () => [];
|
|
108
|
-
const res = await handleRequest(
|
|
109
|
-
mockRequest(`/v1/tiles/aerial/global-mercator/0/0/0.${fmt}`, 'get', apiKeyHeader),
|
|
110
|
-
);
|
|
111
|
-
o(res.status).equals(200);
|
|
112
|
-
o(res.header('content-type')).equals(`image/${fmt}`);
|
|
113
|
-
o(rasterMock.calls.length).equals(1);
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
o('should 304 if a tile is not modified', async () => {
|
|
118
|
-
const key = 'foo';
|
|
119
|
-
const request = mockRequest('/v1/tiles/aerial/global-mercator/0/0/0.png', 'get', {
|
|
120
|
-
'if-none-match': key,
|
|
121
|
-
...apiKeyHeader,
|
|
122
|
-
});
|
|
123
|
-
const res = await handleRequest(request);
|
|
124
|
-
o(res.status).equals(304);
|
|
125
|
-
o(res.header('eTaG')).equals(undefined);
|
|
126
|
-
|
|
127
|
-
o(rasterMock.calls.length).equals(0);
|
|
128
|
-
o(request.logContext['cache']).deepEquals({ key, match: key, hit: true });
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
o('should 404 if a tile is outside of the range', async () => {
|
|
132
|
-
try {
|
|
133
|
-
const res = await handleRequest(mockRequest('/v1/tiles/aerial/global-mercator/25/0/0.png', 'get', apiKeyHeader));
|
|
134
|
-
o(res.status).equals(404);
|
|
135
|
-
} catch (e: any) {
|
|
136
|
-
o(e.status).equals(404);
|
|
137
|
-
}
|
|
138
|
-
try {
|
|
139
|
-
const res = await handleRequest(mockRequest('/v1/tiles/aerial/2193/17/0/0.png', 'get', apiKeyHeader));
|
|
140
|
-
o(res.status).equals(404);
|
|
141
|
-
} catch (e: any) {
|
|
142
|
-
o(e.status).equals(404);
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
o.spec('tileJson', () => {
|
|
147
|
-
o('should 404 if invalid url is given', async () => {
|
|
148
|
-
const request = mockRequest('/v1/tiles/tile.json', 'get', apiKeyHeader);
|
|
149
|
-
|
|
150
|
-
const res = await handleRequest(request);
|
|
151
|
-
o(res.status).equals(404);
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
o('should serve tile json for tile_set', async () => {
|
|
155
|
-
const request = mockRequest('/v1/tiles/aerial/NZTM2000Quad/tile.json', 'get', apiKeyHeader);
|
|
156
|
-
|
|
157
|
-
const res = await handleRequest(request);
|
|
158
|
-
o(res.status).equals(200);
|
|
159
|
-
o(res.header('cache-control')).equals('no-store');
|
|
160
|
-
|
|
161
|
-
const body = Buffer.from(res.body ?? '', 'base64').toString();
|
|
162
|
-
o(JSON.parse(body)).deepEquals({
|
|
163
|
-
tiles: [`https://tiles.test/v1/tiles/aerial/NZTM2000Quad/{z}/{x}/{y}.webp?api=${apiKey}`],
|
|
164
|
-
tilejson: '3.0.0',
|
|
165
|
-
});
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
o('should serve vector tiles', async () => {
|
|
169
|
-
const request = mockRequest('/v1/tiles/topographic/WebMercatorQuad/tile.json', 'get', apiKeyHeader);
|
|
170
|
-
|
|
171
|
-
const res = await handleRequest(request);
|
|
172
|
-
o(res.status).equals(200);
|
|
173
|
-
|
|
174
|
-
const body = Buffer.from(res.body ?? '', 'base64').toString();
|
|
175
|
-
o(JSON.parse(body)).deepEquals({
|
|
176
|
-
tiles: [`https://tiles.test/v1/tiles/topographic/WebMercatorQuad/{z}/{x}/{y}.pbf?api=${apiKey}`],
|
|
177
|
-
tilejson: '3.0.0',
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
o('should serve vector tiles with min/max zoom', async () => {
|
|
182
|
-
const fakeTileSet = new FakeTileSetVector('fake-vector', GoogleTms);
|
|
183
|
-
fakeTileSet.tileSet.maxZoom = 15;
|
|
184
|
-
fakeTileSet.tileSet.minZoom = 3;
|
|
185
|
-
TileSets.add(fakeTileSet);
|
|
186
|
-
const request = mockRequest('/v1/tiles/fake-vector/WebMercatorQuad/tile.json', 'get', apiKeyHeader);
|
|
187
|
-
|
|
188
|
-
const res = await handleRequest(request);
|
|
189
|
-
o(res.status).equals(200);
|
|
190
|
-
|
|
191
|
-
const body = Buffer.from(res.body ?? '', 'base64').toString();
|
|
192
|
-
o(JSON.parse(body)).deepEquals({
|
|
193
|
-
tiles: [`https://tiles.test/v1/tiles/fake-vector/WebMercatorQuad/{z}/{x}/{y}.pbf?api=${apiKey}`],
|
|
194
|
-
maxzoom: 15,
|
|
195
|
-
minzoom: 3,
|
|
196
|
-
tilejson: '3.0.0',
|
|
197
|
-
});
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
o('should serve convert zoom to tile matrix', async () => {
|
|
201
|
-
const fakeTileSet = new FakeTileSetVector('fake-vector', Nztm2000QuadTms);
|
|
202
|
-
fakeTileSet.tileSet.maxZoom = 15;
|
|
203
|
-
fakeTileSet.tileSet.minZoom = 1;
|
|
204
|
-
TileSets.add(fakeTileSet);
|
|
205
|
-
|
|
206
|
-
const request = mockRequest('/v1/tiles/fake-vector/NZTM2000Quad/tile.json', 'get', apiKeyHeader);
|
|
207
|
-
|
|
208
|
-
const res = await handleRequest(request);
|
|
209
|
-
o(res.status).equals(200);
|
|
210
|
-
|
|
211
|
-
const body = Buffer.from(res.body ?? '', 'base64').toString();
|
|
212
|
-
o(JSON.parse(body)).deepEquals({
|
|
213
|
-
tiles: [`https://tiles.test/v1/tiles/fake-vector/NZTM2000Quad/{z}/{x}/{y}.pbf?api=${apiKey}`],
|
|
214
|
-
maxzoom: 13,
|
|
215
|
-
minzoom: 0,
|
|
216
|
-
tilejson: '3.0.0',
|
|
217
|
-
});
|
|
218
|
-
});
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
o.spec('styleJson', () => {
|
|
222
|
-
o('should not found style json', async () => {
|
|
223
|
-
const request = mockRequest('/v1/tiles/topographic/Google/style/topographic.json', 'get', apiKeyHeader);
|
|
224
|
-
|
|
225
|
-
sandbox.stub(Config.Style, 'get').resolves(null);
|
|
226
|
-
|
|
227
|
-
const res = await handleRequest(request);
|
|
228
|
-
o(res.status).equals(404);
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
o('should serve style json', async () => {
|
|
232
|
-
const request = mockRequest('/v1/tiles/topographic/Google/style/topographic.json', 'get', apiKeyHeader);
|
|
233
|
-
|
|
234
|
-
const fakeStyle: StyleJson = {
|
|
235
|
-
version: 8,
|
|
236
|
-
id: 'test',
|
|
237
|
-
name: 'topographic',
|
|
238
|
-
sources: {
|
|
239
|
-
basemaps_vector: {
|
|
240
|
-
type: 'vector',
|
|
241
|
-
url: `/vector`,
|
|
242
|
-
},
|
|
243
|
-
basemaps_raster: {
|
|
244
|
-
type: 'raster',
|
|
245
|
-
tiles: [`/raster`],
|
|
246
|
-
},
|
|
247
|
-
basemaps_raster_encode: {
|
|
248
|
-
type: 'raster',
|
|
249
|
-
tiles: [`/raster/{z}/{x}/{y}.webp`], // Shouldn't encode the {}
|
|
250
|
-
},
|
|
251
|
-
test_vector: {
|
|
252
|
-
type: 'vector',
|
|
253
|
-
url: 'vector.url.co.nz',
|
|
254
|
-
},
|
|
255
|
-
test_raster: {
|
|
256
|
-
type: 'raster',
|
|
257
|
-
tiles: ['raster.url.co.nz'],
|
|
258
|
-
},
|
|
259
|
-
},
|
|
260
|
-
layers: [
|
|
261
|
-
{
|
|
262
|
-
layout: {
|
|
263
|
-
visibility: 'visible',
|
|
264
|
-
},
|
|
265
|
-
paint: {
|
|
266
|
-
'background-color': 'rgba(206, 229, 242, 1)',
|
|
267
|
-
},
|
|
268
|
-
id: 'Background',
|
|
269
|
-
type: 'background',
|
|
270
|
-
minzoom: 0,
|
|
271
|
-
},
|
|
272
|
-
],
|
|
273
|
-
glyphs: '/glyphs',
|
|
274
|
-
sprite: '/sprite',
|
|
275
|
-
metadata: { id: 'test' },
|
|
276
|
-
};
|
|
277
|
-
|
|
278
|
-
const fakeRecord = {
|
|
279
|
-
id: 'st_topographic_production',
|
|
280
|
-
name: 'topographic',
|
|
281
|
-
style: fakeStyle,
|
|
282
|
-
};
|
|
283
|
-
|
|
284
|
-
sandbox.stub(Config.Style, 'get').resolves(fakeRecord as any);
|
|
285
|
-
|
|
286
|
-
const res = await handleRequest(request);
|
|
287
|
-
o(res.status).equals(200);
|
|
288
|
-
o(res.header('content-type')).equals('application/json');
|
|
289
|
-
o(res.header('cache-control')).equals('no-store');
|
|
290
|
-
|
|
291
|
-
const body = Buffer.from(res.body ?? '', 'base64').toString();
|
|
292
|
-
fakeStyle.sources.basemaps_vector = {
|
|
293
|
-
type: 'vector',
|
|
294
|
-
url: `${host}/vector?api=${apiKey}`,
|
|
295
|
-
};
|
|
296
|
-
fakeStyle.sources.basemaps_raster = {
|
|
297
|
-
type: 'raster',
|
|
298
|
-
tiles: [`${host}/raster?api=${apiKey}`],
|
|
299
|
-
};
|
|
300
|
-
fakeStyle.sources.basemaps_raster_encode = {
|
|
301
|
-
type: 'raster',
|
|
302
|
-
tiles: [`${host}/raster/{z}/{x}/{y}.webp?api=${apiKey}`],
|
|
303
|
-
};
|
|
304
|
-
|
|
305
|
-
fakeStyle.sprite = `${host}/sprite`;
|
|
306
|
-
fakeStyle.glyphs = `${host}/glyphs`;
|
|
307
|
-
|
|
308
|
-
o(JSON.parse(body)).deepEquals(fakeStyle);
|
|
309
|
-
});
|
|
310
|
-
});
|
|
311
|
-
|
|
312
|
-
['/favicon.ico', '/index.html', '/foo/bar'].forEach((path) => {
|
|
313
|
-
o('should error on invalid paths: ' + path, async () => {
|
|
314
|
-
const res = await handleRequest(mockRequest(path, 'get', apiKeyHeader));
|
|
315
|
-
o(res.status).equals(404);
|
|
316
|
-
});
|
|
317
|
-
});
|
|
318
|
-
});
|
package/src/api.key.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import * as ulid from 'ulid';
|
|
2
|
-
|
|
3
|
-
const OneHourMs = 60 * 60 * 1000;
|
|
4
|
-
const OneDayMs = 24 * OneHourMs;
|
|
5
|
-
const MaxApiAgeMs = 91 * OneDayMs;
|
|
6
|
-
|
|
7
|
-
export function isValidApiKey(apiKey?: string | null): boolean {
|
|
8
|
-
if (apiKey == null) return false;
|
|
9
|
-
if (!apiKey.startsWith('c') && !apiKey.startsWith('d')) return false;
|
|
10
|
-
const ulidId = apiKey.slice(1).toUpperCase();
|
|
11
|
-
try {
|
|
12
|
-
const ulidTime = ulid.decodeTime(ulidId);
|
|
13
|
-
if (apiKey.startsWith('d')) return true;
|
|
14
|
-
|
|
15
|
-
if (Date.now() - ulidTime > MaxApiAgeMs) {
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
} catch (e) {
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return true;
|
|
23
|
-
}
|
package/src/cli/dump.ts
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { Nztm2000Tms, ImageFormat } from '@basemaps/geo';
|
|
2
|
-
import { LogConfig } from '@basemaps/shared';
|
|
3
|
-
import { LambdaAlbRequest } from '@linzjs/lambda';
|
|
4
|
-
import { Context } from 'aws-lambda';
|
|
5
|
-
import { promises as fs } from 'fs';
|
|
6
|
-
import { tileXyz } from '../routes/tile.xyz.js';
|
|
7
|
-
import { TileSets } from '../tile.set.cache.js';
|
|
8
|
-
import { TileSet } from '../tile.set.js';
|
|
9
|
-
import { TileSetLocal } from './tile.set.local.js';
|
|
10
|
-
|
|
11
|
-
const xyz = { x: 0, y: 0, z: 0 };
|
|
12
|
-
const tileMatrix = Nztm2000Tms;
|
|
13
|
-
const tileSetName = 'aerial';
|
|
14
|
-
const ext = ImageFormat.Png;
|
|
15
|
-
|
|
16
|
-
/** Load a tileset form a file path otherwise default to the hard coded one from AWS */
|
|
17
|
-
async function getTileSet(filePath?: string): Promise<TileSet> {
|
|
18
|
-
if (filePath != null) {
|
|
19
|
-
const tileSet = new TileSetLocal('local', filePath);
|
|
20
|
-
await tileSet.load();
|
|
21
|
-
TileSets.add(tileSet);
|
|
22
|
-
return tileSet;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const tileSet = await TileSets.get(tileSetName, tileMatrix);
|
|
26
|
-
if (tileSet == null) throw new Error('Missing');
|
|
27
|
-
return tileSet;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Utility to render a single tile then save it as a png
|
|
32
|
-
*/
|
|
33
|
-
async function main(): Promise<void> {
|
|
34
|
-
const logger = LogConfig.get();
|
|
35
|
-
|
|
36
|
-
const filePath = process.argv[2];
|
|
37
|
-
const tileSet = await getTileSet(filePath);
|
|
38
|
-
|
|
39
|
-
logger.info({ ...xyz, projection: tileMatrix.projection.code, tileMatrix: tileMatrix.identifier }, 'RenderTile');
|
|
40
|
-
|
|
41
|
-
const ctx = new LambdaAlbRequest(
|
|
42
|
-
{
|
|
43
|
-
httpMethod: 'get',
|
|
44
|
-
path: `/v1/tiles/${tileSet.fullName}/${tileMatrix.identifier}/${xyz.z}/${xyz.x}/${xyz.y}.${ext}`,
|
|
45
|
-
} as any,
|
|
46
|
-
{} as Context,
|
|
47
|
-
logger,
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
const tileData = await tileXyz(ctx);
|
|
51
|
-
|
|
52
|
-
const headers: Record<string, any> = {};
|
|
53
|
-
for (const [key, value] of tileData.headers) headers[key] = value;
|
|
54
|
-
|
|
55
|
-
logger.info({ ...tileData, _body: tileData.body?.length, headers }, 'Done');
|
|
56
|
-
if (tileData._body != null) {
|
|
57
|
-
await fs.writeFile(`output_${xyz.x}_${xyz.y}_z${xyz.z}.${ext}`, tileData._body);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
main().catch(console.error);
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { Epsg, GoogleTms, TileMatrixSets } from '@basemaps/geo';
|
|
2
|
-
import { fsa, LogConfig } from '@basemaps/shared';
|
|
3
|
-
import { CogTiff, TiffTagGeo } from '@cogeotiff/core';
|
|
4
|
-
import { TileSetRaster } from '../tile.set.raster.js';
|
|
5
|
-
|
|
6
|
-
function isTiff(fileName: string): boolean {
|
|
7
|
-
return fileName.toLowerCase().endsWith('.tif') || fileName.toLowerCase().endsWith('.tiff');
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export class TileSetLocal extends TileSetRaster {
|
|
11
|
-
tiffs: CogTiff[];
|
|
12
|
-
filePath: string;
|
|
13
|
-
tileSet = {} as any;
|
|
14
|
-
|
|
15
|
-
constructor(name: string, path: string) {
|
|
16
|
-
super(name, GoogleTms);
|
|
17
|
-
this.filePath = path;
|
|
18
|
-
this.tileSet.name = name;
|
|
19
|
-
this.tileSet.title = name;
|
|
20
|
-
this.tileSet.projection = GoogleTms.projection.code;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
setTitle(name: string): void {
|
|
24
|
-
this.tileSet.title = name;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
async load(): Promise<boolean> {
|
|
28
|
-
if (this.tiffs != null) return true;
|
|
29
|
-
|
|
30
|
-
const fileList = isTiff(this.filePath) ? [this.filePath] : await fsa.toArray(fsa.list(this.filePath));
|
|
31
|
-
const files = fileList.filter(isTiff);
|
|
32
|
-
if (files.length === 0) throw new Error(`No tiff files found in ${this.filePath}`);
|
|
33
|
-
|
|
34
|
-
this.tiffs = files.map((filePath) => new CogTiff(fsa.source(filePath)));
|
|
35
|
-
|
|
36
|
-
// Read in the projection information
|
|
37
|
-
const [firstTiff] = this.tiffs;
|
|
38
|
-
await firstTiff.init(true);
|
|
39
|
-
const projection = Epsg.get(firstTiff.getImage(0).valueGeo(TiffTagGeo.ProjectedCSTypeGeoKey) as number);
|
|
40
|
-
this.tileMatrix = TileMatrixSets.get(projection);
|
|
41
|
-
LogConfig.get().info(
|
|
42
|
-
{ path: this.filePath, count: this.tiffs.length, tileMatrix: this.tileMatrix.identifier },
|
|
43
|
-
'LoadedTiffs',
|
|
44
|
-
);
|
|
45
|
-
return true;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
getTiffsForTile(): CogTiff[] {
|
|
49
|
-
return this.tiffs;
|
|
50
|
-
}
|
|
51
|
-
}
|
package/src/cotar.cache.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { fsa } from '@chunkd/fs';
|
|
2
|
-
import { Cotar } from '@cotar/core';
|
|
3
|
-
import { LambdaHttpResponse } from '@linzjs/lambda';
|
|
4
|
-
import { NotFound } from './routes/response.js';
|
|
5
|
-
import { St } from './source.tracer.js';
|
|
6
|
-
|
|
7
|
-
export class CotarCache {
|
|
8
|
-
static cache = new Map<string, Promise<Cotar | null>>();
|
|
9
|
-
|
|
10
|
-
static get(uri: string): Promise<Cotar | null> {
|
|
11
|
-
let existing = CotarCache.cache.get(uri);
|
|
12
|
-
if (existing == null) {
|
|
13
|
-
const source = fsa.source(uri);
|
|
14
|
-
St.trace(source);
|
|
15
|
-
existing = Cotar.fromTar(source);
|
|
16
|
-
CotarCache.cache.set(uri, existing);
|
|
17
|
-
}
|
|
18
|
-
return existing;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Load a cotar and look for a file inside the cotar returning the file back as a LambdaResponse
|
|
24
|
-
*
|
|
25
|
-
* This will also set two headers
|
|
26
|
-
* - Content-Encoding if the file starts with gzip magic
|
|
27
|
-
* - Content-Type from the parameter contentType
|
|
28
|
-
*/
|
|
29
|
-
export async function serveFromCotar(
|
|
30
|
-
cotarPath: string,
|
|
31
|
-
assetPath: string,
|
|
32
|
-
contentType: string,
|
|
33
|
-
): Promise<LambdaHttpResponse> {
|
|
34
|
-
const cotar = await CotarCache.get(cotarPath);
|
|
35
|
-
if (cotar == null) return NotFound;
|
|
36
|
-
const fileData = await cotar.get(assetPath);
|
|
37
|
-
if (fileData == null) return NotFound;
|
|
38
|
-
const buf = Buffer.from(fileData);
|
|
39
|
-
const ret = LambdaHttpResponse.ok().buffer(buf, contentType);
|
|
40
|
-
if (isGzip(buf)) ret.header('content-encoding', 'gzip');
|
|
41
|
-
return ret;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Does a buffer look like a gzipped document instead of raw json
|
|
46
|
-
*
|
|
47
|
-
* Determined by checking the first two bytes are the gzip magic bytes `0x1f 0x8b`
|
|
48
|
-
*
|
|
49
|
-
* @see https://en.wikipedia.org/wiki/Gzip
|
|
50
|
-
*
|
|
51
|
-
*/
|
|
52
|
-
export function isGzip(b: Buffer): boolean {
|
|
53
|
-
return b[0] === 0x1f && b[1] === 0x8b;
|
|
54
|
-
}
|
package/src/router.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { Const } from '@basemaps/shared';
|
|
2
|
-
import { HttpHeader, LambdaHttpRequest, LambdaHttpResponse } from '@linzjs/lambda';
|
|
3
|
-
|
|
4
|
-
export type ReqCallback = (req: LambdaHttpRequest) => Promise<LambdaHttpResponse>;
|
|
5
|
-
|
|
6
|
-
export interface ActionData {
|
|
7
|
-
version: string;
|
|
8
|
-
name: string;
|
|
9
|
-
rest: string[];
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export class Router {
|
|
13
|
-
static action(req: LambdaHttpRequest): ActionData {
|
|
14
|
-
const path = req.path;
|
|
15
|
-
const [version, name, ...rest] = (path[0] === '/' ? path.slice(1) : path)
|
|
16
|
-
.split('/')
|
|
17
|
-
.map((c) => decodeURIComponent(c));
|
|
18
|
-
if (name == null) return { version: 'v1', name: version, rest: [] };
|
|
19
|
-
return { version, name: name, rest };
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
static apiKey(req: LambdaHttpRequest): string | undefined {
|
|
23
|
-
const apiKey = req.query.get(Const.ApiKey.QueryString) ?? req.header('X-LINZ-Api-Key');
|
|
24
|
-
if (apiKey != null && !Array.isArray(apiKey)) {
|
|
25
|
-
req.set(Const.ApiKey.QueryString, this.apiKey);
|
|
26
|
-
return apiKey;
|
|
27
|
-
}
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
private handlers: Record<string, ReqCallback> = {};
|
|
32
|
-
|
|
33
|
-
async handle(req: LambdaHttpRequest): Promise<LambdaHttpResponse> {
|
|
34
|
-
// Allow cross origin requests
|
|
35
|
-
if (req.method === 'options') {
|
|
36
|
-
return new LambdaHttpResponse(200, 'Options', {
|
|
37
|
-
[HttpHeader.Cors]: '*',
|
|
38
|
-
'Access-Control-Allow-Credentials': 'false',
|
|
39
|
-
'Access-Control-Allow-Methods': 'OPTIONS,GET,PUT,POST,DELETE',
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (req.method !== 'GET') return new LambdaHttpResponse(405, 'Method not allowed');
|
|
44
|
-
|
|
45
|
-
const action = Router.action(req);
|
|
46
|
-
const handler = action.version === 'v1' ? this.handlers[action.name] : null;
|
|
47
|
-
if (handler == null) return new LambdaHttpResponse(404, 'Not Found');
|
|
48
|
-
|
|
49
|
-
const response = await handler(req);
|
|
50
|
-
response.header(HttpHeader.Cors, '*');
|
|
51
|
-
return response;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
get(path: string, handler: ReqCallback): void {
|
|
55
|
-
if (this.handlers[path] != null) throw new Error(path + ' already registered');
|
|
56
|
-
this.handlers[path] = handler;
|
|
57
|
-
}
|
|
58
|
-
}
|
package/src/routes/api.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { LambdaHttpResponse, HttpHeader } from '@linzjs/lambda';
|
|
2
|
-
|
|
3
|
-
const OkResponse = new LambdaHttpResponse(200, 'ok');
|
|
4
|
-
OkResponse.header(HttpHeader.CacheControl, 'no-store');
|
|
5
|
-
|
|
6
|
-
export async function Ping(): Promise<LambdaHttpResponse> {
|
|
7
|
-
return OkResponse;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export async function Version(): Promise<LambdaHttpResponse> {
|
|
11
|
-
const response = new LambdaHttpResponse(200, 'ok');
|
|
12
|
-
response.header(HttpHeader.CacheControl, 'no-store');
|
|
13
|
-
response.json({ version: process.env.GIT_VERSION ?? 'dev', hash: process.env.GIT_HASH });
|
|
14
|
-
return response;
|
|
15
|
-
}
|
package/src/routes/esri/rest.ts
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { GoogleTms, TileMatrixSet } from '@basemaps/geo';
|
|
2
|
-
import { tileXyzFromPath } from '@basemaps/shared';
|
|
3
|
-
import { LambdaHttpRequest, LambdaHttpResponse } from '@linzjs/lambda';
|
|
4
|
-
import { Router } from '../../router.js';
|
|
5
|
-
import { TileSets } from '../../tile.set.cache.js';
|
|
6
|
-
import { NotFound } from '../response.js';
|
|
7
|
-
|
|
8
|
-
export async function vectorTileServer(
|
|
9
|
-
req: LambdaHttpRequest,
|
|
10
|
-
layerId: string,
|
|
11
|
-
tms: TileMatrixSet,
|
|
12
|
-
): Promise<LambdaHttpResponse> {
|
|
13
|
-
if (tms.identifier !== GoogleTms.identifier) return NotFound;
|
|
14
|
-
const extent = {
|
|
15
|
-
xmin: tms.extent.x,
|
|
16
|
-
ymin: tms.extent.y,
|
|
17
|
-
xmax: tms.extent.right,
|
|
18
|
-
ymax: tms.extent.bottom,
|
|
19
|
-
// TODO where is wkid from
|
|
20
|
-
spatialReference: { wkid: 102100, latestWkid: tms.projection.code },
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const res = new LambdaHttpResponse(200, 'ok');
|
|
24
|
-
res.json({
|
|
25
|
-
currentVersion: 10.4,
|
|
26
|
-
name: layerId,
|
|
27
|
-
capabilities: 'TilesOnly',
|
|
28
|
-
type: 'indexedVector',
|
|
29
|
-
tileMap: 'tilemap',
|
|
30
|
-
defaultStyles: 'resources/styles',
|
|
31
|
-
tiles: ['tiles/{z}/{x}/{y}.pbf'],
|
|
32
|
-
exportTilesAllowed: false,
|
|
33
|
-
maxExportTilesCount: 0,
|
|
34
|
-
initialExtent: extent,
|
|
35
|
-
fullExtent: extent,
|
|
36
|
-
minScale: tms.zooms[0].scaleDenominator,
|
|
37
|
-
maxScale: tms.zooms[tms.zooms.length - 1].scaleDenominator,
|
|
38
|
-
tileInfo: {
|
|
39
|
-
// TODO are all the pbf 256x256?
|
|
40
|
-
rows: 256,
|
|
41
|
-
cols: 256,
|
|
42
|
-
dpi: 96,
|
|
43
|
-
format: 'pbf',
|
|
44
|
-
origin: { x: tms.extent.x, y: tms.extent.bottom },
|
|
45
|
-
spatialReference: { wkid: 102100, latestWkid: tms.projection.code },
|
|
46
|
-
lods: tms.zooms.map((c, i) => {
|
|
47
|
-
return {
|
|
48
|
-
level: i,
|
|
49
|
-
scale: c.scaleDenominator,
|
|
50
|
-
resolution: c.scaleDenominator * 0.28e-3,
|
|
51
|
-
};
|
|
52
|
-
}),
|
|
53
|
-
},
|
|
54
|
-
resourceInfo: {
|
|
55
|
-
styleVersion: 8,
|
|
56
|
-
tileCompression: 'gzip',
|
|
57
|
-
cacheInfo: { storageInfo: { packetSize: 128, storageFormat: 'compactV2' } },
|
|
58
|
-
},
|
|
59
|
-
});
|
|
60
|
-
return res;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* /v1/esri/services/:layerId/VectorTileServer
|
|
65
|
-
*
|
|
66
|
-
* @example http://localhost:5000/v1/esri/services/topographic/VectorTileServer
|
|
67
|
-
*/
|
|
68
|
-
export async function Esri(req: LambdaHttpRequest): Promise<LambdaHttpResponse> {
|
|
69
|
-
const { rest } = Router.action(req);
|
|
70
|
-
if (rest[0] !== 'services') return NotFound;
|
|
71
|
-
const layerId = rest[1];
|
|
72
|
-
if (layerId == null) return NotFound;
|
|
73
|
-
|
|
74
|
-
const serviceId = rest[2];
|
|
75
|
-
if (serviceId !== 'VectorTileServer') return NotFound;
|
|
76
|
-
if (rest.length === 3) return vectorTileServer(req, layerId, GoogleTms);
|
|
77
|
-
|
|
78
|
-
if (rest[rest.length - 1].endsWith('.pbf')) {
|
|
79
|
-
const generatedPath = [layerId, GoogleTms.identifier, ...rest.slice(rest.length - 3)];
|
|
80
|
-
const xyz = tileXyzFromPath(generatedPath);
|
|
81
|
-
if (xyz == null) return NotFound;
|
|
82
|
-
req.timer.start('tileset:load');
|
|
83
|
-
const tileSet = await TileSets.get(xyz.name, xyz.tileMatrix);
|
|
84
|
-
req.timer.end('tileset:load');
|
|
85
|
-
if (tileSet == null) return NotFound;
|
|
86
|
-
return await tileSet.tile(req, xyz);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return new LambdaHttpResponse(200, 'ok');
|
|
90
|
-
}
|
package/src/routes/response.ts
DELETED