@basemaps/lambda-tiler 6.16.1 → 6.20.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 (158) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/LICENSE +2 -2
  3. package/build/__test__/tile.style.json.test.d.ts +2 -0
  4. package/build/__test__/tile.style.json.test.d.ts.map +1 -0
  5. package/build/__test__/tile.style.json.test.js +33 -0
  6. package/build/__test__/xyz.test.js +35 -34
  7. package/build/cli/dump.js +2 -2
  8. package/build/index.d.ts.map +1 -1
  9. package/build/index.js +10 -0
  10. package/build/routes/esri/rest.d.ts +10 -0
  11. package/build/routes/esri/rest.d.ts.map +1 -0
  12. package/build/routes/esri/rest.js +87 -0
  13. package/build/routes/imagery.d.ts +10 -0
  14. package/build/routes/imagery.d.ts.map +1 -0
  15. package/build/routes/imagery.js +50 -0
  16. package/build/routes/response.d.ts +4 -0
  17. package/build/routes/response.d.ts.map +1 -0
  18. package/build/routes/response.js +3 -0
  19. package/build/routes/tile.d.ts +0 -20
  20. package/build/routes/tile.d.ts.map +1 -1
  21. package/build/routes/tile.js +11 -164
  22. package/build/routes/tile.json.d.ts +10 -0
  23. package/build/routes/tile.json.d.ts.map +1 -0
  24. package/build/routes/tile.json.js +31 -0
  25. package/build/routes/tile.style.json.d.ts +10 -0
  26. package/build/routes/tile.style.json.d.ts.map +1 -0
  27. package/build/routes/tile.style.json.js +74 -0
  28. package/build/routes/tile.wmts.d.ts +9 -0
  29. package/build/routes/tile.wmts.d.ts.map +1 -0
  30. package/build/routes/tile.wmts.js +57 -0
  31. package/build/routes/tile.xyz.d.ts +13 -0
  32. package/build/routes/tile.xyz.d.ts.map +1 -0
  33. package/build/routes/tile.xyz.js +28 -0
  34. package/build/tile.set.raster.d.ts +2 -0
  35. package/build/tile.set.raster.d.ts.map +1 -1
  36. package/build/tile.set.raster.js +3 -1
  37. package/build/tile.set.vector.js +1 -1
  38. package/dist/index.js +10580 -9573
  39. package/dist/node_modules/color/README.md +7 -7
  40. package/dist/node_modules/color/index.js +173 -158
  41. package/dist/node_modules/color/package.json +18 -16
  42. package/dist/node_modules/color-convert/conversions.js +281 -310
  43. package/dist/node_modules/color-convert/index.js +27 -24
  44. package/dist/node_modules/color-convert/package.json +16 -14
  45. package/dist/node_modules/color-convert/route.js +22 -22
  46. package/dist/node_modules/color-name/package.json +17 -14
  47. package/dist/node_modules/color-string/index.js +2 -2
  48. package/dist/node_modules/color-string/package.json +10 -10
  49. package/dist/node_modules/decompress-response/index.d.ts +14 -21
  50. package/dist/node_modules/decompress-response/index.js +34 -16
  51. package/dist/node_modules/decompress-response/license +1 -1
  52. package/dist/node_modules/decompress-response/package.json +23 -17
  53. package/dist/node_modules/decompress-response/readme.md +2 -6
  54. package/dist/node_modules/detect-libc/package.json +0 -1
  55. package/dist/node_modules/mimic-response/index.d.ts +2 -2
  56. package/dist/node_modules/mimic-response/index.js +41 -2
  57. package/dist/node_modules/mimic-response/package.json +17 -17
  58. package/dist/node_modules/mimic-response/readme.md +22 -1
  59. package/dist/node_modules/node-abi/.circleci/config.yml +63 -0
  60. package/dist/node_modules/node-abi/.releaserc.json +9 -0
  61. package/dist/node_modules/node-abi/abi_registry.json +39 -4
  62. package/dist/node_modules/node-abi/index.js +5 -2
  63. package/dist/node_modules/node-abi/package.json +17 -16
  64. package/dist/node_modules/node-abi/test/index.js +7 -15
  65. package/dist/node_modules/node-addon-api/README.md +2 -2
  66. package/dist/node_modules/node-addon-api/except.gypi +20 -11
  67. package/dist/node_modules/node-addon-api/napi-inl.h +734 -196
  68. package/dist/node_modules/node-addon-api/napi.h +420 -164
  69. package/dist/node_modules/node-addon-api/noexcept.gypi +21 -11
  70. package/dist/node_modules/node-addon-api/package.json +43 -14
  71. package/dist/node_modules/node-addon-api/tools/clang-format.js +18 -17
  72. package/dist/node_modules/node-addon-api/tools/eslint-format.js +71 -0
  73. package/dist/node_modules/prebuild-install/CHANGELOG.md +24 -7
  74. package/dist/node_modules/prebuild-install/README.md +24 -4
  75. package/dist/node_modules/prebuild-install/asset.js +10 -10
  76. package/dist/node_modules/prebuild-install/bin.js +13 -13
  77. package/dist/node_modules/prebuild-install/download.js +22 -22
  78. package/dist/node_modules/prebuild-install/log.js +4 -4
  79. package/dist/node_modules/prebuild-install/node_modules/detect-libc/LICENSE +201 -0
  80. package/dist/node_modules/prebuild-install/node_modules/detect-libc/README.md +160 -0
  81. package/dist/node_modules/prebuild-install/node_modules/detect-libc/index.d.ts +11 -0
  82. package/dist/node_modules/prebuild-install/node_modules/detect-libc/lib/detect-libc.js +178 -0
  83. package/dist/node_modules/prebuild-install/node_modules/detect-libc/lib/process.js +16 -0
  84. package/dist/node_modules/prebuild-install/node_modules/detect-libc/package.json +71 -0
  85. package/dist/node_modules/prebuild-install/package.json +18 -19
  86. package/dist/node_modules/prebuild-install/proxy.js +10 -10
  87. package/dist/node_modules/prebuild-install/rc.js +12 -12
  88. package/dist/node_modules/prebuild-install/util.js +14 -14
  89. package/dist/node_modules/semver/package.json +1 -0
  90. package/dist/node_modules/sharp/README.md +2 -2
  91. package/dist/node_modules/sharp/binding.gyp +12 -9
  92. package/dist/node_modules/sharp/build/Release/sharp-linux-x64.node +0 -0
  93. package/dist/node_modules/sharp/install/dll-copy.js +6 -6
  94. package/dist/node_modules/sharp/install/libvips.js +4 -8
  95. package/dist/node_modules/sharp/lib/channel.js +11 -7
  96. package/dist/node_modules/sharp/lib/colour.js +42 -1
  97. package/dist/node_modules/sharp/lib/constructor.js +18 -31
  98. package/dist/node_modules/sharp/lib/input.js +45 -3
  99. package/dist/node_modules/sharp/lib/is.js +19 -5
  100. package/dist/node_modules/sharp/lib/libvips.js +4 -19
  101. package/dist/node_modules/sharp/lib/operation.js +28 -5
  102. package/dist/node_modules/sharp/lib/output.js +147 -16
  103. package/dist/node_modules/sharp/lib/sharp.js +31 -0
  104. package/dist/node_modules/sharp/lib/utility.js +3 -2
  105. package/dist/node_modules/sharp/package.json +32 -23
  106. package/dist/node_modules/sharp/src/common.cc +67 -11
  107. package/dist/node_modules/sharp/src/common.h +25 -5
  108. package/dist/node_modules/sharp/src/libvips/cplusplus/VConnection.cpp +0 -26
  109. package/dist/node_modules/sharp/src/libvips/cplusplus/VImage.cpp +54 -16
  110. package/dist/node_modules/sharp/src/libvips/cplusplus/VInterpolate.cpp +0 -13
  111. package/dist/node_modules/sharp/src/libvips/cplusplus/vips-operators.cpp +185 -1
  112. package/dist/node_modules/sharp/src/metadata.cc +14 -0
  113. package/dist/node_modules/sharp/src/metadata.h +1 -0
  114. package/dist/node_modules/sharp/src/operations.cc +29 -3
  115. package/dist/node_modules/sharp/src/operations.h +13 -2
  116. package/dist/node_modules/sharp/src/pipeline.cc +103 -35
  117. package/dist/node_modules/sharp/src/pipeline.h +23 -3
  118. package/dist/node_modules/sharp/src/utilities.cc +1 -1
  119. package/dist/node_modules/sharp/vendor/{8.10.6 → 8.11.3/linux-x64}/THIRD-PARTY-NOTICES.md +2 -3
  120. package/dist/node_modules/sharp/vendor/{8.10.6 → 8.11.3/linux-x64}/lib/libvips-cpp.so.42 +0 -0
  121. package/dist/node_modules/sharp/vendor/{8.10.6 → 8.11.3/linux-x64}/platform.json +0 -0
  122. package/dist/node_modules/sharp/vendor/8.11.3/linux-x64/versions.json +30 -0
  123. package/dist/node_modules/simple-get/.github/dependabot.yml +15 -0
  124. package/dist/node_modules/simple-get/.github/workflows/ci.yml +23 -0
  125. package/dist/node_modules/simple-get/README.md +17 -3
  126. package/dist/node_modules/simple-get/index.js +9 -0
  127. package/dist/node_modules/simple-get/package.json +27 -13
  128. package/dist/package-lock.json +54 -54
  129. package/dist/package.json +11 -11
  130. package/package.json +12 -12
  131. package/src/__test__/tile.style.json.test.ts +40 -0
  132. package/src/__test__/xyz.test.ts +43 -41
  133. package/src/cli/dump.ts +2 -2
  134. package/src/index.ts +10 -0
  135. package/src/routes/esri/rest.ts +90 -0
  136. package/src/routes/imagery.ts +52 -0
  137. package/src/routes/response.ts +4 -0
  138. package/src/routes/tile.json.ts +44 -0
  139. package/src/routes/tile.style.json.ts +77 -0
  140. package/src/routes/tile.ts +11 -186
  141. package/src/routes/tile.wmts.ts +59 -0
  142. package/src/routes/tile.xyz.ts +30 -0
  143. package/src/tile.set.raster.ts +4 -1
  144. package/src/tile.set.vector.ts +1 -1
  145. package/tsconfig.tsbuildinfo +1 -1
  146. package/dist/node_modules/color-name/.eslintrc.json +0 -43
  147. package/dist/node_modules/color-name/test.js +0 -7
  148. package/dist/node_modules/node-abi/.travis.yml +0 -17
  149. package/dist/node_modules/node-abi/node_modules/semver/CHANGELOG.md +0 -39
  150. package/dist/node_modules/node-abi/node_modules/semver/LICENSE +0 -15
  151. package/dist/node_modules/node-abi/node_modules/semver/README.md +0 -412
  152. package/dist/node_modules/node-abi/node_modules/semver/bin/semver +0 -160
  153. package/dist/node_modules/node-abi/node_modules/semver/package.json +0 -60
  154. package/dist/node_modules/node-abi/node_modules/semver/range.bnf +0 -16
  155. package/dist/node_modules/node-abi/node_modules/semver/semver.js +0 -1483
  156. package/dist/node_modules/node-addon-api/CHANGELOG.md +0 -722
  157. package/dist/node_modules/sharp/build/Release/sharp.node +0 -0
  158. package/dist/node_modules/sharp/vendor/8.10.6/versions.json +0 -31
