chiitiler 1.21.0 → 1.21.2

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.
@@ -53,6 +53,10 @@ async function getRenderedTile({ stylejson, z, x, y, tileSize, cache, margin, ex
53
53
  width: 512,
54
54
  height: 512,
55
55
  channels: 4,
56
+ // maplibre-native returns premultiplied alpha; tell sharp so it
57
+ // unpremultiplies to straight alpha, otherwise antialiased edges
58
+ // (e.g. white text-halo) come out gray on transparent backgrounds.
59
+ premultiplied: true,
56
60
  },
57
61
  }).resize(256, 256);
58
62
  }
@@ -62,6 +66,7 @@ async function getRenderedTile({ stylejson, z, x, y, tileSize, cache, margin, ex
62
66
  width: tileSize,
63
67
  height: tileSize,
64
68
  channels: 4,
69
+ premultiplied: true,
65
70
  },
66
71
  });
67
72
  }
@@ -71,6 +76,7 @@ async function getRenderedTile({ stylejson, z, x, y, tileSize, cache, margin, ex
71
76
  width: tileSize + margin,
72
77
  height: tileSize + margin,
73
78
  channels: 4,
79
+ premultiplied: true,
74
80
  },
75
81
  })
76
82
  .extract({
@@ -125,6 +131,8 @@ async function getRenderedClip({ stylejson, bbox, size, cache, ext, quality, })
125
131
  width,
126
132
  height,
127
133
  channels: 4,
134
+ // see getRenderedTile: maplibre-native returns premultiplied alpha
135
+ premultiplied: true,
128
136
  },
129
137
  });
130
138
  switch (ext) {
@@ -152,6 +160,8 @@ async function getRenderedCamera(options) {
152
160
  width: options.width,
153
161
  height: options.height,
154
162
  channels: 4,
163
+ // see getRenderedTile: maplibre-native returns premultiplied alpha
164
+ premultiplied: true,
155
165
  },
156
166
  });
157
167
  switch (options.ext) {
@@ -1,28 +1,10 @@
1
- import * as path from 'path';
2
1
  import mbgl from '@maplibre/maplibre-gl-native';
3
2
  import { Pool } from 'lightning-pool';
4
3
  import { LRUCache } from 'lru-cache';
5
4
  import { getSource } from '../source/index.js';
6
- const EMPTY_BUFFER = Buffer.alloc(0);
7
- const TRANSPARENT_BUFFER = {
8
- // 1x1 transparent images
9
- png: Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR4nGP4//8/AwAI/AL+p5qgoAAAAABJRU5ErkJggg==', 'base64'),
10
- webp: Buffer.from('UklGRkAAAABXRUJQVlA4WAoAAAAQAAAAAAAAAAAAQUxQSAIAAAAAAFZQOCAYAAAAMAEAnQEqAQABAAFAJiWkAANwAP789AAA', 'base64'),
11
- jpeg: Buffer.from('/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAABAAEDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD3+iiigD//2Q=='),
12
- };
13
- function handleFileExt(uri) {
14
- if (uri.startsWith('cog://'))
15
- return 'png'; // cog:// always returns as png
16
- // extract extension only, take into account query string or hash
17
- const basename = path.basename(uri).split(/[?#]/)[0];
18
- const ext = basename.split('.').pop();
19
- if (ext === undefined)
20
- return null;
21
- const l = ext.toLowerCase();
22
- if (l === 'jpeg')
23
- return 'jpg';
24
- return l;
25
- }
5
+ // mbglはdataプロパティが無いレスポンスを「データなしタイル」として正常に扱う。
6
+ // 型定義はdataを必須としているが、空タイルを表現するには渡さないのが正解。
7
+ const EMPTY_RESPONSE = {};
26
8
  const mapPoolCache = new LRUCache({
27
9
  max: 10,
28
10
  dispose: (pool, key) => {
@@ -38,26 +20,18 @@ async function getRenderPool(style, cache, mode) {
38
20
  create: () => {
39
21
  const map = new mbgl.Map({
40
22
  request: function (req, callback) {
41
- const ext = handleFileExt(req.url);
42
23
  getSource(req.url, cache)
43
24
  .then((buf) => {
44
- if (buf) {
25
+ if (buf !== null && buf.length > 0) {
45
26
  callback(undefined, { data: buf });
46
27
  }
47
- else if (ext && TRANSPARENT_BUFFER[ext])
48
- callback(undefined, {
49
- data: TRANSPARENT_BUFFER[ext],
50
- });
51
- else
52
- callback(undefined, { data: EMPTY_BUFFER });
28
+ else {
29
+ // 204/空ボディ/404: 空タイルとして扱わせる
30
+ callback(undefined, EMPTY_RESPONSE);
31
+ }
53
32
  })
54
33
  .catch(() => {
55
- if (ext && TRANSPARENT_BUFFER[ext])
56
- callback(undefined, {
57
- data: TRANSPARENT_BUFFER[ext],
58
- });
59
- else
60
- callback(undefined, { data: EMPTY_BUFFER });
34
+ callback(undefined, EMPTY_RESPONSE);
61
35
  });
62
36
  },
63
37
  ratio: 1,
@@ -13,7 +13,12 @@ async function getHttpSource(uri, cache = noneCache()) {
13
13
  console.log(`failed to fetch ${uri}`);
14
14
  return null;
15
15
  }
16
+ // 204/空ボディはキャッシュ汚染を避けるため書き込まずnullを返す
17
+ if (res.status === 204)
18
+ return null;
16
19
  const buf = Buffer.from(await res.arrayBuffer());
20
+ if (buf.length === 0)
21
+ return null;
17
22
  cache.set(uri, buf);
18
23
  return buf;
19
24
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "chiitiler",
4
- "version": "1.21.0",
4
+ "version": "1.21.2",
5
5
  "description": "Tiny map rendering server for MapLibre Style Spec",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",