-
Notifications
You must be signed in to change notification settings - Fork 62
/
poi.js
41 lines (34 loc) · 1.19 KB
/
poi.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { transposeImageData } from "@americana/maplibre-shield-generator";
export function missingIconHandler(shieldRenderer, map, e) {
try {
missingIconLoader(shieldRenderer, map, e);
} catch (err) {
console.error(`Exception while loading image ‘${e?.id}’:\n`, err);
}
}
export function missingIconLoader(shieldRenderer, map, e) {
var sprite = e.id.split("\n")[1].split("=")[1];
var color = e.id.split("\n")[2].split("=")[1];
var sourceSprite = map.style.getImage(sprite);
var width = sourceSprite.data.width;
var height = sourceSprite.data.height;
var ctx = shieldRenderer.createGraphics({ width, height });
transposeImageData(ctx, sourceSprite, 0, false, color);
if (ctx == null) {
// Want to return null here, but that gives a corrupted display. See #243
console.warn("Didn't produce an icon for", JSON.stringify(e.id));
ctx = shieldRenderer.createGraphics({ width: 1, height: 1 });
}
const imgData = ctx.getImageData(0, 0, ctx.canvas.width, ctx.canvas.height);
map.addImage(
e.id,
{
width: ctx.canvas.width,
height: ctx.canvas.height,
data: imgData.data,
},
{
pixelRatio: shieldRenderer.pixelRatio(),
}
);
}