Replies: 3 comments 1 reply
-
Here is a patch that works, but I do not know if this is the place to solve this. diff --git a/src/style/load_sprite.ts b/src/style/load_sprite.ts
index 391317442..6252c4c9a 100644
--- a/src/style/load_sprite.ts
+++ b/src/style/load_sprite.ts
@@ -64,7 +64,14 @@ async function doOnceCompleted(
result[spriteName] = {};
const context = browser.getImageCanvasContext((await imagesMap[spriteName]).data);
- const json = (await jsonsMap[spriteName]).data;
+ const jsonResponseData = (await jsonsMap[spriteName]).data;
+
+ var json
+ if (jsonResponseData instanceof ArrayBuffer) {
+ json = JSON.parse(new TextDecoder().decode(jsonResponseData as ArrayBuffer));
+ } else {
+ json = jsonResponseData;
+ }
for (const id in json) {
const {width, height, x, y, sdf, pixelRatio, stretchX, stretchY, content, textFitWidth, textFitHeight} = json[id];
|
Beta Was this translation helpful? Give feedback.
0 replies
-
It is also possible to work around this problem by parsing the JSON in the // internal:// links handled generally, but not by maplibre. this is an attempt to work around that problem
maplibregl.addProtocol('internal', async (params, abortController) => {
const t = ...;
if (t.status == 200 || t.status == 0) {
const buffer = await t.arrayBuffer();
// work around https://github.com/maplibre/maplibre-gl-js/issues/5002
if (params.url.includes("sprite") && params.url.endsWith(".json")) {
const parsedJSON = JSON.parse(new TextDecoder().decode(buffer));
return {'data': parsedJSON}
}
return {'data': buffer}
} else {
throw new Error('got status: ' + t.status + ' ' + t.statusText + ' for: ' + params.url);
}
}); |
Beta Was this translation helpful? Give feedback.
0 replies
-
You need the maplibregl.addProtocol('internal', async (params, abortController) => {
const fixedUrl = params.url.replace('internal://', 'https://')
const t = await fetch(fixedUrl);
if (t.status == 200 || t.status == 0) {
if (fixedUrl.includes(".json")) {
const text = await t.text();
return {
'data': JSON.parse(text)
}
} else {
const buffer = await t.arrayBuffer();
return {
'data': buffer
}
}
} else {
throw new Error('got status: ' + t.status + ' ' + t.statusText + ' for: ' + params.url);
}
}); |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
maplibre-gl-js version: main branch
browser: Safari
Steps to Trigger Behavior
maplibregl.addProtocol('internal'...
Link to Demonstration
https://jsbin.com/jusasoy/5/edit?html,output
Expected Behavior
See the map with 3 red circles that each have an airplane icon in them.

Actual Behavior
Can see map with 3 red circles, but without airplane icons.

Beta Was this translation helpful? Give feedback.
All reactions