@@ -1,180 +1,27 @@
1
- import { HttpHeader, LambdaHttpResponse } from '@linzjs/lambda';
2
- import { Config, Env, setNameAndProjection, TileSetName, tileWmtsFromPath, tileXyzFromPath } from '@basemaps/shared';
3
- import { TileMakerSharp } from '@basemaps/tiler-sharp';
4
- import { createHash } from 'crypto';
1
+ import { LambdaHttpResponse } from '@linzjs/lambda';
5
2
  import { isValidApiKey } from '../api.key.js';
6
- import { TileSets } from '../tile.set.cache.js';
7
- import { WmtsCapabilities } from '../wmts.capability.js';
8
- import { attribution } from './attribution.js';
9
- import { TileEtag } from './tile.etag.js';
10
3
  import { Router } from '../router.js';
11
- import { ValidateTilePath } from '../validate.js';
12
- import { URL } from 'url';
13
- export const TileComposer = new TileMakerSharp(256);
14
- export const NotFound = new LambdaHttpResponse(404, 'Not Found');
15
- export const NotModified = new LambdaHttpResponse(304, 'Not modified');
16
- export const TileRoute = {
17
- async tile(req) {
18
- const action = Router.action(req);
19
- const xyzData = tileXyzFromPath(action.rest);
20
- if (xyzData == null)
21
- return NotFound;
22
- ValidateTilePath.validate(req, xyzData);
23
- req.timer.start('tileset:load');
24
- const tileSet = await TileSets.get(xyzData.name, xyzData.tileMatrix);
25
- req.timer.end('tileset:load');
26
- if (tileSet == null)
27
- return NotFound;
28
- const res = await tileSet.tile(req, xyzData);
29
- return res;
30
- },
31
- async wmtsLoadTileSets(name, tileMatrix) {
32
- if (tileMatrix != null) {
33
- const ts = await TileSets.get(name, tileMatrix);
34
- if (ts == null || ts.isVector())
35
- return [];
36
- return [ts];
37
- }
38
- if (name === '')
39
- name = TileSetName.aerial;
40
- return (await TileSets.getAll(name, tileMatrix)).filter((f) => f.type === 'raster');
41
- },
42
- async wmts(req) {
43
- var _a;
44
- const action = Router.action(req);
45
- const wmtsData = tileWmtsFromPath(action.rest);
46
- if (wmtsData == null)
47
- return NotFound;
48
- setNameAndProjection(req, wmtsData);
49
- const host = (_a = Env.get(Env.PublicUrlBase)) !== null && _a !== void 0 ? _a : '';
50
- req.timer.start('tileset:load');
51
- const tileSets = await TileRoute.wmtsLoadTileSets(wmtsData.name, wmtsData.tileMatrix);
52
- req.timer.end('tileset:load');
53
- if (tileSets.length === 0)
54
- return NotFound;
55
- const providerId = Config.Provider.id('linz');
56
- const provider = await Config.Provider.get(providerId);
57
- if (provider == null)
58
- return NotFound;
59
- const apiKey = Router.apiKey(req);
60
- const xml = WmtsCapabilities.toXml(host, provider, tileSets, apiKey);
61
- if (xml == null)
62
- return NotFound;
63
- const data = Buffer.from(xml);
64
- const cacheKey = createHash('sha256').update(data).digest('base64');
65
- if (TileEtag.isNotModified(req, cacheKey))
66
- return NotModified;
67
- const response = new LambdaHttpResponse(200, 'ok');
68
- response.header(HttpHeader.ETag, cacheKey);
69
- response.header(HttpHeader.CacheControl, 'max-age=0');
70
- response.buffer(data, 'text/xml');
71
- req.set('bytes', data.byteLength);
72
- return response;
73
- },
74
- async tileJson(req) {
75
- var _a;
76
- const { version, rest, name } = Router.action(req);
77
- const apiKey = Router.apiKey(req);
78
- const host = (_a = Env.get(Env.PublicUrlBase)) !== null && _a !== void 0 ? _a : '';
79
- const tileUrl = `${host}/${version}/${name}/${rest[0]}/${rest[1]}/{z}/{x}/{y}.pbf?api=${apiKey}`;
80
- const tileJson = {
81
- tiles: [tileUrl],
82
- minzoom: 0,
83
- maxzoom: 15,
84
- format: 'pbf',
85
- tilejson: '2.0.0',
86
- };
87
- const json = JSON.stringify(tileJson);
88
- const data = Buffer.from(json);
89
- const cacheKey = createHash('sha256').update(data).digest('base64');
90
- if (TileEtag.isNotModified(req, cacheKey))
91
- return NotModified;
92
- const response = new LambdaHttpResponse(200, 'ok');
93
- response.header(HttpHeader.ETag, cacheKey);
94
- response.header(HttpHeader.CacheControl, 'max-age=120');
95
- response.buffer(data, 'application/json');
96
- req.set('bytes', data.byteLength);
97
- return response;
98
- },
99
- async styleJson(req, fileName) {
100
- var _a;
101
- const apiKey = Router.apiKey(req);
102
- if (apiKey == null)
103
- return new LambdaHttpResponse(400, 'Invalid API Key.');
104
- const styleName = fileName.split('.json')[0];
105
- const host = (_a = Env.get(Env.PublicUrlBase)) !== null && _a !== void 0 ? _a : '';
106
- // Get style Config from db
107
- const dbId = Config.Style.id(styleName);
108
- const styleConfig = await Config.Style.get(dbId);
109
- if (styleConfig == null)
110
- return NotFound;
111
- // Prepare sources and add linz source
112
- const style = styleConfig.style;
113
- const sources = {};
114
- for (const [key, value] of Object.entries(style.sources)) {
115
- if (value.type === 'vector') {
116
- if (value.url.includes(host)) {
117
- const url = new URL(value.url);
118
- url.searchParams.set('api', apiKey);
119
- value.url = url.toString().replace(/%7B/g, '{').replace(/%7D/g, '}');
120
- }
121
- }
122
- else if (value.type === 'raster' && Array.isArray(value.tiles)) {
123
- for (let i = 0; i < value.tiles.length; i++) {
124
- const tile = value.tiles[i];
125
- if (tile.includes(host)) {
126
- const url = new URL(tile);
127
- url.searchParams.set('api', apiKey);
128
- value.tiles[i] = url.toString().replace(/%7B/g, '{').replace(/%7D/g, '}');
129
- }
130
- }
131
- }
132
- sources[key] = value;
133
- }
134
- // prepare Style.json
135
- const styleJson = {
136
- /** Style.json version 8 */
137
- version: 8,
138
- id: style.id,
139
- name: style.name,
140
- sources,
141
- layers: style.layers,
142
- metadata: style.metadata || {},
143
- glyphs: style.glyphs || '',
144
- sprite: style.sprite || '',
145
- };
146
- const json = JSON.stringify(styleJson);
147
- const data = Buffer.from(json);
148
- const cacheKey = createHash('sha256').update(data).digest('base64');
149
- if (TileEtag.isNotModified(req, cacheKey))
150
- return NotModified;
151
- const response = new LambdaHttpResponse(200, 'ok');
152
- response.header(HttpHeader.ETag, cacheKey);
153
- response.header(HttpHeader.CacheControl, 'max-age=120');
154
- response.buffer(data, 'application/json');
155
- req.set('bytes', data.byteLength);
156
- return response;
157
- },
158
- };
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';
159
10
  export async function Tiles(req) {
160
11
  const { rest } = Router.action(req);
161
12
  if (rest.length < 1)
162
13
  return NotFound;
163
14
  const apiKey = Router.apiKey(req);
164
- const apiKeyHash = createHash('sha256')
165
- .update(apiKey !== null && apiKey !== void 0 ? apiKey : '')
166
- .digest('base64');
167
- req.set('api', apiKeyHash);
168
15
  if (!isValidApiKey(apiKey))
169
16
  return new LambdaHttpResponse(400, 'Invalid API Key');
170
17
  const fileName = rest[rest.length - 1].toLowerCase();
171
18
  if (fileName === 'attribution.json')
172
19
  return attribution(req);
173
20
  if (fileName === 'wmtscapabilities.xml')
174
- return TileRoute.wmts(req);
21
+ return wmts(req);
175
22
  if (fileName === 'tile.json')
176
- return TileRoute.tileJson(req);
23
+ return tileJson(req);
177
24
  if (fileName.endsWith('json') && rest[rest.length - 2] === 'style')
178
- return TileRoute.styleJson(req, fileName);
179
- return TileRoute.tile(req);
25
+ return styleJson(req, fileName);
26
+ return tileXyz(req);
180
27
  }
