Country posters: the first country highlight no longer freezes on a shader compile

highlightCountryByIso makes the regions fill and border paints data-driven on a click,
and the first such click paid a one-off shader-variant compile (rega measured 5.5 s /
11.1 s on the research map). The three paints are now data-driven from the moment the
layer is added, with identical branches so nothing changes on screen.
This commit is contained in:
Doxa Maps 2026-09-28 06:44:18 +00:00
parent 7c360016fa
commit 16b2e7aeaf

View file

@ -1252,7 +1252,8 @@ async function openPacket() {
//
// library/composables/usePosterPrints.js ALREADY has printPacket: the same pages, authored as HTML
// with @page rules, printed in place. This map was running a private second implementation of a
// shared product feature. Routing to it deletes the duplicate, drops jspdf from this bundle, and
// shared product feature. Routing to it deletes the duplicate (jspdf itself stays: useMapPoster.toPdf
// still brings it in for the poster, and the bundle grew with the HTML renderer), and
// the packet gains the pages the shared renderer has that the local one never did (the life
// calendar, the funnel, the prayer wheel — see packet-render.buildPacket's page order).
const [{ usePosterPrints }, { defaultPosterSpec }, { useMapPoster }] = await Promise.all([
@ -1407,6 +1408,19 @@ async function ensureRegionsLoaded() {
const regionsData = await mapData.loadRegionsData?.()
if (regionsData && map.value) {
mapLayers.addRegionsLayer?.(regionsData, 'doxa-regions')
// PRE-WARM the shader variant here, while a large GeoJSON is loading anyway. highlightCountryByIso
// turns these three paints DATA-DRIVEN on a click; the first time that costs a one-off shader
// compile (rega on research-map: 5.5 s MapLibre / 11.1 s Mapbox under SwiftShader). Painting each
// current value through a case with two identical branches keeps the look and moves the compile
// off the gesture. All three, or the other two still compile on the click (simpleresearch).
for (const [layer, prop] of [['regions-fill', 'fill-opacity'], ['regions-border', 'line-color'], ['regions-border', 'line-width']]) {
try {
const v = map.value.getLayer(layer) && map.value.getPaintProperty(layer, prop)
if (v != null && !Array.isArray(v)) {
map.value.setPaintProperty(layer, prop, ['case', ['in', ['get', 'iso_3166_1_alpha_3'], ['literal', []]], v, v])
}
} catch (_) { /* a style without the layer: nothing to warm */ }
}
// Hide regions on non-Doxa-Regions tabs so they don't show through.
if (map.value.getLayer('regions-fill') && activeTab.value?.id !== 'doxa-regions') {
map.value.setLayoutProperty('regions-fill', 'visibility', 'none')