@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,25 +0,0 @@
1
- import { ConfigTileSetVector, TileSetNameComponents, TileSetType } from '@basemaps/config';
2
- import { TileMatrixSet, VectorFormat } from '@basemaps/geo';
3
- import { TileDataXyz } from '@basemaps/shared';
4
- import { Cotar } from '@cotar/core';
5
- import { LambdaHttpRequest, LambdaHttpResponse } from '@linzjs/lambda';
6
- declare class CotarCache {
7
- cache: Map<string, Promise<Cotar | null>>;
8
- get(uri: string): Promise<Cotar | null>;
9
- }
10
- export declare const Layers: CotarCache;
11
- export declare class TileSetVector {
12
- type: TileSetType.Vector;
13
- components: TileSetNameComponents;
14
- tileMatrix: TileMatrixSet;
15
- tileSet: ConfigTileSetVector;
16
- constructor(name: string, tileMatrix: TileMatrixSet);
17
- init(record: ConfigTileSetVector): Promise<void>;
18
- /** What format does tile set use */
19
- get format(): VectorFormat;
20
- get id(): string;
21
- get fullName(): string;
22
- tile(req: LambdaHttpRequest, xyz: TileDataXyz): Promise<LambdaHttpResponse>;
23
- }
24
- export {};
25
- //# sourceMappingURL=tile.set.vector.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tile.set.vector.d.ts","sourceRoot":"","sources":["../src/tile.set.vector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAqB,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC9G,OAAO,EAAa,aAAa,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AACvE,OAAO,EAAO,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAc,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAKnF,cAAM,UAAU;IACd,KAAK,qCAA4C;IAEjD,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC;CAUxC;AAED,eAAO,MAAM,MAAM,YAAmB,CAAC;AAEvC,qBAAa,aAAa;IACxB,IAAI,EAAE,WAAW,CAAC,MAAM,CAAsB;IAC9C,UAAU,EAAE,qBAAqB,CAAC;IAClC,UAAU,EAAE,aAAa,CAAC;IAC1B,OAAO,EAAE,mBAAmB,CAAC;gBACjB,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,aAAa;IAK7C,IAAI,CAAC,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAItD,oCAAoC;IACpC,IAAI,MAAM,IAAI,YAAY,CAEzB;IAED,IAAI,EAAE,IAAI,MAAM,CAEf;IAED,IAAI,QAAQ,IAAI,MAAM,CAErB;IAEK,IAAI,CAAC,GAAG,EAAE,iBAAiB,EAAE,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,kBAAkB,CAAC;CAyBlF"}
@@ -1,71 +0,0 @@
1
- import { TileSetNameParser, TileSetType } from '@basemaps/config';
2
- import { GoogleTms, VectorFormat } from '@basemaps/geo';
3
- import { fsa } from '@basemaps/shared';
4
- import { Cotar } from '@cotar/core';
5
- import { HttpHeader, LambdaHttpResponse } from '@linzjs/lambda';
6
- import { NotFound } from './routes/response.js';
7
- import { TileSets } from './tile.set.cache.js';
8
- import { St } from './source.tracer.js';
9
- class CotarCache {
10
- constructor() {
11
- this.cache = new Map();
12
- }
13
- get(uri) {
14
- let cotar = this.cache.get(uri);
15
- if (cotar == null) {
16
- const source = fsa.source(uri);
17
- St.trace(source);
18
- cotar = Cotar.fromTar(source);
19
- this.cache.set(uri, cotar);
20
- }
21
- return cotar;
22
- }
23
- }
24
- export const Layers = new CotarCache();
25
- export class TileSetVector {
26
- constructor(name, tileMatrix) {
27
- this.type = TileSetType.Vector;
28
- this.components = TileSetNameParser.parse(name);
29
- this.tileMatrix = tileMatrix;
30
- }
31
- async init(record) {
32
- this.tileSet = record;
33
- }
34
- /** What format does tile set use */
35
- get format() {
36
- return VectorFormat.MapboxVectorTiles;
37
- }
38
- get id() {
39
- return TileSets.id(this.fullName, this.tileMatrix);
40
- }
41
- get fullName() {
42
- return TileSetNameParser.componentsToName(this.components);
43
- }
44
- async tile(req, xyz) {
45
- if (xyz.ext !== VectorFormat.MapboxVectorTiles)
46
- return NotFound;
47
- if (xyz.tileMatrix.identifier !== GoogleTms.identifier)
48
- return NotFound;
49
- if (this.tileSet.layers.length > 1)
50
- return new LambdaHttpResponse(500, 'Too many layers in tileset');
51
- const [layer] = this.tileSet.layers;
52
- if (layer[3857] == null)
53
- return new LambdaHttpResponse(500, 'Layer url not found from tileset Config');
54
- req.timer.start('cotar:load');
55
- const cotar = await Layers.get(layer[3857]);
56
- if (cotar == null)
57
- return new LambdaHttpResponse(500, 'Failed to load VectorTiles');
58
- req.timer.end('cotar:load');
59
- // Flip Y coordinate because MBTiles files are TMS.
60
- const y = (1 << xyz.z) - 1 - xyz.y;
61
- req.timer.start('cotar:tile');
62
- const tile = await cotar.get(`tiles/${xyz.z}/${xyz.x}/${y}.pbf.gz`);
63
- if (tile == null)
64
- return NotFound;
65
- req.timer.end('cotar:tile');
66
- const response = new LambdaHttpResponse(200, 'Ok');
67
- response.buffer(Buffer.from(tile), 'application/x-protobuf');
68
- response.header(HttpHeader.ContentEncoding, 'gzip');
69
- return response;
70
- }
71
- }
@@ -1,16 +0,0 @@
1
- import { TileDataXyz } from '@basemaps/shared';
2
- import { LambdaHttpRequest } from '@linzjs/lambda';
3
- export declare const ValidateTilePath: {
4
- /**
5
- * Validate that the tile request is somewhat valid
6
- * - Valid projection
7
- * - Valid range
8
- *
9
- * @throws LambdaHttpResponse for tile requests that are not valid
10
- *
11
- * @param req request to validate
12
- * @param xyzData
13
- */
14
- validate(req: LambdaHttpRequest, xyzData: TileDataXyz): void;
15
- };
16
- //# sourceMappingURL=validate.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAsB,MAAM,gBAAgB,CAAC;AAEvE,eAAO,MAAM,gBAAgB;IAC3B;;;;;;;;;OASG;kBACW,iBAAiB,WAAW,WAAW,GAAG,IAAI;CAiB7D,CAAC"}
package/build/validate.js DELETED
@@ -1,31 +0,0 @@
1
- import { Projection } from '@basemaps/shared';
2
- import { LambdaHttpResponse } from '@linzjs/lambda';
3
- export const ValidateTilePath = {
4
- /**
5
- * Validate that the tile request is somewhat valid
6
- * - Valid projection
7
- * - Valid range
8
- *
9
- * @throws LambdaHttpResponse for tile requests that are not valid
10
- *
11
- * @param req request to validate
12
- * @param xyzData
13
- */
14
- validate(req, xyzData) {
15
- const { tileMatrix, x, y, z, ext } = xyzData;
16
- req.set('xyz', { x, y, z });
17
- req.set('projection', tileMatrix.projection.code);
18
- req.set('tileMatrix', tileMatrix.identifier);
19
- req.set('extension', ext);
20
- req.set('tileSet', xyzData.name);
21
- if (z > tileMatrix.maxZoom || z < 0)
22
- throw new LambdaHttpResponse(404, `Zoom not found: ${z}`);
23
- const zoom = tileMatrix.zooms[z];
24
- if (x < 0 || x > zoom.matrixWidth)
25
- throw new LambdaHttpResponse(404, `X not found: ${x}`);
26
- if (y < 0 || y > zoom.matrixHeight)
27
- throw new LambdaHttpResponse(404, `Y not found: ${y}`);
28
- const latLon = Projection.tileCenterToLatLon(tileMatrix, xyzData);
29
- req.set('location', latLon);
30
- },
31
- };
@@ -1,24 +0,0 @@
1
- import { Router } from '../router.js';
2
- import o from 'ospec';
3
- import { LambdaHttpRequest } from '@linzjs/lambda';
4
-
5
- o.spec('Router', () => {
6
- function request(p: string): LambdaHttpRequest {
7
- return { path: p } as any;
8
- }
9
- o('should decode UTF8 correctly', () => {
10
- o(Router.action(request('/v1/version'))).deepEquals({ version: 'v1', name: 'version', rest: [] });
11
- });
12
-
13
- o('should ignore encoded paths', () => {
14
- o(Router.action(request('/v1/version%2fbar'))).deepEquals({ version: 'v1', name: 'version/bar', rest: [] });
15
- o(Router.action(request('/v1/tiles/%C5%8Dtorohanga%2fbar'))).deepEquals({
16
- version: 'v1',
17
- name: 'tiles',
18
- rest: ['ōtorohanga/bar'],
19
- });
20
-
21
- const uri = encodeURI('/v1/🌈/🦄.tiff');
22
- o(Router.action(request(uri))).deepEquals({ version: 'v1', name: '🌈', rest: ['🦄.tiff'] });
23
- });
24
- });
@@ -1,73 +0,0 @@
1
- import { SourceMemory } from '@chunkd/core';
2
- import { CogTiff } from '@cogeotiff/core';
3
- import o from 'ospec';
4
- import { TiffCache } from '../tiff.cache.js';
5
-
6
- /** convert number to megabytes */
7
- const MegaBytes = (num: number): number => num * 1024 * 1024;
8
-
9
- o.spec('TiffCache', () => {
10
- o.beforeEach(() => TiffCache.clear());
11
-
12
- o('should cache items', () => {
13
- const source = new SourceMemory('fake', Buffer.from('foo'));
14
- const tiff = new CogTiff(source);
15
-
16
- o(TiffCache.get('fake')).equals(null);
17
- TiffCache.set('fake', tiff);
18
- o(TiffCache.get('fake')?.source.uri).equals(tiff.source.uri);
19
-
20
- TiffCache.check();
21
- o(TiffCache.get('fake')?.source.uri).equals(tiff.source.uri);
22
- });
23
-
24
- o('should expire cached object if size gets too large', () => {
25
- const source = new SourceMemory('fake', Buffer.from('foo'));
26
- const sourceB = new SourceMemory('fakeB', Buffer.from('foo'));
27
-
28
- // Override chunk size to say there is 500 mb of items
29
- source.chunkSize = MegaBytes(257);
30
- sourceB.chunkSize = MegaBytes(257);
31
-
32
- const tiff = new CogTiff(source);
33
- const tiffB = new CogTiff(sourceB);
34
-
35
- o(TiffCache.get('fake')).equals(null);
36
-
37
- TiffCache.set('fake', tiff);
38
- o(TiffCache.get('fake')?.source.uri).equals(tiff.source.uri);
39
-
40
- TiffCache.check();
41
- o(TiffCache.cacheA.get('fake')?.source.uri).equals(undefined);
42
- o(TiffCache.cacheB.get('fake')?.source.uri).equals(tiff.source.uri);
43
-
44
- // Should evict the cache
45
- TiffCache.set('fakeB', tiffB);
46
- TiffCache.check();
47
-
48
- o(TiffCache.cacheA.get('fake')?.source.uri).equals(undefined);
49
- o(TiffCache.cacheB.get('fake')?.source.uri).equals(undefined);
50
- });
51
-
52
- o('should allow multiple items in the cache', () => {
53
- const source = new SourceMemory('fake', Buffer.from('foo'));
54
- const tiff = new CogTiff(source);
55
-
56
- TiffCache.set('fake', tiff);
57
- const oneMb = MegaBytes(1);
58
- source.chunkSize = oneMb;
59
-
60
- for (let i = 1; i < 256; i++) {
61
- o(TiffCache.currentSize).equals(i * oneMb);
62
- source.chunks.set(i, source.chunks.get(0)!);
63
- }
64
- // should not have overflown
65
- TiffCache.check();
66
- o(TiffCache.cacheA.size).equals(1);
67
- // Overflow the cache
68
- source.chunks.set(257, source.chunks.get(0)!);
69
-
70
- TiffCache.check();
71
- o(TiffCache.cacheA.size).equals(0);
72
- });
73
- });
@@ -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,146 +0,0 @@
1
- import { ConfigImagery, ConfigTileSetRaster, TileSetType } from '@basemaps/config';
2
- import { Epsg, GoogleTms, Nztm2000Tms } from '@basemaps/geo';
3
- import { Config, TileSetName } from '@basemaps/shared';
4
- import o from 'ospec';
5
- import sinon from 'sinon';
6
- import { TileSets } from '../tile.set.cache.js';
7
- import { TileSetRaster } from '../tile.set.raster.js';
8
- const sandbox = sinon.createSandbox();
9
- o.spec('TileSetCache', () => {
10
- const imageOne = {
11
- id: 'im_id1',
12
- name: 'tasman_rural_2018-19_0-3m',
13
- bounds: { x: 123, y: 456, width: 200, height: 300 },
14
- files: [{ name: 'foo', x: 123, y: 456, width: 200, height: 300 }],
15
- uri: 's3://foo/bar',
16
- } as ConfigImagery;
17
-
18
- const imageTwo = {
19
- id: 'im_id2',
20
- name: 'wellington_urban_2018-19_0-3m',
21
- bounds: { x: 123, y: 456, width: 200, height: 300 },
22
- files: [{ name: 'foo', x: 123, y: 456, width: 200, height: 300 }],
23
- uri: 's3://foo/bar',
24
- } as ConfigImagery;
25
-
26
- const imgMap = new Map<string, ConfigImagery>();
27
- imgMap.set(imageOne.id, imageOne);
28
-
29
- o.afterEach(() => {
30
- TileSets.cache.clear();
31
- sandbox.restore();
32
- });
33
-
34
- o.spec('loadTileSet', () => {
35
- o('load individual set', async () => {
36
- TileSets.add(new TileSetRaster('aerial@head', GoogleTms));
37
-
38
- const parentTileSet = await TileSets.get('aerial@head', GoogleTms);
39
- if (parentTileSet == null || parentTileSet.type === TileSetType.Vector) throw new Error('null parentTileSet');
40
- parentTileSet.imagery = imgMap;
41
- parentTileSet.tileSet = {
42
- name: 'parent',
43
- title: 'parent aerial title',
44
- background: { r: 200, g: 50, b: 100, alpha: 0.5 },
45
- } as ConfigTileSetRaster;
46
-
47
- const subTileSet = await TileSets.get('aerial@head:tasman_rural_2018-19_0-3m', GoogleTms);
48
- if (subTileSet == null || subTileSet.type === TileSetType.Vector) throw new Error('null subTileSet');
49
-
50
- o(subTileSet.title).equals('parent aerial title Tasman rural 2018-19 0.3m');
51
- o(subTileSet.fullName).equals('aerial@head:tasman_rural_2018-19_0-3m');
52
- o([...subTileSet.imagery.values()]).deepEquals([imageOne]);
53
- const [firstLayer] = subTileSet.tileSet.layers;
54
- o(firstLayer).deepEquals({
55
- name: firstLayer.name,
56
- [3857]: 'im_id1',
57
- minZoom: 0,
58
- maxZoom: 100,
59
- });
60
- o(subTileSet.tileSet.background).equals(undefined);
61
-
62
- o(parentTileSet.tileSet.background).deepEquals({ r: 200, g: 50, b: 100, alpha: 0.5 });
63
-
64
- const noTiffs = subTileSet.getTiffsForTile({ x: 0, y: 0, z: 1 });
65
- o(noTiffs).deepEquals([]);
66
-
67
- const aTiff = subTileSet.getTiffsForTile({ x: 0, y: 0, z: 0 });
68
- o(aTiff.length).equals(1);
69
- o(aTiff[0].source.uri).equals('s3://foo/bar/foo.tiff');
70
-
71
- TileSets.cache.delete(subTileSet.id);
72
- delete parentTileSet.tileSet.title;
73
- const subTileSetB = await TileSets.get('aerial@head:tasman_rural_2018-19_0-3m', GoogleTms);
74
- if (subTileSetB == null || subTileSetB.type === TileSetType.Vector) throw new Error('null subTileSetB');
75
- o(subTileSetB.title).equals('parent Tasman rural 2018-19 0.3m');
76
- });
77
-
78
- o('should not throw if child does not exist', async () => {
79
- TileSets.add(new TileSetRaster('aerial@head', GoogleTms));
80
-
81
- const parentTileSet = await TileSets.get('aerial@head', GoogleTms);
82
- if (parentTileSet == null || parentTileSet.type === TileSetType.Vector) throw new Error('null parentTileSet');
83
- parentTileSet.imagery = imgMap;
84
-
85
- const subTileSet = await TileSets.get('aerial@head:fake', GoogleTms);
86
- o(subTileSet).equals(null);
87
- });
88
- });
89
-
90
- o.spec('loadTileSets', () => {
91
- o('load all', async () => {
92
- sandbox.stub(Config.TileSet, 'get');
93
-
94
- TileSets.add(new TileSetRaster('aerial', GoogleTms));
95
- TileSets.add(new TileSetRaster('aerial', Nztm2000Tms));
96
- const tileSets = await TileSets.getAll('aerial', null);
97
-
98
- o(tileSets.length).deepEquals(2);
99
-
100
- o(tileSets[0].fullName).equals(TileSetName.aerial);
101
- o(tileSets[0].components.name).equals(TileSetName.aerial);
102
- o(tileSets[0].tileMatrix.projection.code).equals(3857);
103
-
104
- o(tileSets[1].fullName).equals(TileSetName.aerial);
105
- o(tileSets[1].components.name).equals(TileSetName.aerial);
106
- o(tileSets[1].tileMatrix.projection.code).equals(2193);
107
- });
108
-
109
- o('load all subset projections', async () => {
110
- sandbox.stub(Config.TileSet, 'get');
111
-
112
- const ts1 = new TileSetRaster('aerial@head', Nztm2000Tms);
113
- ts1.imagery = imgMap;
114
- TileSets.add(ts1);
115
- const ts2 = new TileSetRaster('aerial@head', GoogleTms);
116
- ts2.imagery = imgMap;
117
- TileSets.add(ts2);
118
- const tileSets = await TileSets.getAll('aerial@head:tasman_rural_2018-19_0-3m', null);
119
-
120
- o(tileSets.length).deepEquals(2);
121
-
122
- o(tileSets[0].fullName).equals('aerial@head:tasman_rural_2018-19_0-3m');
123
- o(tileSets[0].tileMatrix.projection).equals(Epsg.Google);
124
- o(tileSets[1].fullName).equals('aerial@head:tasman_rural_2018-19_0-3m');
125
- o(tileSets[1].tileMatrix.projection).equals(Epsg.Nztm2000);
126
- });
127
-
128
- o('load all @tag', async () => {
129
- sandbox.stub(Config.TileSet, 'get');
130
- const imgMap = new Map();
131
- imgMap.set(imageOne.id, imageOne);
132
- imgMap.set(imageTwo.id, imageTwo);
133
- const ts1 = new TileSetRaster('aerial@head', Nztm2000Tms);
134
- ts1.imagery = imgMap;
135
- TileSets.add(ts1);
136
-
137
- const tileSets = await TileSets.getAll('aerial@head', null);
138
-
139
- o(tileSets.length).deepEquals(3);
140
-
141
- o(tileSets[0].fullName).equals('aerial@head');
142
- o(tileSets[1].fullName).equals('aerial@head:tasman_rural_2018-19_0-3m');
143
- o(tileSets[2].fullName).equals('aerial@head:wellington_urban_2018-19_0-3m');
144
- });
145
- });
146
- });
@@ -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
- });