@@ -0,0 +1,10 @@
1
+ import { LambdaHttpRequest, LambdaHttpResponse } from '@linzjs/lambda';
2
+ export interface TileJson {
3
+ tiles: string[];
4
+ minzoom: number;
5
+ maxzoom: number;
6
+ format: string;
7
+ tilejson: string;
8
+ }
9
+ export declare function tileJson(req: LambdaHttpRequest): Promise<LambdaHttpResponse>;
10
+ //# sourceMappingURL=tile.json.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tile.json.d.ts","sourceRoot":"","sources":["../../src/routes/tile.json.ts"],"names":[],"mappings":"AACA,OAAO,EAAc,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAMnF,MAAM,WAAW,QAAQ;IACvB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,wBAAsB,QAAQ,CAAC,GAAG,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CA4BlF"}
@@ -0,0 +1,31 @@
1
+ import { Env } from '@basemaps/shared';
2
+ import { HttpHeader, LambdaHttpResponse } from '@linzjs/lambda';
3
+ import { createHash } from 'crypto';
4
+ import { Router } from '../router.js';
5
+ import { NotModified } from './response.js';
6
+ import { TileEtag } from './tile.etag.js';
7
+ export async function tileJson(req) {
8
+ var _a;
9
+ const { version, rest, name } = Router.action(req);
10
+ const apiKey = Router.apiKey(req);
11
+ const host = (_a = Env.get(Env.PublicUrlBase)) !== null && _a !== void 0 ? _a : '';
12
+ const tileUrl = `${host}/${version}/${name}/${rest[0]}/${rest[1]}/{z}/{x}/{y}.pbf?api=${apiKey}`;
13
+ const tileJson = {
14
+ tiles: [tileUrl],
15
+ minzoom: 0,
16
+ maxzoom: 15,
17
+ format: 'pbf',
18
+ tilejson: '2.0.0',
19
+ };
20
+ const json = JSON.stringify(tileJson);
21
+ const data = Buffer.from(json);
22
+ const cacheKey = createHash('sha256').update(data).digest('base64');
23
+ if (TileEtag.isNotModified(req, cacheKey))
24
+ return NotModified;
25
+ const response = new LambdaHttpResponse(200, 'ok');
26
+ response.header(HttpHeader.ETag, cacheKey);
27
+ response.header(HttpHeader.CacheControl, 'max-age=120');
28
+ response.buffer(data, 'application/json');
29
+ req.set('bytes', data.byteLength);
30
+ return response;
31
+ }
@@ -0,0 +1,10 @@
1
+ import { LambdaHttpRequest, LambdaHttpResponse } from '@linzjs/lambda';
2
+ /**
3
+ * Convert relative URLS into a full hostname url
4
+ * @param url possible url to update
5
+ * @param apiKey ApiKey to append with ?api= if required
6
+ * @returns Updated Url or empty string if url is empty
7
+ */
8
+ export declare function convertRelativeUrl(url?: string, apiKey?: string): string;
9
+ export declare function styleJson(req: LambdaHttpRequest, fileName: string): Promise<LambdaHttpResponse>;
10
+ //# sourceMappingURL=tile.style.json.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tile.style.json.d.ts","sourceRoot":"","sources":["../../src/routes/tile.style.json.ts"],"names":[],"mappings":"AAGA,OAAO,EAAc,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAOnF;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAOxE;AAED,wBAAsB,SAAS,CAAC,GAAG,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAmDrG"}
@@ -0,0 +1,74 @@
1
+ import { Config, Env } from '@basemaps/shared';
2
+ import { fsa } from '@chunkd/fs';
3
+ import { HttpHeader, LambdaHttpResponse } from '@linzjs/lambda';
4
+ import { createHash } from 'crypto';
5
+ import { URL } from 'url';
6
+ import { Router } from '../router.js';
7
+ import { NotFound, NotModified } from './response.js';
8
+ import { TileEtag } from './tile.etag.js';
9
+ /**
10
+ * Convert relative URLS into a full hostname url
11
+ * @param url possible url to update
12
+ * @param apiKey ApiKey to append with ?api= if required
13
+ * @returns Updated Url or empty string if url is empty
14
+ */
15
+ export function convertRelativeUrl(url, apiKey) {
16
+ var _a;
17
+ if (url == null)
18
+ return '';
19
+ const host = (_a = Env.get(Env.PublicUrlBase)) !== null && _a !== void 0 ? _a : '';
20
+ if (!url.startsWith('/'))
21
+ return url; // Not relative ignore
22
+ const fullUrl = new URL(fsa.join(host, url));
23
+ if (apiKey)
24
+ fullUrl.searchParams.set('api', apiKey);
25
+ return fullUrl.toString().replace(/%7B/g, '{').replace(/%7D/g, '}');
26
+ }
27
+ export async function styleJson(req, fileName) {
28
+ const apiKey = Router.apiKey(req);
29
+ if (apiKey == null)
30
+ return new LambdaHttpResponse(400, 'Invalid API Key.');
31
+ const styleName = fileName.split('.json')[0];
32
+ // Get style Config from db
33
+ const dbId = Config.Style.id(styleName);
34
+ const styleConfig = await Config.Style.get(dbId);
35
+ if (styleConfig == null)
36
+ return NotFound;
37
+ // Prepare sources and add linz source
38
+ const style = styleConfig.style;
39
+ const sources = {};
40
+ for (const [key, value] of Object.entries(style.sources)) {
41
+ if (value.type === 'vector') {
42
+ value.url = convertRelativeUrl(value.url, apiKey);
43
+ }
44
+ else if (value.type === 'raster' && Array.isArray(value.tiles)) {
45
+ for (let i = 0; i < value.tiles.length; i++) {
46
+ value.tiles[i] = convertRelativeUrl(value.tiles[i], apiKey);
47
+ }
48
+ }
49
+ sources[key] = value;
50
+ }
51
+ // prepare Style.json
52
+ const styleJson = {
53
+ /** Style.json version 8 */
54
+ version: 8,
55
+ id: style.id,
56
+ name: style.name,
57
+ sources,
58
+ layers: style.layers,
59
+ metadata: style.metadata || {},
60
+ glyphs: convertRelativeUrl(style.glyphs),
61
+ sprite: convertRelativeUrl(style.sprite),
62
+ };
63
+ const json = JSON.stringify(styleJson);
64
+ const data = Buffer.from(json);
65
+ const cacheKey = createHash('sha256').update(data).digest('base64');
66
+ if (TileEtag.isNotModified(req, cacheKey))
67
+ return NotModified;
68
+ const response = new LambdaHttpResponse(200, 'ok');
69
+ response.header(HttpHeader.ETag, cacheKey);
70
+ response.header(HttpHeader.CacheControl, 'no-store');
71
+ response.buffer(data, 'application/json');
72
+ req.set('bytes', data.byteLength);
73
+ return response;
74
+ }
@@ -0,0 +1,9 @@
1
+ import { LambdaHttpRequest, LambdaHttpResponse } from '@linzjs/lambda';
2
+ /**
3
+ * Serve a WMTS request
4
+ *
5
+ * /v1/tiles/:tileSet/:tileMatrixSet/WMTSCapabilities.xml
6
+ * @example `/v1/tiles/aerial/NZTM2000Quad/WMTSCapabilities.xml`
7
+ */
8
+ export declare function wmts(req: LambdaHttpRequest): Promise<LambdaHttpResponse>;
9
+ //# sourceMappingURL=tile.wmts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tile.wmts.d.ts","sourceRoot":"","sources":["../../src/routes/tile.wmts.ts"],"names":[],"mappings":"AAGA,OAAO,EAAc,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AASnF;;;;;GAKG;AACH,wBAAsB,IAAI,CAAC,GAAG,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CA8B9E"}
@@ -0,0 +1,57 @@
1
+ import { Config } from '@basemaps/config';
2
+ import { Env, TileSetName, tileWmtsFromPath } from '@basemaps/shared';
3
+ import { HttpHeader, LambdaHttpResponse } from '@linzjs/lambda';
4
+ import { createHash } from 'crypto';
5
+ import { Router } from '../router.js';
6
+ import { TileSets } from '../tile.set.cache.js';
7
+ import { WmtsCapabilities } from '../wmts.capability.js';
8
+ import { NotFound, NotModified } from './response.js';
9
+ import { TileEtag } from './tile.etag.js';
10
+ /**
11
+ * Serve a WMTS request
12
+ *
13
+ * /v1/tiles/:tileSet/:tileMatrixSet/WMTSCapabilities.xml
14
+ * @example `/v1/tiles/aerial/NZTM2000Quad/WMTSCapabilities.xml`
15
+ */
16
+ export async function wmts(req) {
17
+ var _a;
18
+ const action = Router.action(req);
19
+ const wmtsData = tileWmtsFromPath(action.rest);
20
+ if (wmtsData == null)
21
+ return NotFound;
22
+ const host = (_a = Env.get(Env.PublicUrlBase)) !== null && _a !== void 0 ? _a : '';
23
+ req.timer.start('tileset:load');
24
+ const tileSets = await wmtsLoadTileSets(wmtsData.name, wmtsData.tileMatrix);
25
+ req.timer.end('tileset:load');
26
+ if (tileSets.length === 0)
27
+ return NotFound;
28
+ const providerId = Config.Provider.id('linz');
29
+ const provider = await Config.Provider.get(providerId);
30
+ if (provider == null)
31
+ return NotFound;
32
+ const apiKey = Router.apiKey(req);
33
+ const xml = WmtsCapabilities.toXml(host, provider, tileSets, apiKey);
34
+ if (xml == null)
35
+ return NotFound;
36
+ const data = Buffer.from(xml);
37
+ const cacheKey = createHash('sha256').update(data).digest('base64');
38
+ if (TileEtag.isNotModified(req, cacheKey))
39
+ return NotModified;
40
+ const response = new LambdaHttpResponse(200, 'ok');
41
+ response.header(HttpHeader.ETag, cacheKey);
42
+ response.header(HttpHeader.CacheControl, 'max-age=0');
43
+ response.buffer(data, 'text/xml');
44
+ req.set('bytes', data.byteLength);
45
+ return response;
46
+ }
47
+ async function wmtsLoadTileSets(name, tileMatrix) {
48
+ if (tileMatrix != null) {
49
+ const ts = await TileSets.get(name, tileMatrix);
50
+ if (ts == null || ts.isVector())
51
+ return [];
52
+ return [ts];
53
+ }
54
+ if (name === '')
55
+ name = TileSetName.aerial;
56
+ return (await TileSets.getAll(name, tileMatrix)).filter((f) => f.type === 'raster');
57
+ }
@@ -0,0 +1,13 @@
1
+ import { LambdaHttpRequest, LambdaHttpResponse } from '@linzjs/lambda';
2
+ /**
3
+ * Serve a tile
4
+ *
5
+ * /v1/tiles/:tileSet/:tileMatrixSet/:z/:x/:y.:tileType
6
+ *
7
+ * @example
8
+ * Vector Tile `/v1/tiles/topographic/EPSG:3857/2/1/1.pbf`
9
+ * Raster Tile `/v1/tiles/aerial/EPSG:3857/6/0/38.webp`
10
+ * @returns
11
+ */
12
+ export declare function tileXyz(req: LambdaHttpRequest): Promise<LambdaHttpResponse>;
13
+ //# sourceMappingURL=tile.xyz.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tile.xyz.d.ts","sourceRoot":"","sources":["../../src/routes/tile.xyz.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAMvE;;;;;;;;;GASG;AACH,wBAAsB,OAAO,CAAC,GAAG,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAYjF"}
@@ -0,0 +1,28 @@
1
+ import { tileXyzFromPath } from '@basemaps/shared';
2
+ import { Router } from '../router.js';
3
+ import { TileSets } from '../tile.set.cache.js';
4
+ import { ValidateTilePath } from '../validate.js';
5
+ import { NotFound } from './response.js';
6
+ /**
7
+ * Serve a tile
8
+ *
9
+ * /v1/tiles/:tileSet/:tileMatrixSet/:z/:x/:y.:tileType
10
+ *
11
+ * @example
12
+ * Vector Tile `/v1/tiles/topographic/EPSG:3857/2/1/1.pbf`
13
+ * Raster Tile `/v1/tiles/aerial/EPSG:3857/6/0/38.webp`
14
+ * @returns
15
+ */
16
+ export async function tileXyz(req) {
17
+ const action = Router.action(req);
18
+ const xyzData = tileXyzFromPath(action.rest);
19
+ if (xyzData == null)
20
+ return NotFound;
21
+ ValidateTilePath.validate(req, xyzData);
22
+ req.timer.start('tileset:load');
23
+ const tileSet = await TileSets.get(xyzData.name, xyzData.tileMatrix);
24
+ req.timer.end('tileset:load');
25
+ if (tileSet == null)
26
+ return NotFound;
27
+ return await tileSet.tile(req, xyzData);
28
+ }
@@ -3,10 +3,12 @@ import { ConfigImagery, ConfigTileSetRaster, TileSetType } from '@basemaps/confi
3
3
  import { Bounds, Tile, TileMatrixSet } from '@basemaps/geo';
