From e34214fe32cafb19d871d3e20a2c5ad80de56a20 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 11 Jun 2022 16:39:34 -0700 Subject: Handle missing style selection --- modern/src/map/switcher/switcher.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'modern/src') diff --git a/modern/src/map/switcher/switcher.js b/modern/src/map/switcher/switcher.js index 60a5eff7..d96f7ffc 100644 --- a/modern/src/map/switcher/switcher.js +++ b/modern/src/map/switcher/switcher.js @@ -16,7 +16,16 @@ export class SwitcherControl { updateStyles(updatedStyles, defaultStyle) { this.styles = updatedStyles; - const selectedStyle = this.currentStyle || defaultStyle; + let selectedStyle = null; + for (const style of this.styles) { + if (style.id === (this.currentStyle || defaultStyle)) { + selectedStyle = style.id; + break; + } + } + if (!selectedStyle) { + this.styles[0].id; + } while (this.mapStyleContainer.firstChild) { this.mapStyleContainer.removeChild(this.mapStyleContainer.firstChild); -- cgit v1.2.3