From b13025c777b345365324fa62deaaae7cc97738d7 Mon Sep 17 00:00:00 2001 From: Candid Dauth Date: Sat, 2 Mar 2024 14:13:48 +0100 Subject: [PATCH] Optimize setting line style --- leaflet/src/lines/lines-layer.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/leaflet/src/lines/lines-layer.ts b/leaflet/src/lines/lines-layer.ts index 62d991c5..908643ed 100644 --- a/leaflet/src/lines/lines-layer.ts +++ b/leaflet/src/lines/lines-layer.ts @@ -270,7 +270,13 @@ export default class LinesLayer extends FeatureGroup { } (this.linesById[line.id] as any).line = line; - this.linesById[line.id].setLatLngs(splitLatLngs).setStyle(style); + + // Set style before setting coordinates, so a new line doesn't have to be rendered twice + if (Object.entries(style).some(([k, v]) => (this.linesById[line.id].realOptions as any)[k] !== v)) { + this.linesById[line.id].setStyle(style); + } + + this.linesById[line.id].setLatLngs(splitLatLngs); if (line.name && line.id != null) { // We don't want a popup for lines that we are drawing right now const quoted = quoteHtml(line.name);