Skip to content

Commit

Permalink
Defer updating Layer’s layout and paint properties until Map style is…
Browse files Browse the repository at this point in the history
… fully loaded (#204)

* Defer setting layer layout and paint during style load

* Check map.style._loaded instead of map.isStyleLoaded()
  • Loading branch information
ciscorn authored Oct 3, 2024
1 parent d3fab1c commit 4cbae2d
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/lib/Layer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 4cbae2d

Please sign in to comment.