fix: stabilize S-52 sprite registration
This commit is contained in:
@@ -667,7 +667,13 @@ async function loadS52SpriteAtlas(){
|
||||
});
|
||||
return {metadata:metadata,image:image};
|
||||
})();
|
||||
return s52SpriteAtlasPromise;
|
||||
try{
|
||||
return await s52SpriteAtlasPromise;
|
||||
}catch(err){
|
||||
// Do not permanently cache a transient fetch/image failure.
|
||||
s52SpriteAtlasPromise=null;
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
async function ensureS52SpriteImages(map){
|
||||
@@ -726,7 +732,9 @@ function prepareS52Style(raw){
|
||||
source.maxzoom=12;
|
||||
source.bounds=[128.0,29.5,132.5,34.8];
|
||||
source.attribution="CM95 九州当前 S-52 Production";
|
||||
style.sprite=location.origin + "/s52/sprite";
|
||||
// Dynamic setStyle() and MapLibre's automatic sprite loader are unreliable
|
||||
// in this comparison page. Register S-52 images explicitly after style.load.
|
||||
delete style.sprite;
|
||||
if(referenceStyleTemplate && referenceStyleTemplate.glyphs){
|
||||
style.glyphs=referenceStyleTemplate.glyphs;
|
||||
}
|
||||
@@ -745,6 +753,9 @@ async function ensureS52StyleTemplate(){
|
||||
async function applyLeftStyleMode(){
|
||||
if(debugLeftS52.checked){
|
||||
setState(leftState,"加载完整 S-52 style…","");
|
||||
// Prefetch the atlas before setStyle so style.load only has to register
|
||||
// already-local pixels; this avoids transient fetch failures mid-style swap.
|
||||
await loadS52SpriteAtlas();
|
||||
const raw=await ensureS52StyleTemplate();
|
||||
const style=prepareS52Style(raw);
|
||||
activeLeftStyleTemplate=style;
|
||||
|
||||
Reference in New Issue
Block a user