@basemaps/lambda-tiler 7.10.0 → 7.12.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 +28 -0
- package/build/index.js +9 -4
- package/build/index.js.map +1 -1
- package/build/routes/__tests__/link.test.d.ts +1 -0
- package/build/routes/__tests__/link.test.js +82 -0
- package/build/routes/__tests__/link.test.js.map +1 -0
- package/build/routes/__tests__/tile.style.json.attribution.test.d.ts +1 -0
- package/build/routes/__tests__/tile.style.json.attribution.test.js +172 -0
- package/build/routes/__tests__/tile.style.json.attribution.test.js.map +1 -0
- package/build/routes/attribution.d.ts +19 -1
- package/build/routes/attribution.js +38 -3
- package/build/routes/attribution.js.map +1 -1
- package/build/routes/link.d.ts +17 -0
- package/build/routes/link.js +42 -0
- package/build/routes/link.js.map +1 -0
- package/build/routes/tile.style.json.d.ts +2 -2
- package/build/routes/tile.style.json.js +12 -4
- package/build/routes/tile.style.json.js.map +1 -1
- package/package.json +9 -9
- package/src/index.ts +10 -4
- package/src/routes/__tests__/link.test.ts +114 -0
- package/src/routes/__tests__/tile.style.json.attribution.test.ts +224 -0
- package/src/routes/attribution.ts +53 -5
- package/src/routes/link.ts +55 -0
- package/src/routes/tile.style.json.ts +15 -4
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { TileSetType } from '@basemaps/config';
|
|
2
|
+
import { Epsg } from '@basemaps/geo';
|
|
3
|
+
import { getPreviewUrl } from '@basemaps/shared';
|
|
4
|
+
import { LambdaHttpRequest, LambdaHttpResponse } from '@linzjs/lambda';
|
|
5
|
+
|
|
6
|
+
import { ConfigLoader } from '../util/config.loader.js';
|
|
7
|
+
|
|
8
|
+
export interface LinkGet {
|
|
9
|
+
Params: {
|
|
10
|
+
tileSet: string;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Redirect the client to a Basemaps URL that is already zoomed to the extent of the tileset's imagery.
|
|
16
|
+
*
|
|
17
|
+
* /v1/link/:tileSet
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* '/v1/link/ashburton-2023-0.1m'
|
|
21
|
+
*
|
|
22
|
+
* @returns on success, 302 redirect response. on failure, 4xx status code response.
|
|
23
|
+
*/
|
|
24
|
+
export async function linkGet(req: LambdaHttpRequest<LinkGet>): Promise<LambdaHttpResponse> {
|
|
25
|
+
const config = await ConfigLoader.load(req);
|
|
26
|
+
|
|
27
|
+
// get tileset
|
|
28
|
+
|
|
29
|
+
req.timer.start('tileset:load');
|
|
30
|
+
const tileSet = await config.TileSet.get(req.params.tileSet);
|
|
31
|
+
req.timer.end('tileset:load');
|
|
32
|
+
|
|
33
|
+
if (tileSet == null) return new LambdaHttpResponse(404, 'Tileset not found');
|
|
34
|
+
|
|
35
|
+
if (tileSet.type !== TileSetType.Raster) return new LambdaHttpResponse(400, 'Tileset must be raster type');
|
|
36
|
+
|
|
37
|
+
// TODO: add support for 'aerial' and 'elevation' multi-layer tilesets
|
|
38
|
+
if (tileSet.layers.length !== 1) return new LambdaHttpResponse(400, 'Too many layers');
|
|
39
|
+
|
|
40
|
+
// get imagery
|
|
41
|
+
|
|
42
|
+
const imageryId = tileSet.layers[0][Epsg.Google.code];
|
|
43
|
+
if (imageryId === undefined) return new LambdaHttpResponse(400, "No imagery for '3857' projection");
|
|
44
|
+
|
|
45
|
+
const imagery = await config.Imagery.get(imageryId);
|
|
46
|
+
if (imagery == null) return new LambdaHttpResponse(400, 'Imagery not found');
|
|
47
|
+
|
|
48
|
+
// do redirect
|
|
49
|
+
|
|
50
|
+
const url = getPreviewUrl({ imagery });
|
|
51
|
+
|
|
52
|
+
return new LambdaHttpResponse(302, 'Redirect to pre-zoomed imagery', {
|
|
53
|
+
location: `/${url.slug}?i=${url.name}`,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
@@ -19,6 +19,7 @@ import { Etag } from '../util/etag.js';
|
|
|
19
19
|
import { convertStyleToNztmStyle } from '../util/nztm.style.js';
|
|
20
20
|
import { NotFound, NotModified } from '../util/response.js';
|
|
21
21
|
import { Validate } from '../util/validate.js';
|
|
22
|
+
import { createTileSetAttribution } from './attribution.js';
|
|
22
23
|
|
|
23
24
|
/**
|
|
24
25
|
* Convert relative URL into a full hostname URL, converting {tileMatrix} into the provided tileMatrix
|
|
@@ -153,12 +154,13 @@ async function ensureTerrain(
|
|
|
153
154
|
* Generate a StyleJSON from a tileset
|
|
154
155
|
* @returns
|
|
155
156
|
*/
|
|
156
|
-
export function tileSetToStyle(
|
|
157
|
+
export async function tileSetToStyle(
|
|
157
158
|
req: LambdaHttpRequest<StyleGet>,
|
|
159
|
+
config: BasemapsConfigProvider,
|
|
158
160
|
tileSet: ConfigTileSetRaster,
|
|
159
161
|
tileMatrix: TileMatrixSet,
|
|
160
162
|
apiKey: string,
|
|
161
|
-
): StyleJson {
|
|
163
|
+
): Promise<StyleJson> {
|
|
162
164
|
// If the style has outputs defined it has a different process for generating the stylejson
|
|
163
165
|
if (tileSet.outputs) return tileSetOutputToStyle(req, tileSet, tileMatrix, apiKey);
|
|
164
166
|
|
|
@@ -175,12 +177,21 @@ export function tileSetToStyle(
|
|
|
175
177
|
(Env.get(Env.PublicUrlBase) ?? '') +
|
|
176
178
|
`/v1/tiles/${tileSet.name}/${tileMatrix.identifier}/{z}/{x}/{y}.${tileFormat}${query}`;
|
|
177
179
|
|
|
180
|
+
const attribution = await createTileSetAttribution(config, tileSet, tileMatrix.projection);
|
|
181
|
+
|
|
178
182
|
const styleId = `basemaps-${tileSet.name}`;
|
|
179
183
|
return {
|
|
180
184
|
id: ConfigId.prefix(ConfigPrefix.Style, tileSet.name),
|
|
181
185
|
name: tileSet.name,
|
|
182
186
|
version: 8,
|
|
183
|
-
sources: {
|
|
187
|
+
sources: {
|
|
188
|
+
[styleId]: {
|
|
189
|
+
type: 'raster',
|
|
190
|
+
tiles: [tileUrl],
|
|
191
|
+
tileSize: 256,
|
|
192
|
+
attribution,
|
|
193
|
+
},
|
|
194
|
+
},
|
|
184
195
|
layers: [{ id: styleId, type: 'raster', source: styleId }],
|
|
185
196
|
};
|
|
186
197
|
}
|
|
@@ -248,7 +259,7 @@ async function generateStyleFromTileSet(
|
|
|
248
259
|
throw new LambdaHttpResponse(400, 'Only raster tile sets can generate style JSON');
|
|
249
260
|
}
|
|
250
261
|
if (tileSet.outputs) return tileSetOutputToStyle(req, tileSet, tileMatrix, apiKey);
|
|
251
|
-
|
|
262
|
+
return tileSetToStyle(req, config, tileSet, tileMatrix, apiKey);
|
|
252
263
|
}
|
|
253
264
|
|
|
254
265
|
export interface StyleGet {
|