@basemaps/lambda-tiler 6.29.0 → 6.32.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (259) hide show
  1. package/CHANGELOG.md +63 -0
  2. package/build/__tests__/config.data.d.ts +11 -0
  3. package/build/__tests__/config.data.d.ts.map +1 -0
  4. package/build/__tests__/config.data.js +112 -0
  5. package/build/__tests__/config.data.js.map +1 -0
  6. package/build/__tests__/index.test.js +5 -14
  7. package/build/__tests__/index.test.js.map +1 -0
  8. package/build/__tests__/tile.style.json.test.js +1 -0
  9. package/build/__tests__/tile.style.json.test.js.map +1 -0
  10. package/build/__tests__/wmts.capability.test.d.ts +1 -1
  11. package/build/__tests__/wmts.capability.test.d.ts.map +1 -1
  12. package/build/__tests__/wmts.capability.test.js +286 -125
  13. package/build/__tests__/wmts.capability.test.js.map +1 -0
  14. package/build/__tests__/xyz.util.d.ts +7 -11
  15. package/build/__tests__/xyz.util.d.ts.map +1 -1
  16. package/build/__tests__/xyz.util.js +14 -42
  17. package/build/__tests__/xyz.util.js.map +1 -0
  18. package/build/index.d.ts +0 -2
  19. package/build/index.d.ts.map +1 -1
  20. package/build/index.js +68 -41
  21. package/build/index.js.map +1 -0
  22. package/build/routes/__tests__/attribution.test.js +351 -399
  23. package/build/routes/__tests__/attribution.test.js.map +1 -0
  24. package/build/routes/__tests__/fonts.test.js +17 -3
  25. package/build/routes/__tests__/fonts.test.js.map +1 -0
  26. package/build/routes/__tests__/health.test.js +17 -13
  27. package/build/routes/__tests__/health.test.js.map +1 -0
  28. package/build/routes/__tests__/imagery.test.js +1 -0
  29. package/build/routes/__tests__/imagery.test.js.map +1 -0
  30. package/build/routes/__tests__/memory.fs.js +1 -0
  31. package/build/routes/__tests__/memory.fs.js.map +1 -0
  32. package/build/routes/__tests__/sprites.test.js +7 -0
  33. package/build/routes/__tests__/sprites.test.js.map +1 -0
  34. package/build/routes/__tests__/tile.json.test.d.ts +2 -0
  35. package/build/routes/__tests__/tile.json.test.d.ts.map +1 -0
  36. package/build/routes/__tests__/tile.json.test.js +124 -0
  37. package/build/routes/__tests__/tile.json.test.js.map +1 -0
  38. package/build/routes/__tests__/tile.style.json.test.d.ts +2 -0
  39. package/build/routes/__tests__/tile.style.json.test.d.ts.map +1 -0
  40. package/build/routes/__tests__/tile.style.json.test.js +95 -0
  41. package/build/routes/__tests__/tile.style.json.test.js.map +1 -0
  42. package/build/routes/__tests__/wmts.test.js +37 -27
  43. package/build/routes/__tests__/wmts.test.js.map +1 -0
  44. package/build/{__tests__ → routes/__tests__}/xyz.test.d.ts +0 -0
  45. package/build/routes/__tests__/xyz.test.d.ts.map +1 -0
  46. package/build/routes/__tests__/xyz.test.js +99 -0
  47. package/build/routes/__tests__/xyz.test.js.map +1 -0
  48. package/build/routes/attribution.d.ts +7 -5
  49. package/build/routes/attribution.d.ts.map +1 -1
  50. package/build/routes/attribution.js +50 -91
  51. package/build/routes/attribution.js.map +1 -0
  52. package/build/routes/fonts.d.ts +1 -1
  53. package/build/routes/fonts.d.ts.map +1 -1
  54. package/build/routes/fonts.js +33 -10
  55. package/build/routes/fonts.js.map +1 -0
  56. package/build/routes/health.d.ts +3 -3
  57. package/build/routes/health.d.ts.map +1 -1
  58. package/build/routes/health.js +16 -13
  59. package/build/routes/health.js.map +1 -0
  60. package/build/routes/imagery.d.ts +8 -1
  61. package/build/routes/imagery.d.ts.map +1 -1
  62. package/build/routes/imagery.js +17 -17
  63. package/build/routes/imagery.js.map +1 -0
  64. package/build/routes/ping.d.ts +3 -0
  65. package/build/routes/ping.d.ts.map +1 -0
  66. package/build/routes/ping.js +7 -0
  67. package/build/routes/ping.js.map +1 -0
  68. package/build/routes/sprites.d.ts.map +1 -1
  69. package/build/routes/sprites.js +22 -22
  70. package/build/routes/sprites.js.map +1 -0
  71. package/build/routes/tile.json.d.ts +7 -1
  72. package/build/routes/tile.json.d.ts.map +1 -1
  73. package/build/routes/tile.json.js +19 -22
  74. package/build/routes/tile.json.js.map +1 -0
  75. package/build/routes/tile.style.json.d.ts +6 -1
  76. package/build/routes/tile.style.json.d.ts.map +1 -1
  77. package/build/routes/tile.style.json.js +11 -13
  78. package/build/routes/tile.style.json.js.map +1 -0
  79. package/build/routes/tile.wmts.d.ts +9 -3
  80. package/build/routes/tile.wmts.d.ts.map +1 -1
  81. package/build/routes/tile.wmts.js +37 -50
  82. package/build/routes/tile.wmts.js.map +1 -0
  83. package/build/routes/tile.xyz.d.ts +14 -4
  84. package/build/routes/tile.xyz.d.ts.map +1 -1
  85. package/build/routes/tile.xyz.js +22 -17
  86. package/build/routes/tile.xyz.js.map +1 -0
  87. package/build/routes/tile.xyz.raster.d.ts +11 -0
  88. package/build/routes/tile.xyz.raster.d.ts.map +1 -0
  89. package/build/routes/tile.xyz.raster.js +90 -0
  90. package/build/routes/tile.xyz.raster.js.map +1 -0
  91. package/build/routes/tile.xyz.vector.d.ts +8 -0
  92. package/build/routes/tile.xyz.vector.d.ts.map +1 -0
  93. package/build/routes/tile.xyz.vector.js +46 -0
  94. package/build/routes/tile.xyz.vector.js.map +1 -0
  95. package/build/routes/version.d.ts +3 -0
  96. package/build/routes/version.d.ts.map +1 -0
  97. package/build/routes/version.js +9 -0
  98. package/build/routes/version.js.map +1 -0
  99. package/build/util/__test__/validate.test.d.ts +2 -0
  100. package/build/util/__test__/validate.test.d.ts.map +1 -0
  101. package/build/util/__test__/validate.test.js +66 -0
  102. package/build/util/__test__/validate.test.js.map +1 -0
  103. package/build/util/cotar.serve.d.ts +20 -0
  104. package/build/util/cotar.serve.d.ts.map +1 -0
  105. package/build/util/cotar.serve.js +41 -0
  106. package/build/util/cotar.serve.js.map +1 -0
  107. package/build/util/etag.d.ts +6 -0
  108. package/build/util/etag.d.ts.map +1 -0
  109. package/build/util/etag.js +20 -0
  110. package/build/util/etag.js.map +1 -0
  111. package/build/util/response.d.ts +4 -0
  112. package/build/util/response.d.ts.map +1 -0
  113. package/build/util/response.js +4 -0
  114. package/build/util/response.js.map +1 -0
  115. package/build/util/source.cache.d.ts +28 -0
  116. package/build/util/source.cache.d.ts.map +1 -0
  117. package/build/util/source.cache.js +53 -0
  118. package/build/util/source.cache.js.map +1 -0
  119. package/build/{source.tracer.d.ts → util/source.tracer.d.ts} +1 -0
  120. package/build/util/source.tracer.d.ts.map +1 -0
  121. package/build/{source.tracer.js → util/source.tracer.js} +4 -0
  122. package/build/util/source.tracer.js.map +1 -0
  123. package/build/util/swapping.lru.d.ts +21 -0
  124. package/build/util/swapping.lru.d.ts.map +1 -0
  125. package/build/util/swapping.lru.js +56 -0
  126. package/build/util/swapping.lru.js.map +1 -0
  127. package/build/util/validate.d.ts +46 -0
  128. package/build/util/validate.d.ts.map +1 -0
  129. package/build/util/validate.js +107 -0
  130. package/build/util/validate.js.map +1 -0
  131. package/build/wmts.capability.d.ts +27 -13
  132. package/build/wmts.capability.d.ts.map +1 -1
  133. package/build/wmts.capability.js +156 -55
  134. package/build/wmts.capability.js.map +1 -0
  135. package/dist/index.js +89 -73
  136. package/dist/node_modules/.package-lock.json +1 -1
  137. package/dist/package-lock.json +2 -2
  138. package/dist/package.json +1 -1
  139. package/package.json +10 -10
  140. package/src/__tests__/config.data.ts +120 -0
  141. package/src/__tests__/index.test.ts +4 -20
  142. package/src/__tests__/wmts.capability.test.ts +312 -139
  143. package/src/__tests__/xyz.util.ts +17 -45
  144. package/src/index.ts +75 -41
  145. package/src/routes/__tests__/attribution.test.ts +356 -403
  146. package/src/routes/__tests__/fonts.test.ts +18 -3
  147. package/src/routes/__tests__/health.test.ts +17 -13
  148. package/src/routes/__tests__/sprites.test.ts +6 -1
  149. package/src/routes/__tests__/tile.json.test.ts +145 -0
  150. package/src/routes/__tests__/tile.style.json.test.ts +105 -0
  151. package/src/routes/__tests__/wmts.test.ts +44 -34
  152. package/src/routes/__tests__/xyz.test.ts +119 -0
  153. package/src/routes/attribution.ts +59 -111
  154. package/src/routes/fonts.ts +32 -10
  155. package/src/routes/health.ts +17 -16
  156. package/src/routes/imagery.ts +18 -15
  157. package/src/routes/ping.ts +8 -0
  158. package/src/routes/sprites.ts +20 -22
  159. package/src/routes/tile.json.ts +24 -19
  160. package/src/routes/tile.style.json.ts +15 -12
  161. package/src/routes/tile.wmts.ts +41 -44
  162. package/src/routes/tile.xyz.raster.ts +106 -0
  163. package/src/routes/tile.xyz.ts +31 -16
  164. package/src/routes/tile.xyz.vector.ts +47 -0
  165. package/src/routes/version.ts +8 -0
  166. package/src/util/__test__/validate.test.ts +74 -0
  167. package/src/util/cotar.serve.ts +46 -0
  168. package/src/util/etag.ts +20 -0
  169. package/src/util/response.ts +4 -0
  170. package/src/util/source.cache.ts +71 -0
  171. package/src/{source.tracer.ts → util/source.tracer.ts} +4 -0
  172. package/src/util/swapping.lru.ts +63 -0
  173. package/src/util/validate.ts +126 -0
  174. package/src/wmts.capability.ts +170 -68
  175. package/tsconfig.tsbuildinfo +1 -1
  176. package/build/__tests__/route.test.d.ts +0 -2
  177. package/build/__tests__/route.test.d.ts.map +0 -1
  178. package/build/__tests__/route.test.js +0 -20
  179. package/build/__tests__/tiff.cache.test.d.ts +0 -2
  180. package/build/__tests__/tiff.cache.test.d.ts.map +0 -1
  181. package/build/__tests__/tiff.cache.test.js +0 -58
  182. package/build/__tests__/tile.cache.key.test.d.ts +0 -2
  183. package/build/__tests__/tile.cache.key.test.d.ts.map +0 -1
  184. package/build/__tests__/tile.cache.key.test.js +0 -48
  185. package/build/__tests__/tile.set.cache.test.d.ts +0 -2
  186. package/build/__tests__/tile.set.cache.test.d.ts.map +0 -1
  187. package/build/__tests__/tile.set.cache.test.js +0 -123
  188. package/build/__tests__/tile.set.test.d.ts +0 -2
  189. package/build/__tests__/tile.set.test.d.ts.map +0 -1
  190. package/build/__tests__/tile.set.test.js +0 -11
  191. package/build/__tests__/xyz.test.d.ts.map +0 -1
  192. package/build/__tests__/xyz.test.js +0 -306
  193. package/build/api.key.d.ts +0 -2
  194. package/build/api.key.d.ts.map +0 -1
  195. package/build/api.key.js +0 -23
  196. package/build/cli/dump.d.ts +0 -2
  197. package/build/cli/dump.d.ts.map +0 -1
  198. package/build/cli/dump.js +0 -47
  199. package/build/cli/tile.set.local.d.ts +0 -12
  200. package/build/cli/tile.set.local.d.ts.map +0 -1
  201. package/build/cli/tile.set.local.js +0 -39
  202. package/build/router.d.ts +0 -15
  203. package/build/router.d.ts.map +0 -1
  204. package/build/router.js +0 -49
  205. package/build/routes/api.d.ts +0 -5
  206. package/build/routes/api.d.ts.map +0 -1
  207. package/build/routes/api.js +0 -16
  208. package/build/routes/esri/rest.d.ts +0 -10
  209. package/build/routes/esri/rest.d.ts.map +0 -1
  210. package/build/routes/esri/rest.js +0 -87
  211. package/build/routes/response.d.ts +0 -4
  212. package/build/routes/response.d.ts.map +0 -1
  213. package/build/routes/response.js +0 -3
  214. package/build/routes/tile.d.ts +0 -3
  215. package/build/routes/tile.d.ts.map +0 -1
  216. package/build/routes/tile.etag.d.ts +0 -11
  217. package/build/routes/tile.etag.d.ts.map +0 -1
  218. package/build/routes/tile.etag.js +0 -29
  219. package/build/routes/tile.js +0 -27
  220. package/build/source.tracer.d.ts.map +0 -1
  221. package/build/tiff.cache.d.ts +0 -17
  222. package/build/tiff.cache.d.ts.map +0 -1
  223. package/build/tiff.cache.js +0 -45
  224. package/build/tile.set.cache.d.ts +0 -21
  225. package/build/tile.set.cache.d.ts.map +0 -1
  226. package/build/tile.set.cache.js +0 -100
  227. package/build/tile.set.d.ts +0 -4
  228. package/build/tile.set.d.ts.map +0 -1
  229. package/build/tile.set.js +0 -1
  230. package/build/tile.set.raster.d.ts +0 -49
  231. package/build/tile.set.raster.d.ts.map +0 -1
  232. package/build/tile.set.raster.js +0 -186
  233. package/build/tile.set.vector.d.ts +0 -25
  234. package/build/tile.set.vector.d.ts.map +0 -1
  235. package/build/tile.set.vector.js +0 -71
  236. package/build/validate.d.ts +0 -16
  237. package/build/validate.d.ts.map +0 -1
  238. package/build/validate.js +0 -31
  239. package/src/__tests__/route.test.ts +0 -24
  240. package/src/__tests__/tiff.cache.test.ts +0 -73
  241. package/src/__tests__/tile.cache.key.test.ts +0 -56
  242. package/src/__tests__/tile.set.cache.test.ts +0 -146
  243. package/src/__tests__/tile.set.test.ts +0 -12
  244. package/src/__tests__/xyz.test.ts +0 -362
  245. package/src/api.key.ts +0 -23
  246. package/src/cli/dump.ts +0 -61
  247. package/src/cli/tile.set.local.ts +0 -51
  248. package/src/router.ts +0 -58
  249. package/src/routes/api.ts +0 -19
  250. package/src/routes/esri/rest.ts +0 -90
  251. package/src/routes/response.ts +0 -4
  252. package/src/routes/tile.etag.ts +0 -36
  253. package/src/routes/tile.ts +0 -23
  254. package/src/tiff.cache.ts +0 -51
  255. package/src/tile.set.cache.ts +0 -111
  256. package/src/tile.set.raster.ts +0 -228
  257. package/src/tile.set.ts +0 -4
  258. package/src/tile.set.vector.ts +0 -79
  259. package/src/validate.ts +0 -32
