From c05a4ea68f0022be16c7196fcb2c6170d9bc8cb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Viricel?= Date: Tue, 22 Oct 2024 16:39:09 +0200 Subject: [PATCH] fix: keep isochrone across style changing #359 --- components/Map/Map.vue | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/components/Map/Map.vue b/components/Map/Map.vue index cbb5a259..ebfcde39 100644 --- a/components/Map/Map.vue +++ b/components/Map/Map.vue @@ -286,7 +286,25 @@ export default defineNuxtComponent({ this.style = style this.doWithMap(() => { // Use no diff mode to avoid issue with added layers - this.map!.setStyle(style, { diff: false }) + this.map!.setStyle(style, { + diff: false, + transformStyle: (previousStyle, nextStyle) => { + if (previousStyle?.sources.isochrone) { + style = { + ...nextStyle, + sources: { + ...nextStyle.sources, + isochrone: previousStyle.sources.isochrone, + }, + layers: [ + ...nextStyle.layers, + ...previousStyle.layers.filter(l => l.id.includes('isochrone')), + ], + } + } + return style + }, + }) this.emitStyleLoad() }) })