@basemaps/lambda-tiler 6.30.0 → 6.32.1
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 +46 -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__/wmts.capability.test.js +88 -6
- package/build/__tests__/wmts.capability.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 +49 -91
- 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/build/wmts.capability.js +24 -8
- package/build/wmts.capability.js.map +1 -1
- package/dist/index.js +78 -76
- 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 +10 -10
- package/src/__tests__/config.data.ts +41 -3
- package/src/__tests__/index.test.ts +3 -19
- package/src/__tests__/wmts.capability.test.ts +109 -6
- 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 +59 -111
- 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 +30 -13
- 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,56 +0,0 @@
|
|
|
1
|
-
import { GoogleTms, Nztm2000Tms, ImageFormat } from '@basemaps/geo';
|
|
2
|
-
import { TileDataXyz, TileType } from '@basemaps/shared';
|
|
3
|
-
import { TestTiff } from '@basemaps/test';
|
|
4
|
-
import { Composition } from '@basemaps/tiler';
|
|
5
|
-
import o from 'ospec';
|
|
6
|
-
import { TileEtag } from '../routes/tile.etag.js';
|
|
7
|
-
|
|
8
|
-
o.spec('TileCacheKey', () => {
|
|
9
|
-
const oldRenderId = TileEtag.RenderId;
|
|
10
|
-
|
|
11
|
-
const xyzData: TileDataXyz = {
|
|
12
|
-
x: 0,
|
|
13
|
-
y: 0,
|
|
14
|
-
z: 0,
|
|
15
|
-
tileMatrix: GoogleTms,
|
|
16
|
-
name: 'foo',
|
|
17
|
-
ext: ImageFormat.Png,
|
|
18
|
-
type: TileType.Tile,
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
o.afterEach(() => {
|
|
22
|
-
TileEtag.RenderId = oldRenderId;
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
o('should generate a cachekey', async () => {
|
|
26
|
-
const tiff = await TestTiff.Google.init();
|
|
27
|
-
const comp: Composition = {
|
|
28
|
-
tiff,
|
|
29
|
-
source: {
|
|
30
|
-
x: 0,
|
|
31
|
-
y: 0,
|
|
32
|
-
imageId: 0,
|
|
33
|
-
width: 512,
|
|
34
|
-
height: 512,
|
|
35
|
-
},
|
|
36
|
-
x: 5,
|
|
37
|
-
y: 5,
|
|
38
|
-
};
|
|
39
|
-
const firstKey = TileEtag.generate([comp], xyzData);
|
|
40
|
-
o(firstKey).equals('8eJ7XnUeEGBI2d7mfAaK5o8KbUc0+CVaIoPzqCvkoDk=');
|
|
41
|
-
|
|
42
|
-
// Different layers should generate different keys
|
|
43
|
-
o(TileEtag.generate([comp, comp], xyzData)).notEquals(firstKey);
|
|
44
|
-
|
|
45
|
-
// Different projections should generate different keys
|
|
46
|
-
xyzData.tileMatrix = Nztm2000Tms;
|
|
47
|
-
o(TileEtag.generate([comp], xyzData)).notEquals(firstKey);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
o('should change if the renderId changes', () => {
|
|
51
|
-
const keyA = TileEtag.generate([], { tileMatrix: {} } as any);
|
|
52
|
-
TileEtag.RenderId = 2;
|
|
53
|
-
const KeyB = TileEtag.generate([], { tileMatrix: {} } as any);
|
|
54
|
-
o(keyA).notEquals(KeyB);
|
|
55
|
-
});
|
|
56
|
-
});
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { ConfigImagery, ConfigTileSetRaster, TileSetType } from '@basemaps/config';
|
|
2
|
-
import { GoogleTms } from '@basemaps/geo';
|
|
3
|
-
import o from 'ospec';
|
|
4
|
-
import sinon from 'sinon';
|
|
5
|
-
import { TileSets } from '../tile.set.cache.js';
|
|
6
|
-
import { TileSetRaster } from '../tile.set.raster.js';
|
|
7
|
-
const sandbox = sinon.createSandbox();
|
|
8
|
-
o.spec('TileSetCache', () => {
|
|
9
|
-
const imageOne = {
|
|
10
|
-
id: 'im_id1',
|
|
11
|
-
name: 'tasman_rural_2018-19_0-3m',
|
|
12
|
-
bounds: { x: 123, y: 456, width: 200, height: 300 },
|
|
13
|
-
files: [{ name: 'foo', x: 123, y: 456, width: 200, height: 300 }],
|
|
14
|
-
uri: 's3://foo/bar',
|
|
15
|
-
} as ConfigImagery;
|
|
16
|
-
|
|
17
|
-
const imgMap = new Map<string, ConfigImagery>();
|
|
18
|
-
imgMap.set(imageOne.id, imageOne);
|
|
19
|
-
|
|
20
|
-
o.afterEach(() => {
|
|
21
|
-
TileSets.cache.clear();
|
|
22
|
-
sandbox.restore();
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
o.spec('loadTileSet', () => {
|
|
26
|
-
o('load individual set', async () => {
|
|
27
|
-
TileSets.add(new TileSetRaster('aerial@head', GoogleTms));
|
|
28
|
-
|
|
29
|
-
const parentTileSet = await TileSets.get('aerial@head', GoogleTms);
|
|
30
|
-
if (parentTileSet == null || parentTileSet.type === TileSetType.Vector) throw new Error('null parentTileSet');
|
|
31
|
-
parentTileSet.imagery = imgMap;
|
|
32
|
-
parentTileSet.tileSet = {
|
|
33
|
-
name: 'parent',
|
|
34
|
-
title: 'parent aerial title',
|
|
35
|
-
background: { r: 200, g: 50, b: 100, alpha: 0.5 },
|
|
36
|
-
} as ConfigTileSetRaster;
|
|
37
|
-
|
|
38
|
-
const subTileSet = await TileSets.get('aerial@head:tasman_rural_2018-19_0-3m', GoogleTms);
|
|
39
|
-
if (subTileSet == null || subTileSet.type === TileSetType.Vector) throw new Error('null subTileSet');
|
|
40
|
-
|
|
41
|
-
o(subTileSet.title).equals('parent aerial title Tasman rural 2018-19 0.3m');
|
|
42
|
-
o(subTileSet.fullName).equals('aerial@head:tasman_rural_2018-19_0-3m');
|
|
43
|
-
o([...subTileSet.imagery.values()]).deepEquals([imageOne]);
|
|
44
|
-
const [firstLayer] = subTileSet.tileSet.layers;
|
|
45
|
-
o(firstLayer).deepEquals({
|
|
46
|
-
name: firstLayer.name,
|
|
47
|
-
[3857]: 'im_id1',
|
|
48
|
-
minZoom: 0,
|
|
49
|
-
maxZoom: 100,
|
|
50
|
-
});
|
|
51
|
-
o(subTileSet.tileSet.background).equals(undefined);
|
|
52
|
-
|
|
53
|
-
o(parentTileSet.tileSet.background).deepEquals({ r: 200, g: 50, b: 100, alpha: 0.5 });
|
|
54
|
-
|
|
55
|
-
const noTiffs = subTileSet.getTiffsForTile({ x: 0, y: 0, z: 1 });
|
|
56
|
-
o(noTiffs).deepEquals([]);
|
|
57
|
-
|
|
58
|
-
const aTiff = subTileSet.getTiffsForTile({ x: 0, y: 0, z: 0 });
|
|
59
|
-
o(aTiff.length).equals(1);
|
|
60
|
-
o(aTiff[0].source.uri).equals('s3://foo/bar/foo.tiff');
|
|
61
|
-
|
|
62
|
-
TileSets.cache.delete(subTileSet.id);
|
|
63
|
-
delete parentTileSet.tileSet.title;
|
|
64
|
-
const subTileSetB = await TileSets.get('aerial@head:tasman_rural_2018-19_0-3m', GoogleTms);
|
|
65
|
-
if (subTileSetB == null || subTileSetB.type === TileSetType.Vector) throw new Error('null subTileSetB');
|
|
66
|
-
o(subTileSetB.title).equals('parent Tasman rural 2018-19 0.3m');
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
o('should not throw if child does not exist', async () => {
|
|
70
|
-
TileSets.add(new TileSetRaster('aerial@head', GoogleTms));
|
|
71
|
-
|
|
72
|
-
const parentTileSet = await TileSets.get('aerial@head', GoogleTms);
|
|
73
|
-
if (parentTileSet == null || parentTileSet.type === TileSetType.Vector) throw new Error('null parentTileSet');
|
|
74
|
-
parentTileSet.imagery = imgMap;
|
|
75
|
-
|
|
76
|
-
const subTileSet = await TileSets.get('aerial@head:fake', GoogleTms);
|
|
77
|
-
o(subTileSet).equals(null);
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
});
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { GoogleTms, Nztm2000Tms } from '@basemaps/geo';
|
|
2
|
-
import o from 'ospec';
|
|
3
|
-
import { TileSetRaster } from '../tile.set.raster.js';
|
|
4
|
-
|
|
5
|
-
o.spec('tile.set', () => {
|
|
6
|
-
o('extent', () => {
|
|
7
|
-
o(new TileSetRaster('google', GoogleTms).extent.toBbox()).deepEquals([
|
|
8
|
-
-20037508.3427892, -20037508.3427892, 20037508.3427892, 20037508.3427892,
|
|
9
|
-
]);
|
|
10
|
-
o(new TileSetRaster('nztm', Nztm2000Tms).extent.toBbox()).deepEquals([274000, 3087000, 3327000, 7173000]);
|
|
11
|
-
});
|
|
12
|
-
});
|
|
@@ -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
|
-
}
|