@@ -1,87 +0,0 @@
1
- import { GoogleTms } from '@basemaps/geo';
2
- import { tileXyzFromPath } from '@basemaps/shared';
3
- import { 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
- export async function vectorTileServer(req, layerId, tms) {
8
- if (tms.identifier !== GoogleTms.identifier)
9
- return NotFound;
10
- const extent = {
11
- xmin: tms.extent.x,
12
- ymin: tms.extent.y,
13
- xmax: tms.extent.right,
14
- ymax: tms.extent.bottom,
15
- // TODO where is wkid from
16
- spatialReference: { wkid: 102100, latestWkid: tms.projection.code },
17
- };
18
- const res = new LambdaHttpResponse(200, 'ok');
19
- res.json({
20
- currentVersion: 10.4,
21
- name: layerId,
22
- capabilities: 'TilesOnly',
23
- type: 'indexedVector',
24
- tileMap: 'tilemap',
25
- defaultStyles: 'resources/styles',
26
- tiles: ['tiles/{z}/{x}/{y}.pbf'],
27
- exportTilesAllowed: false,
28
- maxExportTilesCount: 0,
29
- initialExtent: extent,
30
- fullExtent: extent,
31
- minScale: tms.zooms[0].scaleDenominator,
32
- maxScale: tms.zooms[tms.zooms.length - 1].scaleDenominator,
33
- tileInfo: {
34
- // TODO are all the pbf 256x256?
35
- rows: 256,
36
- cols: 256,
37
- dpi: 96,
38
- format: 'pbf',
39
- origin: { x: tms.extent.x, y: tms.extent.bottom },
40
- spatialReference: { wkid: 102100, latestWkid: tms.projection.code },
41
- lods: tms.zooms.map((c, i) => {
42
- return {
43
- level: i,
44
- scale: c.scaleDenominator,
45
- resolution: c.scaleDenominator * 0.28e-3,
46
- };
47
- }),
48
- },
49
- resourceInfo: {
50
- styleVersion: 8,
51
- tileCompression: 'gzip',
52
- cacheInfo: { storageInfo: { packetSize: 128, storageFormat: 'compactV2' } },
53
- },
54
- });
55
- return res;
56
- }
57
- /**
58
- * /v1/esri/services/:layerId/VectorTileServer
59
- *
60
- * @example http://localhost:5000/v1/esri/services/topographic/VectorTileServer
61
- */
62
- export async function Esri(req) {
63
- const { rest } = Router.action(req);
64
- if (rest[0] !== 'services')
65
- return NotFound;
66
- const layerId = rest[1];
67
- if (layerId == null)
68
- return NotFound;
69
- const serviceId = rest[2];
70
- if (serviceId !== 'VectorTileServer')
71
- return NotFound;
72
- if (rest.length === 3)
73
- return vectorTileServer(req, layerId, GoogleTms);
74
- if (rest[rest.length - 1].endsWith('.pbf')) {
75
- const generatedPath = [layerId, GoogleTms.identifier, ...rest.slice(rest.length - 3)];
76
- const xyz = tileXyzFromPath(generatedPath);
77
- if (xyz == null)
78
- return NotFound;
79
- req.timer.start('tileset:load');
80
- const tileSet = await TileSets.get(xyz.name, xyz.tileMatrix);
81
- req.timer.end('tileset:load');
82
- if (tileSet == null)
83
- return NotFound;
84
- return await tileSet.tile(req, xyz);
85
- }
86
- return new LambdaHttpResponse(200, 'ok');
87
- }
@@ -1,4 +0,0 @@
1
- import { LambdaHttpResponse } from '@linzjs/lambda';
2
- export declare const NotFound: LambdaHttpResponse;
3
- export declare const NotModified: LambdaHttpResponse;
4
- //# sourceMappingURL=response.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../../src/routes/response.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEpD,eAAO,MAAM,QAAQ,oBAA2C,CAAC;AACjE,eAAO,MAAM,WAAW,oBAA8C,CAAC"}
@@ -1,3 +0,0 @@
1
- import { LambdaHttpResponse } from '@linzjs/lambda';
2
- export const NotFound = new LambdaHttpResponse(404, 'Not Found');
3
- export const NotModified = new LambdaHttpResponse(304, 'Not modified');
@@ -1,3 +0,0 @@
1
- import { LambdaHttpRequest, LambdaHttpResponse } from '@linzjs/lambda';
2
- export declare function Tiles(req: LambdaHttpRequest): Promise<LambdaHttpResponse>;
3
- //# sourceMappingURL=tile.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tile.d.ts","sourceRoot":"","sources":["../../src/routes/tile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAUvE,wBAAsB,KAAK,CAAC,GAAG,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAY/E"}
@@ -1,11 +0,0 @@
1
- import { Composition } from '@basemaps/tiler';
2
- import { TileDataXyz } from '@basemaps/shared';
3
- import { LambdaHttpRequest } from '@linzjs/lambda';
4
- export declare const TileEtag: {
5
- RenderId: number;
6
- key(object: Record<string, unknown>): string;
7
- /** Generate a unique ETag for this tile */
8
- generate(compositions: Composition[], xyzData: TileDataXyz): string;
9
- isNotModified(req: LambdaHttpRequest, cacheKey: string): boolean;
10
- };
11
- //# sourceMappingURL=tile.etag.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tile.etag.d.ts","sourceRoot":"","sources":["../../src/routes/tile.etag.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAc,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAG/D,eAAO,MAAM,QAAQ;;gBAIP,OAAO,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM;IAI5C,2CAA2C;2BACpB,WAAW,EAAE,WAAW,WAAW,GAAG,MAAM;uBAUhD,iBAAiB,YAAY,MAAM,GAAG,OAAO;CAUjE,CAAC"}
@@ -1,29 +0,0 @@
1
- import { createHash } from 'crypto';
2
- import { HttpHeader } from '@linzjs/lambda';
3
- import { basename } from 'path';
4
- export const TileEtag = {
5
- // To force a full cache invalidation change this number
6
- RenderId: 1,
7
- key(object) {
8
- return createHash('sha256').update(JSON.stringify(object)).digest('base64');
9
- },
10
- /** Generate a unique ETag for this tile */
11
- generate(compositions, xyzData) {
12
- // We cannot serialize the CogTiff inside of composition so replace it with the source name
13
- const layers = compositions.map((c) => {
14
- return { ...c, tiff: basename(c.tiff.source.uri) };
15
- });
16
- const xyz = { ...xyzData, tileMatrix: xyzData.tileMatrix.identifier };
17
- return TileEtag.key({ xyz, layers, RenderId: TileEtag.RenderId });
18
- },
19
- isNotModified(req, cacheKey) {
20
- // If the user has supplied a IfNoneMatch Header and it contains the full sha256 sum for our
21
- // etag this tile has not been modified.
22
- const ifNoneMatch = req.header(HttpHeader.IfNoneMatch);
23
- if (ifNoneMatch != null && ifNoneMatch.indexOf(cacheKey) > -1) {
24
- req.set('cache', { key: cacheKey, hit: true, match: ifNoneMatch });
25
- return true;
26
- }
27
- return false;
28
- },
29
- };
@@ -1,27 +0,0 @@
1
- import { LambdaHttpResponse } from '@linzjs/lambda';
2
- import { isValidApiKey } from '../api.key.js';
3
- import { Router } from '../router.js';
4
- import { attribution } from './attribution.js';
5
- import { NotFound } from './response.js';
6
- import { tileJson } from './tile.json.js';
7
- import { styleJson } from './tile.style.json.js';
8
- import { wmts } from './tile.wmts.js';
9
- import { tileXyz } from './tile.xyz.js';
10
- export async function Tiles(req) {
11
- const { rest } = Router.action(req);
12
- if (rest.length < 1)
13
- return NotFound;
14
- const apiKey = Router.apiKey(req);
15
- if (!isValidApiKey(apiKey))
16
- return new LambdaHttpResponse(400, 'Invalid API Key');
17
- const fileName = rest[rest.length - 1].toLowerCase();
18
- if (fileName === 'attribution.json')
19
- return attribution(req);
20
- if (fileName === 'wmtscapabilities.xml')
21
- return wmts(req);
22
- if (fileName === 'tile.json')
23
- return tileJson(req);
24
- if (fileName.endsWith('json') && rest[rest.length - 2] === 'style')
25
- return styleJson(req, fileName);
26
- return tileXyz(req);
27
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"source.tracer.d.ts","sourceRoot":"","sources":["../src/source.tracer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,UAAU,aAAa;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,qBAAa,YAAY;IACvB,QAAQ,EAAE,aAAa,EAAE,CAAM;IAE/B,+BAA+B;IAC/B,KAAK,IAAI,IAAI;IAIb,6EAA6E;IAC7E,KAAK,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI;CAajC;AAED,eAAO,MAAM,EAAE,cAAqB,CAAC"}
@@ -1,17 +0,0 @@
1
- import { CogTiff } from '@cogeotiff/core';
2
- /** Limit the caching of tiffs */
3
- export declare class TiffCache {
4
- static cacheA: Map<string, CogTiff>;
5
- static cacheB: Map<string, CogTiff>;
6
- /** 256 MB Cache */
7
- static MaxCacheSizeBytes: number;
8
- static get(id: string): CogTiff | null;
9
- /** Reset the cache */
10
- static clear(): void;
11
- static set(id: string, tiff: CogTiff): void;
12
- /** Validate the size of the cache has not exploded */
13
- static check(): void;
14
- /** Calculate the total number of bytes used by this tiff cache */
15
- static get currentSize(): number;
16
- }
17
- //# sourceMappingURL=tiff.cache.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tiff.cache.d.ts","sourceRoot":"","sources":["../src/tiff.cache.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE1C,iCAAiC;AACjC,qBAAa,SAAS;IACpB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAa;IAChD,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAa;IAEhD,mBAAmB;IACnB,MAAM,CAAC,iBAAiB,SAAqB;IAE7C,MAAM,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,GAAG,IAAI;IAYtC,sBAAsB;IACtB,MAAM,CAAC,KAAK,IAAI,IAAI;IAKpB,MAAM,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI;IAK3C,sDAAsD;IACtD,MAAM,CAAC,KAAK,IAAI,IAAI;IAOpB,kEAAkE;IAClE,MAAM,KAAK,WAAW,IAAI,MAAM,CAM/B;CACF"}
@@ -1,45 +0,0 @@
1
- /** Limit the caching of tiffs */
2
- export class TiffCache {
3
- static get(id) {
4
- const cacheA = TiffCache.cacheA.get(id);
5
- if (cacheA)
6
- return cacheA;
7
- const cacheB = TiffCache.cacheB.get(id);
8
- if (cacheB == null)
9
- return null;
10
- // If a object is still useful move it into the main cache
11
- TiffCache.cacheA.set(id, cacheB);
12
- TiffCache.cacheB.delete(id);
13
- return cacheB;
14
- }
15
- /** Reset the cache */
16
- static clear() {
17
- this.cacheA.clear();
18
- this.cacheB.clear();
19
- }
20
- static set(id, tiff) {
21
- TiffCache.cacheA.set(id, tiff);
22
- TiffCache.check();
23
- }
24
- /** Validate the size of the cache has not exploded */
25
- static check() {
26
- if (TiffCache.MaxCacheSizeBytes <= 0)
27
- return;
28
- if (TiffCache.currentSize <= TiffCache.MaxCacheSizeBytes)
29
- return;
30
- TiffCache.cacheB = TiffCache.cacheA;
31
- TiffCache.cacheA = new Map();
32
- }
33
- /** Calculate the total number of bytes used by this tiff cache */
34
- static get currentSize() {
35
- let size = 0;
36
- for (const value of TiffCache.cacheA.values()) {
37
- size += value.source.chunkSize * value.source.chunks.size;
38
- }
39
- return size;
40
- }
41
- }
42
- TiffCache.cacheA = new Map();
43
- TiffCache.cacheB = new Map();
44
- /** 256 MB Cache */
45
- TiffCache.MaxCacheSizeBytes = 256 * 1024 * 1024;
@@ -1,21 +0,0 @@
1
- import { TileMatrixSet } from '@basemaps/geo';
2
- import { TileSet } from './tile.set.js';
3
- export declare class TileSetCache {
4
- /** Duration to cache tile sets for */
5
- CacheTime: number;
6
- /** Cache the fetch requests */
7
- cache: Map<string, {
8
- time: number;
9
- value: Promise<TileSet | null>;
10
- }>;
11
- /** Cache initialized tile sets */
12
- tileSets: Map<string, TileSet>;
13
- id(tileSet: TileSet): string;
14
- id(name: string, tileMatrix: TileMatrixSet): string;
15
- add(tileSet: TileSet, expiresAt?: number): void;
16
- get(name: string, tileMatrix: TileMatrixSet): Promise<TileSet | null>;
17
- loadTileSet(name: string, tileMatrix: TileMatrixSet): Promise<TileSet | null>;
18
- getAll(name: string, tileMatrix?: TileMatrixSet | null): Promise<TileSet[]>;
19
- }
20
- export declare const TileSets: TileSetCache;
21
- //# sourceMappingURL=tile.set.cache.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tile.set.cache.d.ts","sourceRoot":"","sources":["../src/tile.set.cache.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAkB,MAAM,eAAe,CAAC;AAE9D,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAIxC,qBAAa,YAAY;IACvB,sCAAsC;IACtC,SAAS,SAAU;IAEnB,+BAA+B;IAC/B,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAAA;KAAE,CAAC,CAAa;IACjF,kCAAkC;IAClC,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAa;IAE3C,EAAE,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM;IAC5B,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,aAAa,GAAG,MAAM;IAUnD,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS,SAA8B,GAAG,IAAI;IAMpE,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,aAAa,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;IAY/D,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,aAAa,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;IAqC7E,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,aAAa,GAAG,IAAI,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;CA0BlF;AAED,eAAO,MAAM,QAAQ,cAAqB,CAAC"}
@@ -1,100 +0,0 @@
1
- import { TileSetNameParser, TileSetType } from '@basemaps/config';
2
- import { TileMatrixSets } from '@basemaps/geo';
3
- import { Config } from '@basemaps/shared';
4
- import { TileSetRaster } from './tile.set.raster.js';
5
- import { TileSetVector } from './tile.set.vector.js';
6
- export class TileSetCache {
7
- constructor() {
8
- /** Duration to cache tile sets for */
9
- this.CacheTime = 30000;
10
- /** Cache the fetch requests */
11
- this.cache = new Map();
12
- /** Cache initialized tile sets */
13
- this.tileSets = new Map();
14
- }
15
- id(name, tileMatrix) {
16
- if (typeof name === 'string') {
17
- const nameComp = TileSetNameParser.parse(name);
18
- return `${TileSetNameParser.componentsToName(nameComp)}_${tileMatrix === null || tileMatrix === void 0 ? void 0 : tileMatrix.identifier}`;
19
- }
20
- return `${name.fullName}_${name.tileMatrix.identifier}`;
21
- }
22
- add(tileSet, expiresAt = Date.now() + this.CacheTime) {
23
- const id = this.id(tileSet);
24
- if (this.cache.has(id))
25
- throw new Error('Trying to add duplicate tile set:' + id);
26
- this.cache.set(id, { time: expiresAt, value: Promise.resolve(tileSet) });
27
- }
28
- get(name, tileMatrix) {
29
- const tsId = this.id(name, tileMatrix);
30
- let existing = this.cache.get(tsId);
31
- // Validate the data is current every ~30 seconds
32
- if (existing == null || Date.now() - existing.time > 0) {
33
- const value = this.loadTileSet(name, tileMatrix);
34
- existing = { time: Date.now(), value };
35
- this.cache.set(tsId, existing);
36
- }
37
- return existing.value;
38
- }
39
- async loadTileSet(name, tileMatrix) {
40
- const nameComp = TileSetNameParser.parse(name);
41
- const tileSetId = this.id(name, tileMatrix);
42
- if (nameComp.layer != null) {
43
- const parentName = TileSetNameParser.componentsToName({ ...nameComp, layer: undefined });
44
- const parent = await this.get(parentName, tileMatrix);
45
- if (parent == null || parent.type === TileSetType.Vector)
46
- return null;
47
- return parent.child(nameComp.layer);
48
- }
49
- const dbId = Config.TileSet.id(name);
50
- const tileSet = await Config.TileSet.get(dbId);
51
- if (tileSet == null) {
52
- this.cache.delete(tileSetId);
53
- return null;
54
- }
55
- // If we already have a copy and it hasn't been modified just return it
56
- const existing = this.tileSets.get(tileSetId);
57
- if (existing != null && (existing === null || existing === void 0 ? void 0 : existing.tileSet.updatedAt) === tileSet.updatedAt) {
58
- return existing;
59
- }
60
- if (Config.isTileSetRaster(tileSet)) {
61
- const ts = new TileSetRaster(name, tileMatrix);
62
- await ts.init(tileSet);
63
- this.tileSets.set(tileSetId, ts);
64
- return ts;
65
- }
66
- const ts = new TileSetVector(name, tileMatrix);
67
- await ts.init(tileSet);
68
- this.tileSets.set(tileSetId, ts);
69
- return ts;
70
- }
71
- async getAll(name, tileMatrix) {
72
- const nameComp = TileSetNameParser.parse(name);
73
- const tileMatrices = tileMatrix == null ? Array.from(TileMatrixSets.Defaults.values()) : [tileMatrix];
74
- const promises = [];
75
- for (const tileMatrix of tileMatrices)
76
- promises.push(this.get(name, tileMatrix));
77
- const tileMatrixSets = await Promise.all(promises);
78
- const tileSets = [];
79
- for (const parent of tileMatrixSets) {
80
- if (parent == null)
81
- continue;
82
- if (parent.type === TileSetType.Vector)
83
- continue;
84
- tileSets.push(parent);
85
- if (nameComp.layer != null) {
86
- parent.components.name = nameComp.name;
87
- }
88
- else if (parent.imagery != null && parent.imagery.size > 1) {
89
- for (const imageId of parent.imagery.keys()) {
90
- const childImg = parent.child(imageId);
91
- if (childImg == null)
92
- continue;
93
- tileSets.push(childImg);
94
- }
95
- }
96
- }
97
- return tileSets.sort((a, b) => a.title.localeCompare(b.title));
98
- }
99
- }
100
- export const TileSets = new TileSetCache();
@@ -1,4 +0,0 @@
1
- import { TileSetRaster } from './tile.set.raster.js';
2
- import { TileSetVector } from './tile.set.vector.js';
3
- export declare type TileSet = TileSetVector | TileSetRaster;
4
- //# sourceMappingURL=tile.set.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tile.set.d.ts","sourceRoot":"","sources":["../src/tile.set.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,oBAAY,OAAO,GAAG,aAAa,GAAG,aAAa,CAAC"}
package/build/tile.set.js DELETED
@@ -1 +0,0 @@
1
- export {};
@@ -1,49 +0,0 @@
1
- /// <reference types="node" />
2
- import { ConfigImagery, ConfigTileSetRaster, TileSetNameComponents, TileSetType } from '@basemaps/config';
3
- import { Bounds, ImageFormat, Tile, TileMatrixSet } from '@basemaps/geo';
4
- import { LogType, TileDataXyz } from '@basemaps/shared';
5
- import { Tiler } from '@basemaps/tiler';
6
- import { TileMakerSharp } from '@basemaps/tiler-sharp';
7
- import { CogTiff } from '@cogeotiff/core';
8
- import { LambdaHttpRequest, LambdaHttpResponse } from '@linzjs/lambda';
9
- import { Metrics } from '@linzjs/metrics';
10
- export declare const TileComposer: TileMakerSharp;
11
- export interface TileSetResponse {
12
- buffer: Buffer;
13
- metrics: Metrics;
14
- layersUsed: number;
15
- layersTotal: number;
16
- contentType: string;
17
- }
18
- export declare function getTiffName(name: string): string;
19
- export declare class TileSetRaster {
20
- type: TileSetType.Raster;
21
- tileMatrix: TileMatrixSet;
22
- tiler: Tiler;
23
- imagery: Map<string, ConfigImagery>;
24
- extentOverride: Bounds;
25
- components: TileSetNameComponents;
26
- tileSet: ConfigTileSetRaster;
27
- constructor(name: string, tileMatrix: TileMatrixSet);
28
- get id(): string;
29
- get fullName(): string;
30
- get title(): string;
31
- get description(): string;
32
- get extent(): Bounds;
33
- /** Preferred default imagery format */
34
- get format(): ImageFormat;
35
- init(record: ConfigTileSetRaster): Promise<void>;
36
- initTiffs(tile: Tile, log: LogType): Promise<CogTiff[]>;
37
- tile(req: LambdaHttpRequest, xyz: TileDataXyz): Promise<LambdaHttpResponse>;
38
- /**
39
- * Get a list of tiffs in the rendering order that is needed to render the tile
40
- * @param tms tile matrix set to describe the tiling scheme
41
- * @param tile tile to render
42
- */
43
- getTiffsForTile(tile: Tile, log?: LogType): CogTiff[];
44
- private getCogsForTile;
45
- /** Look up imagery by imageryId or by image name */
46
- findImagery(imgId: string): ConfigImagery | null;
47
- child(imgId: string): TileSetRaster | null;
48
- }
49
- //# sourceMappingURL=tile.set.raster.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tile.set.raster.d.ts","sourceRoot":"","sources":["../src/tile.set.raster.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,aAAa,EAEb,mBAAmB,EACnB,qBAAqB,EAErB,WAAW,EACZ,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,MAAM,EAAQ,WAAW,EAAE,IAAI,EAAE,aAAa,EAAgC,MAAM,eAAe,CAAC;AAC7G,OAAO,EAAoB,OAAO,EAAE,WAAW,EAAuB,MAAM,kBAAkB,CAAC;AAC/F,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAc,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACnF,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAU1C,eAAO,MAAM,YAAY,gBAA0B,CAAC;AAEpD,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;CACrB;AAKD,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAGhD;AAED,qBAAa,aAAa;IACxB,IAAI,EAAE,WAAW,CAAC,MAAM,CAAsB;IAE9C,UAAU,EAAE,aAAa,CAAC;IAC1B,KAAK,EAAE,KAAK,CAAC;IACb,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IACpC,cAAc,EAAE,MAAM,CAAC;IAEvB,UAAU,EAAE,qBAAqB,CAAC;IAClC,OAAO,EAAE,mBAAmB,CAAC;gBAEjB,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,aAAa;IAMnD,IAAI,EAAE,IAAI,MAAM,CAEf;IAED,IAAI,QAAQ,IAAI,MAAM,CAErB;IAED,IAAI,KAAK,IAAI,MAAM,CAElB;IAED,IAAI,WAAW,IAAI,MAAM,CAExB;IAED,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,uCAAuC;IACvC,IAAI,MAAM,IAAI,WAAW,CAExB;IAEK,IAAI,CAAC,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAKhD,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAmBhD,IAAI,CAAC,GAAG,EAAE,iBAAiB,EAAE,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,kBAAkB,CAAC;IA4BxF;;;;OAIG;IACI,eAAe,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC,EAAE,OAAO,GAAG,OAAO,EAAE;IA+B5D,OAAO,CAAC,cAAc;IAwBtB,oDAAoD;IACpD,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,aAAa,GAAG,IAAI;IAShD,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,aAAa,GAAG,IAAI;CAqB3C"}
@@ -1,186 +0,0 @@
1
- import { TileSetNameParser, TileSetType, } from '@basemaps/config';
2
- import { Bounds, Epsg, ImageFormat, TileMatrixSet, TileMatrixSets, VectorFormat } from '@basemaps/geo';
3
- import { Config, Env, fsa, titleizeImageryName } from '@basemaps/shared';
4
- import { Tiler } from '@basemaps/tiler';
5
- import { TileMakerSharp } from '@basemaps/tiler-sharp';
6
- import { CogTiff } from '@cogeotiff/core';
7
- import { HttpHeader, LambdaHttpResponse } from '@linzjs/lambda';
8
- import pLimit from 'p-limit';
9
- import { NotFound, NotModified } from './routes/response.js';
10
- import { TileEtag } from './routes/tile.etag.js';
11
- import { St } from './source.tracer.js';
12
- import { TiffCache } from './tiff.cache.js';
13
- import { TileSets } from './tile.set.cache.js';
14
- const LoadingQueue = pLimit(Env.getNumber(Env.TiffConcurrency, 25));
15
- export const TileComposer = new TileMakerSharp(256);
16
- const DefaultResizeKernel = { in: 'lanczos3', out: 'lanczos3' };
17
- const DefaultBackground = { r: 0, g: 0, b: 0, alpha: 0 };
18
- export function getTiffName(name) {
19
- if (name.endsWith('.tif') || name.endsWith('.tiff'))
20
- return name;
21
- return `${name}.tiff`;
22
- }
23
- export class TileSetRaster {
24
- constructor(name, tileMatrix) {
25
- this.type = TileSetType.Raster;
26
- this.components = TileSetNameParser.parse(name);
27
- this.tileMatrix = tileMatrix;
28
- this.tiler = new Tiler(this.tileMatrix);
29
- }
30
- get id() {
31
- return TileSets.id(this.fullName, this.tileMatrix);
32
- }
33
- get fullName() {
34
- return TileSetNameParser.componentsToName(this.components);
35
- }
36
- get title() {
37
- var _a, _b;
38
- return (_b = (_a = this.tileSet) === null || _a === void 0 ? void 0 : _a.title) !== null && _b !== void 0 ? _b : this.components.name;
39
- }
40
- get description() {
41
- var _a, _b;
42
- return (_b = (_a = this.tileSet) === null || _a === void 0 ? void 0 : _a.description) !== null && _b !== void 0 ? _b : '';
43
- }
44
- get extent() {
45
- var _a;
46
- return (_a = this.extentOverride) !== null && _a !== void 0 ? _a : this.tileMatrix.extent;
47
- }
48
- /** Preferred default imagery format */
49
- get format() {
50
- var _a;
51
- return (_a = this.tileSet.format) !== null && _a !== void 0 ? _a : ImageFormat.Webp;
52
- }
53
- async init(record) {
54
- this.tileSet = record;
55
- this.imagery = await Config.getAllImagery(this.tileSet.layers, this.tileMatrix.projection);
56
- }
57
- async initTiffs(tile, log) {
58
- const tiffs = this.getTiffsForTile(tile, log);
59
- let failed = false;
60
- // Remove any tiffs that failed to load
61
- const promises = tiffs.map((c) => {
62
- return LoadingQueue(async () => {
63
- try {
64
- await c.init();
65
- }
66
- catch (error) {
67
- log.warn({ error, tiff: c.source.uri }, 'TiffLoadFailed');
68
- failed = true;
69
- }
70
- });
71
- });
72
- await Promise.all(promises);
73
- if (failed)
74
- return tiffs.filter((f) => f.images.length > 0);
75
- return tiffs;
76
- }
77
- async tile(req, xyz) {
78
- var _a, _b;
79
- if (xyz.ext === VectorFormat.MapboxVectorTiles)
80
- return NotFound;
81
- const tiffs = await this.initTiffs(xyz, req.log);
82
- const layers = await this.tiler.tile(tiffs, xyz.x, xyz.y, xyz.z);
83
- // Generate a unique hash given the full URI, the layers used and a renderId
84
- const cacheKey = TileEtag.generate(layers, xyz);
85
- req.set('layers', layers.length);
86
- if (TileEtag.isNotModified(req, cacheKey))
87
- return NotModified;
88
- const res = await TileComposer.compose({
89
- layers,
90
- format: xyz.ext,
91
- background: (_a = this.tileSet.background) !== null && _a !== void 0 ? _a : DefaultBackground,
92
- resizeKernel: (_b = this.tileSet.resizeKernel) !== null && _b !== void 0 ? _b : DefaultResizeKernel,
93
- metrics: req.timer,
94
- });
95
- req.set('layersUsed', res.layers);
96
- req.set('bytes', res.buffer.byteLength);
97
- const response = new LambdaHttpResponse(200, 'ok');
98
- response.header(HttpHeader.ETag, cacheKey);
99
- response.header(HttpHeader.CacheControl, 'public, max-age=604800');
100
- response.buffer(res.buffer, 'image/' + xyz.ext);
101
- return response;
102
- }
103
- /**
104
- * Get a list of tiffs in the rendering order that is needed to render the tile
105
- * @param tms tile matrix set to describe the tiling scheme
106
- * @param tile tile to render
107
- */
108
- getTiffsForTile(tile, log) {
109
- const output = [];
110
- const tileBounds = this.tileMatrix.tileToSourceBounds(tile);
111
- // All zoom level config is stored as Google zoom levels
112
- const filterZoom = TileMatrixSet.convertZoomLevel(tile.z, this.tileMatrix, TileMatrixSets.get(Epsg.Google));
113
- for (const layer of this.tileSet.layers) {
114
- if (layer.maxZoom != null && filterZoom > layer.maxZoom)
115
- continue;
116
- if (layer.minZoom != null && filterZoom < layer.minZoom)
117
- continue;
118
- const imgId = layer[this.tileMatrix.projection.code];
119
- if (imgId == null) {
120
- log === null || log === void 0 ? void 0 : log.warn({ layer: layer.name, projection: this.tileMatrix.projection.code }, 'Failed to lookup imagery');
121
- continue;
122
- }
123
- const imagery = this.imagery.get(imgId);
124
- if (imagery == null) {
125
- log === null || log === void 0 ? void 0 : log.warn({ layer: layer.name, projection: this.tileMatrix.projection.code, imgId }, 'Failed to lookup imagery');
126
- continue;
127
- }
128
- if (!tileBounds.intersects(Bounds.fromJson(imagery.bounds)))
129
- continue;
130
- for (const tiff of this.getCogsForTile(imagery, tileBounds))
131
- output.push(tiff);
132
- }
133
- return output;
134
- }
135
- getCogsForTile(record, tileBounds) {
136
- const output = [];
137
- for (const c of record.files) {
138
- if (!tileBounds.intersects(Bounds.fromJson(c)))
139
- continue;
140
- const tiffPath = fsa.join(record.uri, getTiffName(c.name));
141
- let existing = TiffCache.get(tiffPath);
142
- if (existing == null) {
143
- const source = fsa.source(tiffPath);
144
- if (source == null) {
145
- throw new Error(`Failed to create CogSource from ${tiffPath}`);
146
- }
147
- St.trace(source);
148
- existing = new CogTiff(source);
149
- TiffCache.set(tiffPath, existing);
150
- }
151
- output.push(existing);
152
- }
153
- return output;
154
- }
155
- /** Look up imagery by imageryId or by image name */
156
- findImagery(imgId) {
157
- const existing = this.imagery.get(imgId);
158
- if (existing != null)
159
- return existing;
160
- for (const img of this.imagery.values()) {
161
- if (img.name === imgId)
162
- return img;
163
- }
164
- return null;
165
- }
166
- child(imgId) {
167
- var _a, _b, _c;
168
- const image = this.findImagery(imgId);
169
- if (image == null)
170
- return null;
171
- const childName = TileSetNameParser.componentsToName({ ...this.components, layer: image.name });
172
- const child = new TileSetRaster(childName, this.tileMatrix);
173
- // use parent data as prototype for child;
174
- child.tileSet = { ...this.tileSet };
175
- child.tileSet.background = undefined;
176
- const title = (_b = (_a = this.tileSet) === null || _a === void 0 ? void 0 : _a.title) !== null && _b !== void 0 ? _b : (_c = this.tileSet) === null || _c === void 0 ? void 0 : _c.name;
177
- child.tileSet.title = `${title} ${titleizeImageryName(image.name)}`;
178
- child.extentOverride = Bounds.fromJson(image.bounds);
179
- const layer = { name: image.name, minZoom: 0, maxZoom: 100 };
180
- layer[this.tileMatrix.projection.code] = image.id;
181
- child.tileSet.layers = [layer];
182
- child.imagery = new Map();
183
- child.imagery.set(image.id, image);
184
- return child;
185
- }
186
- }