@basemaps/lambda-tiler 6.43.0 → 6.45.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 +25 -0
- package/build/cli/render.preview.d.ts +2 -0
- package/build/cli/render.preview.d.ts.map +1 -0
- package/build/cli/render.preview.js +38 -0
- package/build/cli/render.preview.js.map +1 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js +6 -0
- package/build/index.js.map +1 -1
- package/build/routes/__tests__/preview.index.test.d.ts +2 -0
- package/build/routes/__tests__/preview.index.test.d.ts.map +1 -0
- package/build/routes/__tests__/preview.index.test.js +109 -0
- package/build/routes/__tests__/preview.index.test.js.map +1 -0
- package/build/routes/preview.d.ts +58 -0
- package/build/routes/preview.d.ts.map +1 -0
- package/build/routes/preview.index.d.ts +23 -0
- package/build/routes/preview.index.d.ts.map +1 -0
- package/build/routes/preview.index.js +100 -0
- package/build/routes/preview.index.js.map +1 -0
- package/build/routes/preview.js +159 -0
- package/build/routes/preview.js.map +1 -0
- package/build/routes/tile.xyz.raster.d.ts +15 -0
- package/build/routes/tile.xyz.raster.d.ts.map +1 -1
- package/build/routes/tile.xyz.raster.js +45 -24
- package/build/routes/tile.xyz.raster.js.map +1 -1
- package/build/util/validate.d.ts +3 -1
- package/build/util/validate.d.ts.map +1 -1
- package/build/util/validate.js +10 -0
- package/build/util/validate.js.map +1 -1
- package/bundle.sh +1 -1
- package/package.json +8 -8
- package/src/cli/render.preview.ts +44 -0
- package/src/index.ts +7 -0
- package/src/routes/__tests__/preview.index.test.ts +136 -0
- package/src/routes/preview.index.ts +122 -0
- package/src/routes/preview.ts +234 -0
- package/src/routes/tile.xyz.raster.ts +53 -28
- package/src/util/validate.ts +10 -1
- package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,31 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [6.45.0](https://github.com/linz/basemaps/compare/v6.44.0...v6.45.0) (2023-09-18)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **lambda-tiler:** generate previews from config urls too ([#2937](https://github.com/linz/basemaps/issues/2937)) ([ebe499f](https://github.com/linz/basemaps/commit/ebe499fc81ab31a0f1f45ac0ee7262a9b66431e9))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# [6.44.0](https://github.com/linz/basemaps/compare/v6.43.0...v6.44.0) (2023-09-05)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
* **lambda-tiler:** use the same checker background that the landing does for previews BM-264 ([#2929](https://github.com/linz/basemaps/issues/2929)) ([9318588](https://github.com/linz/basemaps/commit/9318588bd929b6f41d10217138726331fa8115b2))
|
|
23
|
+
* add og:image preview to all basemaps links BM-264 ([#2925](https://github.com/linz/basemaps/issues/2925)) ([de00528](https://github.com/linz/basemaps/commit/de005285eac0c2f5e2c83c8eeaa61aafeff8edde))
|
|
24
|
+
* **lambda-tiler:** create preview images for og:image BM-264 ([#2921](https://github.com/linz/basemaps/issues/2921)) ([a074cc4](https://github.com/linz/basemaps/commit/a074cc45b40e35d5a593380f067f4932ef9e8da4))
|
|
25
|
+
* **lambda-tiler:** try arm based lambdas ([#2910](https://github.com/linz/basemaps/issues/2910)) ([e5bd68d](https://github.com/linz/basemaps/commit/e5bd68df37f487c4cc543c69fbedc66f13c5fdc0))
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
6
31
|
# [6.43.0](https://github.com/linz/basemaps/compare/v6.42.1...v6.43.0) (2023-08-22)
|
|
7
32
|
|
|
8
33
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.preview.d.ts","sourceRoot":"","sources":["../../src/cli/render.preview.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ConfigProviderMemory } from '@basemaps/config';
|
|
2
|
+
import { initConfigFromUrls } from '@basemaps/config/build/json/tiff.config.js';
|
|
3
|
+
import { ImageFormat, TileMatrixSets } from '@basemaps/geo';
|
|
4
|
+
import { LogConfig, setDefaultConfig } from '@basemaps/shared';
|
|
5
|
+
import { fsa } from '@chunkd/fs';
|
|
6
|
+
import { LambdaUrlRequest } from '@linzjs/lambda';
|
|
7
|
+
import { pathToFileURL } from 'url';
|
|
8
|
+
import { renderPreview } from '../routes/preview.js';
|
|
9
|
+
const target = pathToFileURL(`/home/blacha/tmp/basemaps/bm-724/test-north-island_20230220_10m/`);
|
|
10
|
+
const location = { lat: -39.0852555, lon: 177.3998405 };
|
|
11
|
+
const z = 12;
|
|
12
|
+
const outputFormat = ImageFormat.Webp;
|
|
13
|
+
let tileMatrix = null;
|
|
14
|
+
async function main() {
|
|
15
|
+
const log = LogConfig.get();
|
|
16
|
+
const provider = new ConfigProviderMemory();
|
|
17
|
+
setDefaultConfig(provider);
|
|
18
|
+
const { tileSet, imagery } = await initConfigFromUrls(provider, [target]);
|
|
19
|
+
if (tileSet.layers.length === 0)
|
|
20
|
+
throw new Error('No imagery found in path: ' + target);
|
|
21
|
+
log.info({ tileSet: tileSet.name, layers: tileSet.layers.length }, 'TileSet:Loaded');
|
|
22
|
+
for (const im of imagery) {
|
|
23
|
+
log.info({ url: im.uri, title: im.title, tileMatrix: im.tileMatrix, files: im.files.length }, 'Imagery:Loaded');
|
|
24
|
+
if (tileMatrix == null) {
|
|
25
|
+
tileMatrix = TileMatrixSets.find(im.tileMatrix);
|
|
26
|
+
log.info({ tileMatrix: im.tileMatrix }, 'Imagery:TileMatrix:Set');
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (tileMatrix == null)
|
|
30
|
+
throw new Error('No tileMatrix found');
|
|
31
|
+
const req = new LambdaUrlRequest({ headers: {} }, {}, LogConfig.get());
|
|
32
|
+
const res = await renderPreview(req, { tileMatrix, tileSet, location, z, outputFormat });
|
|
33
|
+
const previewFile = `./z${z}_${location.lon}_${location.lat}.${outputFormat}`;
|
|
34
|
+
await fsa.write(previewFile, Buffer.from(res.body, 'base64'));
|
|
35
|
+
log.info({ path: previewFile }, 'Tile:Write');
|
|
36
|
+
}
|
|
37
|
+
main();
|
|
38
|
+
//# sourceMappingURL=render.preview.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.preview.js","sourceRoot":"","sources":["../../src/cli/render.preview.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,4CAA4C,CAAC;AAChF,OAAO,EAAE,WAAW,EAAiB,cAAc,EAAE,MAAM,eAAe,CAAC;AAC3E,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,EAAqB,gBAAgB,EAAY,MAAM,gBAAgB,CAAC;AAE/E,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,MAAM,MAAM,GAAG,aAAa,CAAC,kEAAkE,CAAC,CAAC;AACjG,MAAM,QAAQ,GAAG,EAAE,GAAG,EAAE,CAAC,UAAU,EAAE,GAAG,EAAE,WAAW,EAAE,CAAC;AACxD,MAAM,CAAC,GAAG,EAAE,CAAC;AAEb,MAAM,YAAY,GAAG,WAAW,CAAC,IAAI,CAAC;AACtC,IAAI,UAAU,GAAyB,IAAI,CAAC;AAE5C,KAAK,UAAU,IAAI;IACjB,MAAM,GAAG,GAAG,SAAS,CAAC,GAAG,EAAE,CAAC;IAC5B,MAAM,QAAQ,GAAG,IAAI,oBA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E,YAAY,EAAE,CAAC,CAAC;IACzF,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,QAAQ,CAAC,GAAG,IAAI,QAAQ,CAAC,GAAG,IAAI,YAAY,EAAE,CAAC;IAC9E,MAAM,GAAG,CAAC,KAAK,CAAC,WAAW,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC;IAC9D,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,EAAE,YAAY,CAAC,CAAC;AAChD,CAAC;AAED,IAAI,EAAE,CAAC"}
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAuBA,eAAO,MAAM,OAAO,uRAA2B,CAAC"}
|
package/build/index.js
CHANGED
|
@@ -18,6 +18,8 @@ import { versionGet } from './routes/version.js';
|
|
|
18
18
|
import { NotFound, OkResponse } from './util/response.js';
|
|
19
19
|
import { CoSources } from './util/source.cache.js';
|
|
20
20
|
import { St } from './util/source.tracer.js';
|
|
21
|
+
import { tilePreviewGet } from './routes/preview.js';
|
|
22
|
+
import { previewIndexGet } from './routes/preview.index.js';
|
|
21
23
|
export const handler = lf.http(LogConfig.get());
|
|
22
24
|
/** If the request takes too long, respond with a 408 timeout when there is approx 1 second remaining */
|
|
23
25
|
handler.router.timeoutEarlyMs = 1000;
|
|
@@ -77,6 +79,10 @@ handler.router.get('/v1/tiles/:tileSet/:tileMatrix/style/:styleName.json', style
|
|
|
77
79
|
handler.router.get('/v1/tiles/:tileSet/:tileMatrix/tile.json', tileJsonGet);
|
|
78
80
|
// Tiles
|
|
79
81
|
handler.router.get('/v1/tiles/:tileSet/:tileMatrix/:z/:x/:y.:tileType', tileXyzGet);
|
|
82
|
+
// Preview
|
|
83
|
+
handler.router.get('/v1/preview/:tileSet/:tileMatrix/:z/:lon/:lat', tilePreviewGet);
|
|
84
|
+
handler.router.get('/v1/@:location', previewIndexGet);
|
|
85
|
+
handler.router.get('/@:location', previewIndexGet);
|
|
80
86
|
// Attribution
|
|
81
87
|
handler.router.get('/v1/tiles/:tileSet/:tileMatrix/attribution.json', tileAttributionGet);
|
|
82
88
|
handler.router.get('/v1/attribution/:tileSet/:tileMatrix/summary.json', tileAttributionGet);
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC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AM,CAAC,GAAG,CAAC,qDAAqD,EAAE,mBAAmB,CAAC,CAAC;AAC/F,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,yCAAyC,EAAE,mBAAmB,CAAC,CAAC;AACnF,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,gCAAgC,EAAE,mBAAmB,CAAC,CAAC;AAE1E,gBAAgB;AAChB,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,oDAAoD,EAAE,mBAAmB,CAAC,CAAC;AAC9F,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,oDAAoD,EAAE,UAAU,CAAC,CAAC;AACtF,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,8DAA8D,EAAE,kBAAkB,CAAC,CAAC;AACvG,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,sBAAsB,EAAE,aAAa,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preview.index.test.d.ts","sourceRoot":"","sources":["../../../src/routes/__tests__/preview.index.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { Env, LogConfig, V, fsa } from '@basemaps/shared';
|
|
2
|
+
import { LambdaAlbRequest } from '@linzjs/lambda';
|
|
3
|
+
import o from 'ospec';
|
|
4
|
+
import { loadAndServeIndexHtml, previewIndexGet } from '../preview.index.js';
|
|
5
|
+
import { LocationUrl } from '@basemaps/geo';
|
|
6
|
+
import { FsMemory } from '@chunkd/source-memory';
|
|
7
|
+
import { ConfigProviderMemory } from '@basemaps/config';
|
|
8
|
+
import { FakeData } from '../../__tests__/config.data.js';
|
|
9
|
+
o.spec('/@*', async () => {
|
|
10
|
+
o.specTimeout(1000);
|
|
11
|
+
const baseRequest = {
|
|
12
|
+
requestContext: null,
|
|
13
|
+
httpMethod: 'get',
|
|
14
|
+
path: '/@-41.8900012,174.0492432,z5',
|
|
15
|
+
body: null,
|
|
16
|
+
isBase64Encoded: false,
|
|
17
|
+
};
|
|
18
|
+
const fsMem = new FsMemory();
|
|
19
|
+
let lastLocation;
|
|
20
|
+
o.beforeEach(() => {
|
|
21
|
+
fsa.register('memory://', fsMem);
|
|
22
|
+
lastLocation = process.env[Env.StaticAssetLocation];
|
|
23
|
+
});
|
|
24
|
+
o.afterEach(() => {
|
|
25
|
+
if (lastLocation == null)
|
|
26
|
+
delete process.env[Env.StaticAssetLocation];
|
|
27
|
+
else
|
|
28
|
+
process.env[Env.StaticAssetLocation] = lastLocation;
|
|
29
|
+
});
|
|
30
|
+
o('Should redirect on failure to load', async () => {
|
|
31
|
+
const ctx = new LambdaAlbRequest(baseRequest, {}, LogConfig.get());
|
|
32
|
+
const res = await loadAndServeIndexHtml(ctx);
|
|
33
|
+
o(res.status).equals(302);
|
|
34
|
+
o(res.header('location')).equals('/?');
|
|
35
|
+
});
|
|
36
|
+
o('Should redirect with querystring on failure to load', async () => {
|
|
37
|
+
const evt = { ...baseRequest, queryStringParameters: { config: 'config-latest.json' } };
|
|
38
|
+
const ctx = new LambdaAlbRequest(evt, {}, LogConfig.get());
|
|
39
|
+
const res = await loadAndServeIndexHtml(ctx);
|
|
40
|
+
o(res.status).equals(302);
|
|
41
|
+
o(res.header('location')).equals('/?config=config-latest.json');
|
|
42
|
+
});
|
|
43
|
+
o('Should redirect with querystring and location on failure to load', async () => {
|
|
44
|
+
const evt = { ...baseRequest, queryStringParameters: { config: 'config-latest.json' } };
|
|
45
|
+
const loc = LocationUrl.fromSlug(evt.path);
|
|
46
|
+
const ctx = new LambdaAlbRequest(evt, {}, LogConfig.get());
|
|
47
|
+
const res = await loadAndServeIndexHtml(ctx, loc);
|
|
48
|
+
o(res.status).equals(302);
|
|
49
|
+
o(res.header('location')).equals('/?config=config-latest.json#@-41.8900012,174.0492432,z5');
|
|
50
|
+
});
|
|
51
|
+
o('should redirect on failure to load index.html', async () => {
|
|
52
|
+
const ctx = new LambdaAlbRequest(baseRequest, {}, LogConfig.get());
|
|
53
|
+
process.env[Env.StaticAssetLocation] = 'memory://assets/';
|
|
54
|
+
const res = await loadAndServeIndexHtml(ctx);
|
|
55
|
+
o(res.status).equals(302);
|
|
56
|
+
});
|
|
57
|
+
o('should redirect with new tags!', async () => {
|
|
58
|
+
var _a, _b;
|
|
59
|
+
const ctx = new LambdaAlbRequest(baseRequest, {}, LogConfig.get());
|
|
60
|
+
process.env[Env.StaticAssetLocation] = 'memory://assets/';
|
|
61
|
+
const indexHtml = V('html', [
|
|
62
|
+
V('head', [
|
|
63
|
+
V('meta', { property: 'og:title', content: 'LINZ Basemaps' }),
|
|
64
|
+
V('meta', { property: 'og:image', content: '/basemaps-card.jepg' }),
|
|
65
|
+
V('meta', { name: 'viewport' }),
|
|
66
|
+
]),
|
|
67
|
+
]).toString();
|
|
68
|
+
await fsa.write('memory://assets/index.html', indexHtml);
|
|
69
|
+
// Pass back the body un altered
|
|
70
|
+
const res = await loadAndServeIndexHtml(ctx);
|
|
71
|
+
o((_a = getBody(res)) === null || _a === void 0 ? void 0 : _a.toString()).equals(indexHtml);
|
|
72
|
+
// Replace og:title with a <fake tag />
|
|
73
|
+
const resB = await loadAndServeIndexHtml(ctx, null, new Map([['og:title', '<fake tag />']]));
|
|
74
|
+
o((_b = getBody(resB)) === null || _b === void 0 ? void 0 : _b.toString().includes('<fake tag />')).equals(true);
|
|
75
|
+
});
|
|
76
|
+
o('should include config url', async () => {
|
|
77
|
+
var _a;
|
|
78
|
+
const ctx = new LambdaAlbRequest({
|
|
79
|
+
...baseRequest,
|
|
80
|
+
queryStringParameters: { config: 'memory://linz-basemaps/config-latest.json', i: 'imagery-name' },
|
|
81
|
+
}, {}, LogConfig.get());
|
|
82
|
+
ctx.params = { location: '@-41.8900012,174.0492432,z5' };
|
|
83
|
+
// Create a fake config to use
|
|
84
|
+
const expectedConfig = new ConfigProviderMemory();
|
|
85
|
+
expectedConfig.put(FakeData.tileSetRaster('imagery-name'));
|
|
86
|
+
await fsa.write('memory://linz-basemaps/config-latest.json', JSON.stringify(expectedConfig.toJson()));
|
|
87
|
+
process.env[Env.StaticAssetLocation] = 'memory://assets/';
|
|
88
|
+
const indexHtml = V('html', [
|
|
89
|
+
V('head', [
|
|
90
|
+
V('meta', { property: 'og:title', content: 'LINZ Basemaps' }),
|
|
91
|
+
V('meta', { property: 'og:image', content: '/basemaps-card.jepg' }),
|
|
92
|
+
V('meta', { name: 'viewport' }),
|
|
93
|
+
]),
|
|
94
|
+
]).toString();
|
|
95
|
+
await fsa.write('memory://assets/index.html', indexHtml);
|
|
96
|
+
const res = await previewIndexGet(ctx);
|
|
97
|
+
o(res.status).equals(200);
|
|
98
|
+
const ogImage = (_a = getBody(res)) === null || _a === void 0 ? void 0 : _a.toString().split('\n').find((f) => f.includes('og:image'));
|
|
99
|
+
o(ogImage).equals('<meta name="twitter:image" property="og:image" content="/v1/preview/imagery-name/WebMercatorQuad/5/174.0492432/-41.8900012?config=QzX7ZsK6qG6p42wHZaF9dhihsgprX942gAuKwfryknM429iqxdDiRSGu" />');
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
function getBody(res) {
|
|
103
|
+
if (res._body == null)
|
|
104
|
+
return null;
|
|
105
|
+
if (res.isBase64Encoded)
|
|
106
|
+
return Buffer.from(res._body, 'base64');
|
|
107
|
+
return Buffer.from(res._body);
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=preview.index.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preview.index.test.js","sourceRoot":"","sources":["../../../src/routes/__tests__/preview.index.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAyC,MAAM,gBAAgB,CAAC;AAEzF,OAAO,CAAC,MAAM,OAAO,CAAC;AAEtB,OAAO,EAAmB,qBAAqB,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC9F,OAAO,EAAE,WAAW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from '@linzjs/lambda';
|
|
4
|
+
export interface PreviewGet {
|
|
5
|
+
Params: {
|
|
6
|
+
tileSet: string;
|
|
7
|
+
tileMatrix: string;
|
|
8
|
+
lat: string;
|
|
9
|
+
lon: string;
|
|
10
|
+
z: string;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Serve a preview of a imagery set
|
|
15
|
+
*
|
|
16
|
+
* /v1/preview/:tileSet/:tileMatrixSet/:z/:lon/:lat
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* Raster Tile `/v1/preview/aerial/WebMercatorQuad/12/177.3998405/-39.0852555`
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
export declare function tilePreviewGet(req: LambdaHttpRequest<PreviewGet>): Promise<LambdaHttpResponse>;
|
|
23
|
+
interface PreviewRenderContext {
|
|
24
|
+
/** Imagery to use */
|
|
25
|
+
tileSet: ConfigTileSetRaster;
|
|
26
|
+
/** output tilematrix to use */
|
|
27
|
+
tileMatrix: TileMatrixSet;
|
|
28
|
+
/** Center point of the preview */
|
|
29
|
+
location: LatLon;
|
|
30
|
+
/** Iamge format to render the preview as */
|
|
31
|
+
outputFormat: ImageFormat;
|
|
32
|
+
/** Zom level to be use, must be a integer */
|
|
33
|
+
z: number;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Render the preview!
|
|
37
|
+
*
|
|
38
|
+
* All the parameter validation is done in {@link tilePreviewGet} this function expects everything to align
|
|
39
|
+
*
|
|
40
|
+
* @returns 304 not modified if the ETag matches or 200 ok with the content of the image
|
|
41
|
+
*/
|
|
42
|
+
export declare function renderPreview(req: LambdaHttpRequest, ctx: PreviewRenderContext): Promise<LambdaHttpResponse>;
|
|
43
|
+
export interface CheckerBoard {
|
|
44
|
+
/** Output image width in pixels */
|
|
45
|
+
width: number;
|
|
46
|
+
/** Output image height in pixels */
|
|
47
|
+
height: number;
|
|
48
|
+
colors: {
|
|
49
|
+
/** Color of the checker board eg 0xef */
|
|
50
|
+
fill: number;
|
|
51
|
+
/** Color of the background eg 0xff */
|
|
52
|
+
background: number;
|
|
53
|
+
};
|
|
54
|
+
/** Size of the checkers */
|
|
55
|
+
size: number;
|
|
56
|
+
}
|
|
57
|
+
export {};
|
|
58
|
+
//# sourceMappingURL=preview.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preview.d.ts","sourceRoot":"","sources":["../../src/routes/preview.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAU,WAAW,EAAE,MAAM,EAAc,aAAa,EAAE,MAAM,eAAe,CAAC;AAGvF,OAAO,EAAc,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAQnF,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE;QACN,OAAO,EAAE,MAAM,CAAC;QAChB,UAAU,EAAE,MAAM,CAAC;QACnB,GAAG,EAAE,MAAM,CAAC;QACZ,GAAG,EAAE,MAAM,CAAC;QACZ,CAAC,EAAE,MAAM,CAAC;KACX,CAAC;CACH;AAWD;;;;;;;;GAQG;AACH,wBAAsB,cAAc,CAAC,GAAG,EAAE,iBAAiB,CAAC,UAAU,CAAC,GAAG,OAAO,CAAC,kBAAkB,CAAC,CA2BpG;AAED,UAAU,oBAAoB;IAC5B,qBAAqB;IACrB,OAAO,EAAE,mBAAmB,CAAC;IAC7B,+BAA+B;IAC/B,UAAU,EAAE,aAAa,CAAC;IAC1B,kCAAkC;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB,4CAA4C;IAC5C,YAAY,EAAE,WAAW,CAAC;IAC1B,6CAA6C;IAC7C,CAAC,EAAE,MAAM,CAAC;CACX;AACD;;;;;;GAMG;AACH,wBAAsB,aAAa,CAAC,GAAG,EAAE,iBAAiB,EAAE,GAAG,EAAE,oBAAoB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CA0ElH;AAeD,MAAM,WAAW,YAAY;IAC3B,mCAAmC;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,oCAAoC;IACpC,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE;QACN,yCAAyC;QACzC,IAAI,EAAE,MAAM,CAAC;QACb,sCAAsC;QACtC,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;IACF,2BAA2B;IAC3B,IAAI,EAAE,MAAM,CAAC;CACd"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { LonLatZoom } from '@basemaps/geo';
|
|
2
|
+
import { LambdaHttpRequest, LambdaHttpResponse } from '@linzjs/lambda';
|
|
3
|
+
export interface PreviewIndexGet {
|
|
4
|
+
Params: {
|
|
5
|
+
location: string;
|
|
6
|
+
};
|
|
7
|
+
Query: {
|
|
8
|
+
config?: string;
|
|
9
|
+
style?: string;
|
|
10
|
+
tileMatrix?: string;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Load the `index.html` from the static bucket and replace `<meta />` tags with the preview open graph tags
|
|
15
|
+
*
|
|
16
|
+
* @param loc location of the request if valid
|
|
17
|
+
* @param tags tags to replace if they exist
|
|
18
|
+
*
|
|
19
|
+
* @returns response containing the output HTML
|
|
20
|
+
*/
|
|
21
|
+
export declare function loadAndServeIndexHtml(req: LambdaHttpRequest, loc?: LonLatZoom | null, tags?: Map<string, string>): Promise<LambdaHttpResponse>;
|
|
22
|
+
export declare function previewIndexGet(req: LambdaHttpRequest<PreviewIndexGet>): Promise<LambdaHttpResponse>;
|
|
23
|
+
//# sourceMappingURL=preview.index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preview.index.d.ts","sourceRoot":"","sources":["../../src/routes/preview.index.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,UAAU,EAAkB,MAAM,eAAe,CAAC;AACnF,OAAO,EAAc,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAUnF,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE;QACN,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC;IACF,KAAK,EAAE;QACL,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB,CAAC;CACH;AAED;;;;;;;GAOG;AACH,wBAAsB,qBAAqB,CACzC,GAAG,EAAE,iBAAiB,EACtB,GAAG,CAAC,EAAE,UAAU,GAAG,IAAI,EACvB,IAAI,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GACzB,OAAO,CAAC,kBAAkB,CAAC,CA8C7B;AAED,wBAAsB,eAAe,CAAC,GAAG,EAAE,iBAAiB,CAAC,eAAe,CAAC,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAuC1G"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { GoogleTms, LocationUrl, TileMatrixSets } from '@basemaps/geo';
|
|
2
|
+
import { HttpHeader, LambdaHttpResponse } from '@linzjs/lambda';
|
|
3
|
+
import { ConfigLoader } from '../util/config.loader.js';
|
|
4
|
+
import { Env, fsa } from '@basemaps/shared';
|
|
5
|
+
import { isGzip } from '../util/cotar.serve.js';
|
|
6
|
+
import { gunzip } from 'node:zlib';
|
|
7
|
+
import { promisify } from 'node:util';
|
|
8
|
+
import { Etag } from '../util/etag.js';
|
|
9
|
+
const gunzipP = promisify(gunzip);
|
|
10
|
+
/**
|
|
11
|
+
* Load the `index.html` from the static bucket and replace `<meta />` tags with the preview open graph tags
|
|
12
|
+
*
|
|
13
|
+
* @param loc location of the request if valid
|
|
14
|
+
* @param tags tags to replace if they exist
|
|
15
|
+
*
|
|
16
|
+
* @returns response containing the output HTML
|
|
17
|
+
*/
|
|
18
|
+
export async function loadAndServeIndexHtml(req, loc, tags) {
|
|
19
|
+
const locUrl = loc ? `#` + LocationUrl.toSlug(loc) : '';
|
|
20
|
+
// If the static location is given to us replace
|
|
21
|
+
const staticLocation = Env.get(Env.StaticAssetLocation);
|
|
22
|
+
// No static assets defined, just redirect back to the main page
|
|
23
|
+
if (staticLocation == null) {
|
|
24
|
+
return new LambdaHttpResponse(302, 'Invalid index.html', {
|
|
25
|
+
location: '/?' + req.query.toString() + locUrl,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
let indexHtml = await fsa.read(fsa.join(staticLocation, 'index.html'));
|
|
30
|
+
if (isGzip(indexHtml))
|
|
31
|
+
indexHtml = await gunzipP(indexHtml);
|
|
32
|
+
const res = new LambdaHttpResponse(200, 'ok');
|
|
33
|
+
// These index.html documents are refreshed frequently so only let them be cached for short durations
|
|
34
|
+
res.header(HttpHeader.CacheControl, 'public, max-age=30, stale-while-revalidate=60');
|
|
35
|
+
if (tags == null) {
|
|
36
|
+
res.header(HttpHeader.ETag, Etag.key(indexHtml));
|
|
37
|
+
res.buffer(indexHtml, `text/html; charset=utf-8`);
|
|
38
|
+
return res;
|
|
39
|
+
}
|
|
40
|
+
// Replace open graph tags
|
|
41
|
+
const output = String(indexHtml)
|
|
42
|
+
.split('\n')
|
|
43
|
+
.map((f) => {
|
|
44
|
+
for (const [key, value] of tags.entries()) {
|
|
45
|
+
if (f.includes(key))
|
|
46
|
+
return value;
|
|
47
|
+
}
|
|
48
|
+
return f;
|
|
49
|
+
});
|
|
50
|
+
const outHtml = output.join('\n');
|
|
51
|
+
res.header(HttpHeader.ETag, Etag.key(outHtml));
|
|
52
|
+
res.buffer(outHtml, `text/html; charset=utf-8`);
|
|
53
|
+
return res;
|
|
54
|
+
}
|
|
55
|
+
catch (e) {
|
|
56
|
+
req.log.fatal({ e }, 'Index:Failed');
|
|
57
|
+
// If we fail to read transform the index, just redirect the user to the actual index.html
|
|
58
|
+
return new LambdaHttpResponse(302, 'Failed to render index.html', {
|
|
59
|
+
location: '/?' + req.query.toString() + locUrl,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
export async function previewIndexGet(req) {
|
|
64
|
+
const config = await ConfigLoader.load(req);
|
|
65
|
+
const loc = LocationUrl.fromSlug(req.params.location);
|
|
66
|
+
if (loc == null)
|
|
67
|
+
return loadAndServeIndexHtml(req);
|
|
68
|
+
const query = LocationUrl.parseQuery(req.query);
|
|
69
|
+
req.timer.start('tileset:load');
|
|
70
|
+
const tileSet = await config.TileSet.get(config.TileSet.id(query.style));
|
|
71
|
+
req.timer.end('tileset:load');
|
|
72
|
+
if (tileSet == null)
|
|
73
|
+
return loadAndServeIndexHtml(req, loc);
|
|
74
|
+
if (tileSet.type !== 'raster')
|
|
75
|
+
return loadAndServeIndexHtml(req, loc);
|
|
76
|
+
let tileMatrix = TileMatrixSets.find(query.tileMatrix);
|
|
77
|
+
if (tileMatrix == null)
|
|
78
|
+
tileMatrix = GoogleTms;
|
|
79
|
+
const short = LocationUrl.truncateLatLon(loc);
|
|
80
|
+
const shortLocation = [short.zoom, short.lon, short.lat].join('/');
|
|
81
|
+
const cfg = ConfigLoader.extract(req);
|
|
82
|
+
const queryParams = cfg == null ? '' : `?config=${cfg}`;
|
|
83
|
+
// Include tile matrix name eg "[NZTM2000Quad]" in the title if its not WebMercatorQuad
|
|
84
|
+
const tileMatrixId = tileMatrix.identifier === GoogleTms.identifier ? '' : ` [${tileMatrix.identifier}]`;
|
|
85
|
+
// List of tags to replace in the index.html
|
|
86
|
+
const ogTags = new Map([
|
|
87
|
+
['og:title', `<meta name="twitter:title" property="og:title" content="LINZ Basemaps">`],
|
|
88
|
+
// TODO attribution could be used to get exactly what imagery is being looked at.
|
|
89
|
+
[
|
|
90
|
+
'og:description',
|
|
91
|
+
`<meta name="twitter:description" property="og:description" content="${tileSet.title}${tileMatrixId}" />`,
|
|
92
|
+
],
|
|
93
|
+
[
|
|
94
|
+
'og:image',
|
|
95
|
+
`<meta name="twitter:image" property="og:image" content="/v1/preview/${tileSet.name}/${tileMatrix.identifier}/${shortLocation}${queryParams}" />`,
|
|
96
|
+
],
|
|
97
|
+
]);
|
|
98
|
+
return loadAndServeIndexHtml(req, loc, ogTags);
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=preview.index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preview.index.js","sourceRoot":"","sources":["../../src/routes/preview.index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAc,cAAc,EAAE,MAAM,eAAe,CAAC;AACnF,OAAO,EAAE,UAAU,EAAqB,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACnF,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAEvC,MAAM,OAAO,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;AAalC;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,GAAsB,EACtB,GAAuB,EACvB,IAA0B;IAE1B,MAAM,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACxD,gDAAgD;IAChD,MAAM,cAAc,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IACxD,gEAAgE;IAChE,IAAI,cAAc,IAAI,IAAI,EAAE;QAC1B,OAAO,IAAI,kBAAkB,CAAC,GAAG,EAAE,oBAAoB,EAAE;YACvD,QAAQ,EAAE,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,QAAQ,EAAE,GAAG,MA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AI,IAAI;QAAE,UAAU,GAAG,SAAS,CAAC;IAE/C,MAAM,KAAK,GAAG,WAAW,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;IAC9C,MAAM,aAAa,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAEnE,MAAM,GAAG,GAAG,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACtC,MAAM,WAAW,GAAG,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,GAAG,EAAE,CAAC;IAExD,uFAAuF;IACvF,MAAM,YAAY,GAAG,UAAU,CAAC,UAAU,KAAK,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,UAAU,CAAC,UAAU,GAAG,CAAC;IACzG,4CAA4C;IAC5C,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC;QACrB,CAAC,UAAU,EAAE,yEAAyE,CAAC;QACvF,iFAAiF;QACjF;YACE,gBAAgB;YAChB,uEAAuE,OAAO,CAAC,KAAK,GAAG,YAAY,MAAM;SAC1G;QACD;YACE,UAAU;YACV,uEAAuE,OAAO,CAAC,IAAI,IAAI,UAAU,CAAC,UAAU,IAAI,aAAa,GAAG,WAAW,MAAM;SAClJ;KACF,CAAC,CAAC;IAEH,OAAO,qBAAqB,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;AACjD,CAAC"}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { Bounds, ImageFormat, Projection } from '@basemaps/geo';
|
|
2
|
+
import { Tiler } from '@basemaps/tiler';
|
|
3
|
+
import { TileMakerSharp } from '@basemaps/tiler-sharp';
|
|
4
|
+
import { HttpHeader, LambdaHttpResponse } from '@linzjs/lambda';
|
|
5
|
+
import { ConfigLoader } from '../util/config.loader.js';
|
|
6
|
+
import { Etag } from '../util/etag.js';
|
|
7
|
+
import { NotModified } from '../util/response.js';
|
|
8
|
+
import { Validate } from '../util/validate.js';
|
|
9
|
+
import { DefaultResizeKernel, TileXyzRaster, isArchiveTiff } from './tile.xyz.raster.js';
|
|
10
|
+
import sharp from 'sharp';
|
|
11
|
+
const PreviewSize = { width: 1200, height: 630 };
|
|
12
|
+
const TilerSharp = new TileMakerSharp(PreviewSize.width, PreviewSize.height);
|
|
13
|
+
const OutputFormat = ImageFormat.Webp;
|
|
14
|
+
/** Slightly grey color for the checker background */
|
|
15
|
+
const PreviewBackgroundFillColor = 0xef;
|
|
16
|
+
/** Make th e checkered background 30x30px */
|
|
17
|
+
const PreviewBackgroundSizePx = 30;
|
|
18
|
+
/**
|
|
19
|
+
* Serve a preview of a imagery set
|
|
20
|
+
*
|
|
21
|
+
* /v1/preview/:tileSet/:tileMatrixSet/:z/:lon/:lat
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* Raster Tile `/v1/preview/aerial/WebMercatorQuad/12/177.3998405/-39.0852555`
|
|
25
|
+
*
|
|
26
|
+
*/
|
|
27
|
+
export async function tilePreviewGet(req) {
|
|
28
|
+
const tileMatrix = Validate.getTileMatrixSet(req.params.tileMatrix);
|
|
29
|
+
if (tileMatrix == null)
|
|
30
|
+
return new LambdaHttpResponse(404, 'Tile Matrix not found');
|
|
31
|
+
req.set('tileMatrix', tileMatrix.identifier);
|
|
32
|
+
req.set('projection', tileMatrix.projection.code);
|
|
33
|
+
// TODO we should detect the format based off the "Accept" header and maybe default back to webp
|
|
34
|
+
req.set('extension', OutputFormat);
|
|
35
|
+
const location = Validate.getLocation(req.params.lon, req.params.lat);
|
|
36
|
+
if (location == null)
|
|
37
|
+
return new LambdaHttpResponse(404, 'Preview location not found');
|
|
38
|
+
req.set('location', location);
|
|
39
|
+
const z = Math.ceil(parseFloat(req.params.z));
|
|
40
|
+
if (isNaN(z) || z < 0 || z > tileMatrix.maxZoom)
|
|
41
|
+
return new LambdaHttpResponse(404, 'Preview zoom invalid');
|
|
42
|
+
const config = await ConfigLoader.load(req);
|
|
43
|
+
req.timer.start('tileset:load');
|
|
44
|
+
const tileSet = await config.TileSet.get(config.TileSet.id(req.params.tileSet));
|
|
45
|
+
req.timer.end('tileset:load');
|
|
46
|
+
if (tileSet == null)
|
|
47
|
+
return new LambdaHttpResponse(404, 'Tileset not found');
|
|
48
|
+
// Only raster previews are supported
|
|
49
|
+
if (tileSet.type !== 'raster')
|
|
50
|
+
return new LambdaHttpResponse(404, 'Preview invalid tile set type');
|
|
51
|
+
return renderPreview(req, { tileSet, tileMatrix, location, outputFormat: OutputFormat, z });
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Render the preview!
|
|
55
|
+
*
|
|
56
|
+
* All the parameter validation is done in {@link tilePreviewGet} this function expects everything to align
|
|
57
|
+
*
|
|
58
|
+
* @returns 304 not modified if the ETag matches or 200 ok with the content of the image
|
|
59
|
+
*/
|
|
60
|
+
export async function renderPreview(req, ctx) {
|
|
61
|
+
const tileMatrix = ctx.tileMatrix;
|
|
62
|
+
// Convert the input lat/lon into the projected coordinates to make it easier to do math with
|
|
63
|
+
const coords = Projection.get(tileMatrix).fromWgs84([ctx.location.lon, ctx.location.lat]);
|
|
64
|
+
// use the input as the center point, but round it to the closest pixel to make it easier to do math
|
|
65
|
+
const point = tileMatrix.sourceToPixels(coords[0], coords[1], ctx.z);
|
|
66
|
+
const pointCenter = { x: Math.round(point.x), y: Math.round(point.y) };
|
|
67
|
+
// position of the preview in relation to the output screen
|
|
68
|
+
const screenBounds = new Bounds(pointCenter.x - PreviewSize.width / 2, pointCenter.y - PreviewSize.height / 2, PreviewSize.width, PreviewSize.height);
|
|
69
|
+
// Convert the screen bounds back into the source to find the assets we need to render the preview
|
|
70
|
+
const topLeft = tileMatrix.pixelsToSource(screenBounds.x, screenBounds.y, ctx.z);
|
|
71
|
+
const bottomRight = tileMatrix.pixelsToSource(screenBounds.right, screenBounds.bottom, ctx.z);
|
|
72
|
+
const sourceBounds = Bounds.fromBbox([topLeft.x, topLeft.y, bottomRight.x, bottomRight.y]);
|
|
73
|
+
const assetLocations = await TileXyzRaster.getAssetsForBounds(req, ctx.tileSet, tileMatrix, sourceBounds, ctx.z, true);
|
|
74
|
+
const cacheKey = Etag.key(assetLocations);
|
|
75
|
+
if (Etag.isNotModified(req, cacheKey))
|
|
76
|
+
return NotModified();
|
|
77
|
+
const assets = await TileXyzRaster.loadAssets(req, assetLocations);
|
|
78
|
+
const tiler = new Tiler(tileMatrix);
|
|
79
|
+
// Figure out what tiffs and tiles need to be read and where they are placed on the output image
|
|
80
|
+
const compositions = [];
|
|
81
|
+
for (const asset of assets) {
|
|
82
|
+
// there shouldn't be any Cotar archives in previews but ignore them to be safe
|
|
83
|
+
if (!isArchiveTiff(asset))
|
|
84
|
+
continue;
|
|
85
|
+
const result = tiler.getTiles(asset, screenBounds, ctx.z);
|
|
86
|
+
if (result == null)
|
|
87
|
+
continue;
|
|
88
|
+
compositions.push(...result);
|
|
89
|
+
}
|
|
90
|
+
// Load all the tiff tiles and resize/them into the correct locations
|
|
91
|
+
req.timer.start('compose:overlay');
|
|
92
|
+
const overlays = (await Promise.all(compositions.map((comp) => TilerSharp.composeTileTiff(comp, DefaultResizeKernel))).then((items) => items.filter((f) => f != null)));
|
|
93
|
+
req.timer.end('compose:overlay');
|
|
94
|
+
// Create the output image and render all the individual pieces into them
|
|
95
|
+
const img = getBaseImage(ctx.tileSet.background);
|
|
96
|
+
img.composite(overlays);
|
|
97
|
+
req.timer.start('compose:compress');
|
|
98
|
+
const buf = await TilerSharp.toImage(ctx.outputFormat, img);
|
|
99
|
+
req.timer.end('compose:compress');
|
|
100
|
+
req.set('layersUsed', overlays.length);
|
|
101
|
+
req.set('bytes', buf.byteLength);
|
|
102
|
+
const response = new LambdaHttpResponse(200, 'ok');
|
|
103
|
+
response.header(HttpHeader.ETag, cacheKey);
|
|
104
|
+
response.header(HttpHeader.CacheControl, 'public, max-age=604800, stale-while-revalidate=86400');
|
|
105
|
+
response.buffer(buf, 'image/' + ctx.outputFormat);
|
|
106
|
+
const shortLocation = [ctx.location.lon.toFixed(7), ctx.location.lat.toFixed(7)].join('_');
|
|
107
|
+
const suggestedFileName = `preview_${ctx.tileSet.name}_z${ctx.z}_${shortLocation}.${ctx.outputFormat}`;
|
|
108
|
+
response.header('Content-Disposition', `inline; filename=\"${suggestedFileName}\"`);
|
|
109
|
+
return response;
|
|
110
|
+
}
|
|
111
|
+
function getBaseImage(bg) {
|
|
112
|
+
if (bg == null || bg.alpha === 0) {
|
|
113
|
+
const buf = createCheckerBoard({
|
|
114
|
+
width: PreviewSize.width,
|
|
115
|
+
height: PreviewSize.height,
|
|
116
|
+
colors: { fill: PreviewBackgroundFillColor, background: 0xff },
|
|
117
|
+
size: PreviewBackgroundSizePx,
|
|
118
|
+
});
|
|
119
|
+
return sharp(buf.buffer, { raw: buf.raw });
|
|
120
|
+
}
|
|
121
|
+
return TilerSharp.createImage(bg);
|
|
122
|
+
}
|
|
123
|
+
/** Create a chess/checkerboard background alternating between two colors */
|
|
124
|
+
function createCheckerBoard(ctx) {
|
|
125
|
+
const { width, height, size } = ctx;
|
|
126
|
+
const fillColor = ctx.colors.fill;
|
|
127
|
+
// Create a one band image, which starts off as full white
|
|
128
|
+
const buf = Buffer.alloc(height * width, ctx.colors.background); // 1 band grey buffer;
|
|
129
|
+
// Number of squares to make in x/y directions
|
|
130
|
+
const tileY = height / size;
|
|
131
|
+
const tileX = width / size;
|
|
132
|
+
// Fill in a square at the x/y pixel offsets
|
|
133
|
+
function fillSquare(xOffset, yOffset) {
|
|
134
|
+
for (let y = 0; y < size; y++) {
|
|
135
|
+
const yPx = (yOffset + y) * width;
|
|
136
|
+
for (let x = 0; x < size; x++) {
|
|
137
|
+
const px = yPx + xOffset + x;
|
|
138
|
+
// Actually set the color
|
|
139
|
+
buf[px] = fillColor;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
for (let tX = 0; tX < tileX; tX++) {
|
|
144
|
+
for (let tY = 0; tY < tileY; tY++) {
|
|
145
|
+
const yOffset = tY * size;
|
|
146
|
+
const y2 = tY % 2;
|
|
147
|
+
// Draw every second tile alternating on rows
|
|
148
|
+
const x2 = tX % 2;
|
|
149
|
+
if (x2 === 0 && y2 === 1)
|
|
150
|
+
continue;
|
|
151
|
+
if (x2 === 1 && y2 === 0)
|
|
152
|
+
continue;
|
|
153
|
+
const xOffset = tX * size;
|
|
154
|
+
fillSquare(xOffset, yOffset);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return { buffer: buf, raw: { width, height, channels: 1 } };
|
|
158
|
+
}
|
|
159
|
+
//# sourceMappingURL=preview.js.map
|