@basemaps/lambda-tiler 6.16.1 → 6.20.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 +49 -0
- package/LICENSE +2 -2
- package/build/__test__/tile.style.json.test.d.ts +2 -0
- package/build/__test__/tile.style.json.test.d.ts.map +1 -0
- package/build/__test__/tile.style.json.test.js +33 -0
- package/build/__test__/xyz.test.js +35 -34
- package/build/cli/dump.js +2 -2
- package/build/index.d.ts.map +1 -1
- package/build/index.js +10 -0
- package/build/routes/esri/rest.d.ts +10 -0
- package/build/routes/esri/rest.d.ts.map +1 -0
- package/build/routes/esri/rest.js +87 -0
- package/build/routes/imagery.d.ts +10 -0
- package/build/routes/imagery.d.ts.map +1 -0
- package/build/routes/imagery.js +50 -0
- package/build/routes/response.d.ts +4 -0
- package/build/routes/response.d.ts.map +1 -0
- package/build/routes/response.js +3 -0
- package/build/routes/tile.d.ts +0 -20
- package/build/routes/tile.d.ts.map +1 -1
- package/build/routes/tile.js +11 -164
- package/build/routes/tile.json.d.ts +10 -0
- package/build/routes/tile.json.d.ts.map +1 -0
- package/build/routes/tile.json.js +31 -0
- package/build/routes/tile.style.json.d.ts +10 -0
- package/build/routes/tile.style.json.d.ts.map +1 -0
- package/build/routes/tile.style.json.js +74 -0
- package/build/routes/tile.wmts.d.ts +9 -0
- package/build/routes/tile.wmts.d.ts.map +1 -0
- package/build/routes/tile.wmts.js +57 -0
- package/build/routes/tile.xyz.d.ts +13 -0
- package/build/routes/tile.xyz.d.ts.map +1 -0
- package/build/routes/tile.xyz.js +28 -0
- package/build/tile.set.raster.d.ts +2 -0
- package/build/tile.set.raster.d.ts.map +1 -1
- package/build/tile.set.raster.js +3 -1
- package/build/tile.set.vector.js +1 -1
- package/dist/index.js +10580 -9573
- package/dist/node_modules/color/README.md +7 -7
- package/dist/node_modules/color/index.js +173 -158
- package/dist/node_modules/color/package.json +18 -16
- package/dist/node_modules/color-convert/conversions.js +281 -310
- package/dist/node_modules/color-convert/index.js +27 -24
- package/dist/node_modules/color-convert/package.json +16 -14
- package/dist/node_modules/color-convert/route.js +22 -22
- package/dist/node_modules/color-name/package.json +17 -14
- package/dist/node_modules/color-string/index.js +2 -2
- package/dist/node_modules/color-string/package.json +10 -10
- package/dist/node_modules/decompress-response/index.d.ts +14 -21
- package/dist/node_modules/decompress-response/index.js +34 -16
- package/dist/node_modules/decompress-response/license +1 -1
- package/dist/node_modules/decompress-response/package.json +23 -17
- package/dist/node_modules/decompress-response/readme.md +2 -6
- package/dist/node_modules/detect-libc/package.json +0 -1
- package/dist/node_modules/mimic-response/index.d.ts +2 -2
- package/dist/node_modules/mimic-response/index.js +41 -2
- package/dist/node_modules/mimic-response/package.json +17 -17
- package/dist/node_modules/mimic-response/readme.md +22 -1
- package/dist/node_modules/node-abi/.circleci/config.yml +63 -0
- package/dist/node_modules/node-abi/.releaserc.json +9 -0
- package/dist/node_modules/node-abi/abi_registry.json +39 -4
- package/dist/node_modules/node-abi/index.js +5 -2
- package/dist/node_modules/node-abi/package.json +17 -16
- package/dist/node_modules/node-abi/test/index.js +7 -15
- package/dist/node_modules/node-addon-api/README.md +2 -2
- package/dist/node_modules/node-addon-api/except.gypi +20 -11
- package/dist/node_modules/node-addon-api/napi-inl.h +734 -196
- package/dist/node_modules/node-addon-api/napi.h +420 -164
- package/dist/node_modules/node-addon-api/noexcept.gypi +21 -11
- package/dist/node_modules/node-addon-api/package.json +43 -14
- package/dist/node_modules/node-addon-api/tools/clang-format.js +18 -17
- package/dist/node_modules/node-addon-api/tools/eslint-format.js +71 -0
- package/dist/node_modules/prebuild-install/CHANGELOG.md +24 -7
- package/dist/node_modules/prebuild-install/README.md +24 -4
- package/dist/node_modules/prebuild-install/asset.js +10 -10
- package/dist/node_modules/prebuild-install/bin.js +13 -13
- package/dist/node_modules/prebuild-install/download.js +22 -22
- package/dist/node_modules/prebuild-install/log.js +4 -4
- package/dist/node_modules/prebuild-install/node_modules/detect-libc/LICENSE +201 -0
- package/dist/node_modules/prebuild-install/node_modules/detect-libc/README.md +160 -0
- package/dist/node_modules/prebuild-install/node_modules/detect-libc/index.d.ts +11 -0
- package/dist/node_modules/prebuild-install/node_modules/detect-libc/lib/detect-libc.js +178 -0
- package/dist/node_modules/prebuild-install/node_modules/detect-libc/lib/process.js +16 -0
- package/dist/node_modules/prebuild-install/node_modules/detect-libc/package.json +71 -0
- package/dist/node_modules/prebuild-install/package.json +18 -19
- package/dist/node_modules/prebuild-install/proxy.js +10 -10
- package/dist/node_modules/prebuild-install/rc.js +12 -12
- package/dist/node_modules/prebuild-install/util.js +14 -14
- package/dist/node_modules/semver/package.json +1 -0
- package/dist/node_modules/sharp/README.md +2 -2
- package/dist/node_modules/sharp/binding.gyp +12 -9
- package/dist/node_modules/sharp/build/Release/sharp-linux-x64.node +0 -0
- package/dist/node_modules/sharp/install/dll-copy.js +6 -6
- package/dist/node_modules/sharp/install/libvips.js +4 -8
- package/dist/node_modules/sharp/lib/channel.js +11 -7
- package/dist/node_modules/sharp/lib/colour.js +42 -1
- package/dist/node_modules/sharp/lib/constructor.js +18 -31
- package/dist/node_modules/sharp/lib/input.js +45 -3
- package/dist/node_modules/sharp/lib/is.js +19 -5
- package/dist/node_modules/sharp/lib/libvips.js +4 -19
- package/dist/node_modules/sharp/lib/operation.js +28 -5
- package/dist/node_modules/sharp/lib/output.js +147 -16
- package/dist/node_modules/sharp/lib/sharp.js +31 -0
- package/dist/node_modules/sharp/lib/utility.js +3 -2
- package/dist/node_modules/sharp/package.json +32 -23
- package/dist/node_modules/sharp/src/common.cc +67 -11
- package/dist/node_modules/sharp/src/common.h +25 -5
- package/dist/node_modules/sharp/src/libvips/cplusplus/VConnection.cpp +0 -26
- package/dist/node_modules/sharp/src/libvips/cplusplus/VImage.cpp +54 -16
- package/dist/node_modules/sharp/src/libvips/cplusplus/VInterpolate.cpp +0 -13
- package/dist/node_modules/sharp/src/libvips/cplusplus/vips-operators.cpp +185 -1
- package/dist/node_modules/sharp/src/metadata.cc +14 -0
- package/dist/node_modules/sharp/src/metadata.h +1 -0
- package/dist/node_modules/sharp/src/operations.cc +29 -3
- package/dist/node_modules/sharp/src/operations.h +13 -2
- package/dist/node_modules/sharp/src/pipeline.cc +103 -35
- package/dist/node_modules/sharp/src/pipeline.h +23 -3
- package/dist/node_modules/sharp/src/utilities.cc +1 -1
- package/dist/node_modules/sharp/vendor/{8.10.6 → 8.11.3/linux-x64}/THIRD-PARTY-NOTICES.md +2 -3
- package/dist/node_modules/sharp/vendor/{8.10.6 → 8.11.3/linux-x64}/lib/libvips-cpp.so.42 +0 -0
- package/dist/node_modules/sharp/vendor/{8.10.6 → 8.11.3/linux-x64}/platform.json +0 -0
- package/dist/node_modules/sharp/vendor/8.11.3/linux-x64/versions.json +30 -0
- package/dist/node_modules/simple-get/.github/dependabot.yml +15 -0
- package/dist/node_modules/simple-get/.github/workflows/ci.yml +23 -0
- package/dist/node_modules/simple-get/README.md +17 -3
- package/dist/node_modules/simple-get/index.js +9 -0
- package/dist/node_modules/simple-get/package.json +27 -13
- package/dist/package-lock.json +54 -54
- package/dist/package.json +11 -11
- package/package.json +12 -12
- package/src/__test__/tile.style.json.test.ts +40 -0
- package/src/__test__/xyz.test.ts +43 -41
- package/src/cli/dump.ts +2 -2
- package/src/index.ts +10 -0
- package/src/routes/esri/rest.ts +90 -0
- package/src/routes/imagery.ts +52 -0
- package/src/routes/response.ts +4 -0
- package/src/routes/tile.json.ts +44 -0
- package/src/routes/tile.style.json.ts +77 -0
- package/src/routes/tile.ts +11 -186
- package/src/routes/tile.wmts.ts +59 -0
- package/src/routes/tile.xyz.ts +30 -0
- package/src/tile.set.raster.ts +4 -1
- package/src/tile.set.vector.ts +1 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/node_modules/color-name/.eslintrc.json +0 -43
- package/dist/node_modules/color-name/test.js +0 -7
- package/dist/node_modules/node-abi/.travis.yml +0 -17
- package/dist/node_modules/node-abi/node_modules/semver/CHANGELOG.md +0 -39
- package/dist/node_modules/node-abi/node_modules/semver/LICENSE +0 -15
- package/dist/node_modules/node-abi/node_modules/semver/README.md +0 -412
- package/dist/node_modules/node-abi/node_modules/semver/bin/semver +0 -160
- package/dist/node_modules/node-abi/node_modules/semver/package.json +0 -60
- package/dist/node_modules/node-abi/node_modules/semver/range.bnf +0 -16
- package/dist/node_modules/node-abi/node_modules/semver/semver.js +0 -1483
- package/dist/node_modules/node-addon-api/CHANGELOG.md +0 -722
- package/dist/node_modules/sharp/build/Release/sharp.node +0 -0
- package/dist/node_modules/sharp/vendor/8.10.6/versions.json +0 -31
package/src/__test__/xyz.test.ts
CHANGED
|
@@ -3,17 +3,21 @@ import { TileMatrixSets } from '@basemaps/geo';
|
|
|
3
3
|
import { Config, Env, LogConfig, VNodeParser } from '@basemaps/shared';
|
|
4
4
|
import { round } from '@basemaps/test/build/rounding.js';
|
|
5
5
|
import o from 'ospec';
|
|
6
|
+
import sinon from 'sinon';
|
|
6
7
|
import { handleRequest } from '../index.js';
|
|
7
|
-
import { TileComposer } from '../routes/tile.js';
|
|
8
8
|
import { TileEtag } from '../routes/tile.etag.js';
|
|
9
9
|
import { TileSets } from '../tile.set.cache.js';
|
|
10
|
+
import { TileComposer } from '../tile.set.raster.js';
|
|
10
11
|
import { FakeTileSet, mockRequest, Provider } from './xyz.util.js';
|
|
11
|
-
|
|
12
|
+
|
|
12
13
|
const sandbox = sinon.createSandbox();
|
|
13
14
|
|
|
14
15
|
const TileSetNames = ['aerial', 'aerial@head', 'aerial@beta', '01E7PJFR9AMQFJ05X9G7FQ3XMW'];
|
|
15
16
|
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
16
17
|
o.spec('LambdaXyz', () => {
|
|
18
|
+
const host = 'https://tiles.test';
|
|
19
|
+
const origPublicUrlBase = process.env[Env.PublicUrlBase];
|
|
20
|
+
|
|
17
21
|
/** Generate mock ALBEvent */
|
|
18
22
|
|
|
19
23
|
let rasterMock = o.spy();
|
|
@@ -26,6 +30,8 @@ o.spec('LambdaXyz', () => {
|
|
|
26
30
|
const apiKeyHeader = { 'x-linz-api-key': 'd01f7w7rnhdzg0p7fyrc9v9ard1' };
|
|
27
31
|
|
|
28
32
|
o.beforeEach(() => {
|
|
33
|
+
process.env[Env.PublicUrlBase] = host;
|
|
34
|
+
|
|
29
35
|
LogConfig.disable();
|
|
30
36
|
// tileMock = o.spy(() => tileMockData) as any;
|
|
31
37
|
rasterMock = o.spy(() => {
|
|
@@ -54,6 +60,7 @@ o.spec('LambdaXyz', () => {
|
|
|
54
60
|
TileSets.cache.clear();
|
|
55
61
|
TileComposer.compose = origCompose;
|
|
56
62
|
TileEtag.generate = origTileEtag;
|
|
63
|
+
process.env[Env.PublicUrlBase] = origPublicUrlBase;
|
|
57
64
|
sandbox.restore();
|
|
58
65
|
});
|
|
59
66
|
|
|
@@ -134,12 +141,8 @@ o.spec('LambdaXyz', () => {
|
|
|
134
141
|
});
|
|
135
142
|
|
|
136
143
|
o.spec('WMTSCapabilities', () => {
|
|
137
|
-
const origPublicUrlBase = process.env[Env.PublicUrlBase];
|
|
138
|
-
o.after(() => {
|
|
139
|
-
process.env[Env.PublicUrlBase] = origPublicUrlBase;
|
|
140
|
-
});
|
|
141
|
-
|
|
142
144
|
o('should 304 if a xml is not modified', async () => {
|
|
145
|
+
delete process.env[Env.PublicUrlBase];
|
|
143
146
|
o.timeout(1000);
|
|
144
147
|
const key = 'NuirTK8fozzCJV1iG1FznmdHhKvk6WaWuDhhEA1d40c=';
|
|
145
148
|
const request = mockRequest('/v1/tiles/WMTSCapabilities.xml', 'get', {
|
|
@@ -148,6 +151,7 @@ o.spec('LambdaXyz', () => {
|
|
|
148
151
|
});
|
|
149
152
|
|
|
150
153
|
const res = await handleRequest(request);
|
|
154
|
+
|
|
151
155
|
if (res.status === 200) {
|
|
152
156
|
o(res.header('eTaG')).equals(key); // this line is useful for discovering the new etag
|
|
153
157
|
return;
|
|
@@ -160,9 +164,6 @@ o.spec('LambdaXyz', () => {
|
|
|
160
164
|
});
|
|
161
165
|
|
|
162
166
|
o('should serve WMTSCapabilities for tile_set', async () => {
|
|
163
|
-
console.log('\n\nTestStart');
|
|
164
|
-
process.env[Env.PublicUrlBase] = 'https://tiles.test';
|
|
165
|
-
|
|
166
167
|
const request = mockRequest('/v1/tiles/aerial@beta/WMTSCapabilities.xml', 'get', apiKeyHeader);
|
|
167
168
|
|
|
168
169
|
const res = await handleRequest(request);
|
|
@@ -185,13 +186,10 @@ o.spec('LambdaXyz', () => {
|
|
|
185
186
|
});
|
|
186
187
|
|
|
187
188
|
o.spec('tileJson', () => {
|
|
188
|
-
const origPublicUrlBase = process.env[Env.PublicUrlBase];
|
|
189
|
-
o.after(() => {
|
|
190
|
-
process.env[Env.PublicUrlBase] = origPublicUrlBase;
|
|
191
|
-
});
|
|
192
|
-
|
|
193
189
|
o('should 304 if a json is not modified', async () => {
|
|
194
|
-
|
|
190
|
+
// delete process.env[Env.PublicUrlBase];
|
|
191
|
+
|
|
192
|
+
const key = 'BBfQpNXA3Q90jlFrLSOZhxbvfOh7OpN1OEE+BylpbHw=';
|
|
195
193
|
const request = mockRequest('/v1/tiles/tile.json', 'get', { 'if-none-match': key, ...apiKeyHeader });
|
|
196
194
|
|
|
197
195
|
const res = await handleRequest(request);
|
|
@@ -206,10 +204,20 @@ o.spec('LambdaXyz', () => {
|
|
|
206
204
|
o(request.logContext['cache']).deepEquals({ key, match: key, hit: true });
|
|
207
205
|
});
|
|
208
206
|
|
|
209
|
-
o('should
|
|
210
|
-
|
|
207
|
+
o('should 200 if a invalid etag is given', async () => {
|
|
208
|
+
const key = 'ABCXecTdbcdjCyzB1MHOOQbrOkD2TTJ0ORh4JuXqhxXEE0=';
|
|
209
|
+
const request = mockRequest('/v1/tiles/tile.json', 'get', { 'if-none-match': key, ...apiKeyHeader });
|
|
211
210
|
|
|
212
|
-
const
|
|
211
|
+
const res = await handleRequest(request);
|
|
212
|
+
o(res.status).equals(200);
|
|
213
|
+
o(res.header('etag')).equals('BBfQpNXA3Q90jlFrLSOZhxbvfOh7OpN1OEE+BylpbHw=');
|
|
214
|
+
const out = JSON.parse(Buffer.from(res.body ?? '', 'base64').toString());
|
|
215
|
+
o(out.tiles[0].startsWith('https://tiles.test/v1/tiles/tile.json/undefined/{z}/{x}/{y}.pbf?api=')).equals(true);
|
|
216
|
+
o(request.logContext['cache']).deepEquals(undefined);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
o('should serve tile json for tile_set', async () => {
|
|
220
|
+
const request = mockRequest('/v1/tiles/topographic/Google/tile.json', 'get', apiKeyHeader);
|
|
213
221
|
|
|
214
222
|
const res = await handleRequest(request);
|
|
215
223
|
o(res.status).equals(200);
|
|
@@ -218,7 +226,7 @@ o.spec('LambdaXyz', () => {
|
|
|
218
226
|
|
|
219
227
|
const body = Buffer.from(res.body ?? '', 'base64').toString();
|
|
220
228
|
o(JSON.parse(body)).deepEquals({
|
|
221
|
-
tiles: [`https://tiles.test/v1/tiles/
|
|
229
|
+
tiles: [`https://tiles.test/v1/tiles/topographic/Google/{z}/{x}/{y}.pbf?api=${apiKey}`],
|
|
222
230
|
minzoom: 0,
|
|
223
231
|
maxzoom: 15,
|
|
224
232
|
format: 'pbf',
|
|
@@ -228,15 +236,8 @@ o.spec('LambdaXyz', () => {
|
|
|
228
236
|
});
|
|
229
237
|
|
|
230
238
|
o.spec('styleJson', () => {
|
|
231
|
-
const origPublicUrlBase = process.env[Env.PublicUrlBase];
|
|
232
|
-
o.after(() => {
|
|
233
|
-
process.env[Env.PublicUrlBase] = origPublicUrlBase;
|
|
234
|
-
});
|
|
235
|
-
|
|
236
239
|
o('should not found style json', async () => {
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
const request = mockRequest('/v1/tiles/topolike/Google/style/topolike.json', 'get', apiKeyHeader);
|
|
240
|
+
const request = mockRequest('/v1/tiles/topographic/Google/style/topographic.json', 'get', apiKeyHeader);
|
|
240
241
|
|
|
241
242
|
sandbox.stub(Config.Style, 'get').resolves(null);
|
|
242
243
|
|
|
@@ -245,27 +246,24 @@ o.spec('LambdaXyz', () => {
|
|
|
245
246
|
});
|
|
246
247
|
|
|
247
248
|
o('should serve style json', async () => {
|
|
248
|
-
const
|
|
249
|
-
process.env[Env.PublicUrlBase] = host;
|
|
250
|
-
|
|
251
|
-
const request = mockRequest('/v1/tiles/topolike/Google/style/topolike.json', 'get', apiKeyHeader);
|
|
249
|
+
const request = mockRequest('/v1/tiles/topographic/Google/style/topographic.json', 'get', apiKeyHeader);
|
|
252
250
|
|
|
253
251
|
const fakeStyle: StyleJson = {
|
|
254
252
|
version: 8,
|
|
255
253
|
id: 'test',
|
|
256
|
-
name: '
|
|
254
|
+
name: 'topographic',
|
|
257
255
|
sources: {
|
|
258
256
|
basemaps_vector: {
|
|
259
257
|
type: 'vector',
|
|
260
|
-
url:
|
|
258
|
+
url: `/vector`,
|
|
261
259
|
},
|
|
262
260
|
basemaps_raster: {
|
|
263
261
|
type: 'raster',
|
|
264
|
-
tiles: [
|
|
262
|
+
tiles: [`/raster`],
|
|
265
263
|
},
|
|
266
264
|
basemaps_raster_encode: {
|
|
267
265
|
type: 'raster',
|
|
268
|
-
tiles: [
|
|
266
|
+
tiles: [`/raster/{z}/{x}/{y}.webp`], // Shouldn't encode the {}
|
|
269
267
|
},
|
|
270
268
|
test_vector: {
|
|
271
269
|
type: 'vector',
|
|
@@ -289,14 +287,14 @@ o.spec('LambdaXyz', () => {
|
|
|
289
287
|
minzoom: 0,
|
|
290
288
|
},
|
|
291
289
|
],
|
|
292
|
-
glyphs: 'glyphs',
|
|
293
|
-
sprite: 'sprite',
|
|
290
|
+
glyphs: '/glyphs',
|
|
291
|
+
sprite: '/sprite',
|
|
294
292
|
metadata: { id: 'test' },
|
|
295
293
|
};
|
|
296
294
|
|
|
297
295
|
const fakeRecord = {
|
|
298
|
-
id: '
|
|
299
|
-
name: '
|
|
296
|
+
id: 'st_topographic_production',
|
|
297
|
+
name: 'topographic',
|
|
300
298
|
style: fakeStyle,
|
|
301
299
|
};
|
|
302
300
|
|
|
@@ -305,7 +303,7 @@ o.spec('LambdaXyz', () => {
|
|
|
305
303
|
const res = await handleRequest(request);
|
|
306
304
|
o(res.status).equals(200);
|
|
307
305
|
o(res.header('content-type')).equals('application/json');
|
|
308
|
-
o(res.header('cache-control')).equals('
|
|
306
|
+
o(res.header('cache-control')).equals('no-store');
|
|
309
307
|
|
|
310
308
|
const body = Buffer.from(res.body ?? '', 'base64').toString();
|
|
311
309
|
fakeStyle.sources.basemaps_vector = {
|
|
@@ -320,6 +318,10 @@ o.spec('LambdaXyz', () => {
|
|
|
320
318
|
type: 'raster',
|
|
321
319
|
tiles: [`${host}/raster/{z}/{x}/{y}.webp?api=${apiKey}`],
|
|
322
320
|
};
|
|
321
|
+
|
|
322
|
+
fakeStyle.sprite = `${host}/sprite`;
|
|
323
|
+
fakeStyle.glyphs = `${host}/glyphs`;
|
|
324
|
+
|
|
323
325
|
o(JSON.parse(body)).deepEquals(fakeStyle);
|
|
324
326
|
});
|
|
325
327
|
});
|
package/src/cli/dump.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { ImageFormat } from '@basemaps/tiler';
|
|
|
4
4
|
import { LambdaAlbRequest } from '@linzjs/lambda';
|
|
5
5
|
import { Context } from 'aws-lambda';
|
|
6
6
|
import { promises as fs } from 'fs';
|
|
7
|
-
import {
|
|
7
|
+
import { tileXyz } from '../routes/tile.xyz.js';
|
|
8
8
|
import { TileSets } from '../tile.set.cache.js';
|
|
9
9
|
import { TileSet } from '../tile.set.js';
|
|
10
10
|
import { TileSetLocal } from './tile.set.local.js';
|
|
@@ -48,7 +48,7 @@ async function main(): Promise<void> {
|
|
|
48
48
|
logger,
|
|
49
49
|
);
|
|
50
50
|
|
|
51
|
-
const tileData = await
|
|
51
|
+
const tileData = await tileXyz(ctx);
|
|
52
52
|
|
|
53
53
|
const headers: Record<string, any> = {};
|
|
54
54
|
for (const [key, value] of tileData.headers) headers[key] = value;
|
package/src/index.ts
CHANGED
|
@@ -4,6 +4,9 @@ import { Ping, Version } from './routes/api.js';
|
|
|
4
4
|
import { Health } from './routes/health.js';
|
|
5
5
|
import { Tiles } from './routes/tile.js';
|
|
6
6
|
import { Router } from './router.js';
|
|
7
|
+
import { createHash } from 'crypto';
|
|
8
|
+
import { Imagery } from './routes/imagery.js';
|
|
9
|
+
import { Esri } from './routes/esri/rest.js';
|
|
7
10
|
|
|
8
11
|
const app = new Router();
|
|
9
12
|
|
|
@@ -11,6 +14,8 @@ app.get('ping', Ping);
|
|
|
11
14
|
app.get('health', Health);
|
|
12
15
|
app.get('version', Version);
|
|
13
16
|
app.get('tiles', Tiles);
|
|
17
|
+
app.get('imagery', Imagery);
|
|
18
|
+
app.get('esri', Esri);
|
|
14
19
|
|
|
15
20
|
let slowTimer: NodeJS.Timer | null = null;
|
|
16
21
|
export async function handleRequest(req: LambdaHttpRequest): Promise<LambdaHttpResponse> {
|
|
@@ -21,6 +26,11 @@ export async function handleRequest(req: LambdaHttpRequest): Promise<LambdaHttpR
|
|
|
21
26
|
|
|
22
27
|
req.set('name', 'LambdaTiler');
|
|
23
28
|
try {
|
|
29
|
+
const apiKey = Router.apiKey(req);
|
|
30
|
+
if (apiKey != null) {
|
|
31
|
+
const apiKeyHash = createHash('sha256').update(apiKey).digest('base64');
|
|
32
|
+
req.set('api', apiKeyHash);
|
|
33
|
+
}
|
|
24
34
|
return await app.handle(req);
|
|
25
35
|
} finally {
|
|
26
36
|
if (slowTimer) clearTimeout(slowTimer);
|
|
@@ -0,0 +1,90 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Config } from '@basemaps/config';
|
|
2
|
+
import { fsa } from '@basemaps/shared';
|
|
3
|
+
import { HttpHeader, LambdaHttpRequest, LambdaHttpResponse } from '@linzjs/lambda';
|
|
4
|
+
import { createHash } from 'crypto';
|
|
5
|
+
import { promisify } from 'util';
|
|
6
|
+
import { gzip } from 'zlib';
|
|
7
|
+
import { Router } from '../router.js';
|
|
8
|
+
import { NotModified } from './response.js';
|
|
9
|
+
import { TileEtag } from './tile.etag.js';
|
|
10
|
+
|
|
11
|
+
const gzipP = promisify(gzip);
|
|
12
|
+
|
|
13
|
+
function isAllowedFile(f: string): boolean {
|
|
14
|
+
if (f.endsWith('.geojson')) return true;
|
|
15
|
+
if (f.endsWith('.json')) return true;
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Get metadata around the imagery such as the source bounding box or the bounding box of the COGS
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* - /v1/imagery/:imageryId/source.geojson
|
|
24
|
+
* - /v1/imagery/:imageryId/covering.geojson
|
|
25
|
+
*/
|
|
26
|
+
export async function Imagery(req: LambdaHttpRequest): Promise<LambdaHttpResponse> {
|
|
27
|
+
const { rest } = Router.action(req);
|
|
28
|
+
const [imageryId, requestType] = rest;
|
|
29
|
+
if (!isAllowedFile(requestType)) return new LambdaHttpResponse(404, 'Not found');
|
|
30
|
+
|
|
31
|
+
const imagery = await Config.Imagery.get(imageryId);
|
|
32
|
+
if (imagery == null) return new LambdaHttpResponse(404, 'Not found');
|
|
33
|
+
|
|
34
|
+
const targetPath = fsa.join(imagery.uri, requestType);
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
const buf = await fsa.read(targetPath);
|
|
38
|
+
const cacheKey = createHash('sha256').update(buf).digest('base64');
|
|
39
|
+
|
|
40
|
+
if (TileEtag.isNotModified(req, cacheKey)) return NotModified;
|
|
41
|
+
|
|
42
|
+
const response = new LambdaHttpResponse(200, 'ok');
|
|
43
|
+
response.header(HttpHeader.ETag, cacheKey);
|
|
44
|
+
response.header(HttpHeader.ContentEncoding, 'gzip');
|
|
45
|
+
response.buffer(await gzipP(buf), 'application/json');
|
|
46
|
+
req.set('bytes', buf.byteLength);
|
|
47
|
+
return response;
|
|
48
|
+
} catch (e) {
|
|
49
|
+
req.log.warn({ targetPath }, 'ImageryMetadata:Failed');
|
|
50
|
+
return new LambdaHttpResponse(404, 'Not found');
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Env } from '@basemaps/shared';
|
|
2
|
+
import { HttpHeader, LambdaHttpRequest, LambdaHttpResponse } from '@linzjs/lambda';
|
|
3
|
+
import { createHash } from 'crypto';
|
|
4
|
+
import { Router } from '../router.js';
|
|
5
|
+
import { NotModified } from './response.js';
|
|
6
|
+
import { TileEtag } from './tile.etag.js';
|
|
7
|
+
|
|
8
|
+
export interface TileJson {
|
|
9
|
+
tiles: string[];
|
|
10
|
+
minzoom: number;
|
|
11
|
+
maxzoom: number;
|
|
12
|
+
format: string;
|
|
13
|
+
tilejson: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export async function tileJson(req: LambdaHttpRequest): Promise<LambdaHttpResponse> {
|
|
17
|
+
const { version, rest, name } = Router.action(req);
|
|
18
|
+
const apiKey = Router.apiKey(req);
|
|
19
|
+
const host = Env.get(Env.PublicUrlBase) ?? '';
|
|
20
|
+
const tileUrl = `${host}/${version}/${name}/${rest[0]}/${rest[1]}/{z}/{x}/{y}.pbf?api=${apiKey}`;
|
|
21
|
+
|
|
22
|
+
const tileJson: TileJson = {
|
|
23
|
+
tiles: [tileUrl],
|
|
24
|
+
minzoom: 0,
|
|
25
|
+
maxzoom: 15,
|
|
26
|
+
format: 'pbf',
|
|
27
|
+
tilejson: '2.0.0',
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const json = JSON.stringify(tileJson);
|
|
31
|
+
|
|
32
|
+
const data = Buffer.from(json);
|
|
33
|
+
|
|
34
|
+
const cacheKey = createHash('sha256').update(data).digest('base64');
|
|
35
|
+
|
|
36
|
+
if (TileEtag.isNotModified(req, cacheKey)) return NotModified;
|
|
37
|
+
|
|
38
|
+
const response = new LambdaHttpResponse(200, 'ok');
|
|
39
|
+
response.header(HttpHeader.ETag, cacheKey);
|
|
40
|
+
response.header(HttpHeader.CacheControl, 'max-age=120');
|
|
41
|
+
response.buffer(data, 'application/json');
|
|
42
|
+
req.set('bytes', data.byteLength);
|
|
43
|
+
return response;
|
|
44
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Sources, StyleJson } from '@basemaps/config';
|
|
2
|
+
import { Config, Env } from '@basemaps/shared';
|
|
3
|
+
import { fsa } from '@chunkd/fs';
|
|
4
|
+
import { HttpHeader, LambdaHttpRequest, LambdaHttpResponse } from '@linzjs/lambda';
|
|
5
|
+
import { createHash } from 'crypto';
|
|
6
|
+
import { URL } from 'url';
|
|
7
|
+
import { Router } from '../router.js';
|
|
8
|
+
import { NotFound, NotModified } from './response.js';
|
|
9
|
+
import { TileEtag } from './tile.etag.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Convert relative URLS into a full hostname url
|
|
13
|
+
* @param url possible url to update
|
|
14
|
+
* @param apiKey ApiKey to append with ?api= if required
|
|
15
|
+
* @returns Updated Url or empty string if url is empty
|
|
16
|
+
*/
|
|
17
|
+
export function convertRelativeUrl(url?: string, apiKey?: string): string {
|
|
18
|
+
if (url == null) return '';
|
|
19
|
+
const host = Env.get(Env.PublicUrlBase) ?? '';
|
|
20
|
+
if (!url.startsWith('/')) return url; // Not relative ignore
|
|
21
|
+
const fullUrl = new URL(fsa.join(host, url));
|
|
22
|
+
if (apiKey) fullUrl.searchParams.set('api', apiKey);
|
|
23
|
+
return fullUrl.toString().replace(/%7B/g, '{').replace(/%7D/g, '}');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export async function styleJson(req: LambdaHttpRequest, fileName: string): Promise<LambdaHttpResponse> {
|
|
27
|
+
const apiKey = Router.apiKey(req);
|
|
28
|
+
if (apiKey == null) return new LambdaHttpResponse(400, 'Invalid API Key.');
|
|
29
|
+
const styleName = fileName.split('.json')[0];
|
|
30
|
+
|
|
31
|
+
// Get style Config from db
|
|
32
|
+
const dbId = Config.Style.id(styleName);
|
|
33
|
+
const styleConfig = await Config.Style.get(dbId);
|
|
34
|
+
if (styleConfig == null) return NotFound;
|
|
35
|
+
|
|
36
|
+
// Prepare sources and add linz source
|
|
37
|
+
const style = styleConfig.style;
|
|
38
|
+
const sources: Sources = {};
|
|
39
|
+
for (const [key, value] of Object.entries(style.sources)) {
|
|
40
|
+
if (value.type === 'vector') {
|
|
41
|
+
value.url = convertRelativeUrl(value.url, apiKey);
|
|
42
|
+
} else if (value.type === 'raster' && Array.isArray(value.tiles)) {
|
|
43
|
+
for (let i = 0; i < value.tiles.length; i++) {
|
|
44
|
+
value.tiles[i] = convertRelativeUrl(value.tiles[i], apiKey);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
sources[key] = value;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// prepare Style.json
|
|
51
|
+
const styleJson: StyleJson = {
|
|
52
|
+
/** Style.json version 8 */
|
|
53
|
+
version: 8,
|
|
54
|
+
id: style.id,
|
|
55
|
+
name: style.name,
|
|
56
|
+
sources,
|
|
57
|
+
layers: style.layers,
|
|
58
|
+
metadata: style.metadata || {},
|
|
59
|
+
glyphs: convertRelativeUrl(style.glyphs),
|
|
60
|
+
sprite: convertRelativeUrl(style.sprite),
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const json = JSON.stringify(styleJson);
|
|
64
|
+
|
|
65
|
+
const data = Buffer.from(json);
|
|
66
|
+
|
|
67
|
+
const cacheKey = createHash('sha256').update(data).digest('base64');
|
|
68
|
+
|
|
69
|
+
if (TileEtag.isNotModified(req, cacheKey)) return NotModified;
|
|
70
|
+
|
|
71
|
+
const response = new LambdaHttpResponse(200, 'ok');
|
|
72
|
+
response.header(HttpHeader.ETag, cacheKey);
|
|
73
|
+
response.header(HttpHeader.CacheControl, 'no-store');
|
|
74
|
+
response.buffer(data, 'application/json');
|
|
75
|
+
req.set('bytes', data.byteLength);
|
|
76
|
+
return response;
|
|
77
|
+
}
|