4
4
  import { LogType, TileDataXyz } from '@basemaps/shared';
5
5
  import { Tiler } from '@basemaps/tiler';
6
+ import { TileMakerSharp } from '@basemaps/tiler-sharp';
6
7
  import { CogTiff } from '@cogeotiff/core';
7
8
  import { LambdaHttpRequest, LambdaHttpResponse } from '@linzjs/lambda';
8
9
  import { Metrics } from '@linzjs/metrics';
9
10
  import { TileSetHandler } from './tile.set.js';
11
+ export declare const TileComposer: TileMakerSharp;
10
12
  export interface TileSetResponse {
11
13
  buffer: Buffer;
12
14
  metrics: Metrics;
@@ -1 +1 @@
1
- {"version":3,"file":"tile.set.raster.d.ts","sourceRoot":"","sources":["../src/tile.set.raster.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAe,mBAAmB,EAAqB,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACnH,OAAO,EAAE,MAAM,EAAQ,IAAI,EAAE,aAAa,EAAkB,MAAM,eAAe,CAAC;AAClF,OAAO,EAAoB,OAAO,EAAE,WAAW,EAAqC,MAAM,kBAAkB,CAAC;AAC7G,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,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;AAK1C,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAI/C,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,qBAAa,aAAc,SAAQ,cAAc,CAAC,mBAAmB,CAAC;IACpE,IAAI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AAC,GAAG,EAAE,iBAAiB,EAAE,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,kBAAkB,CAAC;IA8BxF;;;;OAIG;IACI,eAAe,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC,EAAE,OAAO,GAAG,OAAO,EAAE;IAgC5D,OAAO,CAAC,cAAc;IAsBtB,oDAAoD;IACpD,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,aAAa,GAAG,IAAI;IAShD,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,aAAa;CAuBpC"}
@@ -2,14 +2,16 @@ import { TileSetNameParser, TileSetType } from '@basemaps/config';
2
2
  import { Bounds, Epsg, TileMatrixSet, TileMatrixSets } from '@basemaps/geo';
3
3
  import { Config, Env, fsa, titleizeImageryName, VectorFormat } from '@basemaps/shared';
4
4
  import { Tiler } from '@basemaps/tiler';
5
+ import { TileMakerSharp } from '@basemaps/tiler-sharp';
5
6
  import { CogTiff } from '@cogeotiff/core';
6
7
  import { HttpHeader, LambdaHttpResponse } from '@linzjs/lambda';
7
8
  import pLimit from 'p-limit';
9
+ import { NotFound, NotModified } from './routes/response.js';
8
10
  import { TileEtag } from './routes/tile.etag.js';
9
- import { NotFound, NotModified, TileComposer } from './routes/tile.js';
10
11
  import { TiffCache } from './tiff.cache.js';
11
12
  import { TileSetHandler } from './tile.set.js';
12
13
  const LoadingQueue = pLimit(Env.getNumber(Env.TiffConcurrency, 5));
14
+ export const TileComposer = new TileMakerSharp(256);
13
15
  const DefaultResizeKernel = { in: 'lanczos3', out: 'lanczos3' };
14
16
  const DefaultBackground = { r: 0, g: 0, b: 0, alpha: 0 };
15
17
  export class TileSetRaster extends TileSetHandler {
@@ -2,7 +2,7 @@ import { TileSetType } from '@basemaps/config';
2
2
  import { fsa, VectorFormat } from '@basemaps/shared';
3
3
  import { Cotar } from '@cotar/core';
4
4
  import { HttpHeader, LambdaHttpResponse } from '@linzjs/lambda';
5
- import { NotFound } from './routes/tile.js';
5
+ import { NotFound } from './routes/response.js';
6
6
  import { TileSetHandler } from './tile.set.js';
7
7
  class CotarCache {
8
8
  constructor() {