From 4cbae2d5586f5606beb2124c6e81819ac1e82210 Mon Sep 17 00:00:00 2001 From: Taku Fukada Date: Fri, 4 Oct 2024 05:21:33 +0900 Subject: [PATCH] =?UTF-8?q?Defer=20updating=20Layer=E2=80=99s=20layout=20a?= =?UTF-8?q?nd=20paint=20properties=20until=20Map=20style=20is=20fully=20lo?= =?UTF-8?q?aded=20(#204)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Defer setting layer layout and paint during style load * Check map.style._loaded instead of map.isStyleLoaded() --- src/lib/Layer.svelte | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/lib/Layer.svelte b/src/lib/Layer.svelte index 418e582..b636718 100644 --- a/src/lib/Layer.svelte +++ b/src/lib/Layer.svelte @@ -279,14 +279,28 @@ }); $: applyPaint = $layer - ? diffApplier((key, value) => $map?.setPaintProperty($layer!, key, value)) - : undefined; + ? diffApplier((key, value) => { + if ($map?.style._loaded) { + $map.setPaintProperty($layer!, key, value); + } else { + $map?.once('styledata', () => $map?.setPaintProperty($layer!, key, value)); + } + }) + : void 0; + $: applyLayout = $layer - ? diffApplier((key, value) => $map?.setLayoutProperty($layer!, key, value)) - : undefined; + ? diffApplier((key, value) => { + if ($map?.style._loaded) { + $map.setLayoutProperty($layer!, key, value); + } else { + $map?.once('styledata', () => $map?.setLayoutProperty($layer!, key, value)); + } + }) + : void 0; $: applyPaint?.(paint); $: applyLayout?.(layout); + $: if ($layer) $map?.setLayerZoomRange($layer, actualMinZoom, actualMaxZoom); // Don't set the filter again after we've just created it.