From e2ae83536eca3bde66e2ebf5e1fc28e9b6826bb7 Mon Sep 17 00:00:00 2001 From: Bavo Vanderghote Date: Wed, 22 Jul 2020 12:05:29 +0200 Subject: [PATCH] toggle filter --- UI/Base/CheckBox.ts | 7 ++++--- UI/LayerSelection.ts | 6 +++--- index.ts | 3 ++- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/UI/Base/CheckBox.ts b/UI/Base/CheckBox.ts index ba8085e..34c568b 100644 --- a/UI/Base/CheckBox.ts +++ b/UI/Base/CheckBox.ts @@ -11,13 +11,14 @@ export class CheckBox extends UIElement{ private readonly _showEnabled: string|UIElement; private readonly _showDisabled: string|UIElement; - constructor(data: UIEventSource, showEnabled: string|UIElement, showDisabled: string|UIElement) { + constructor(showEnabled: string|UIElement, showDisabled: string|UIElement, data: UIEventSource = undefined) { super(data); - this._data = data; + this._data = data??new UIEventSource(false); this._showEnabled = showEnabled; this._showDisabled = showDisabled; + const self = this; this.onClick(() => { - data.setData(!data.data); + self._data.setData(!self._data.data); }) diff --git a/UI/LayerSelection.ts b/UI/LayerSelection.ts index bdb3ee4..25b9684 100644 --- a/UI/LayerSelection.ts +++ b/UI/LayerSelection.ts @@ -12,9 +12,9 @@ export class LayerSelection extends UIElement{ this._checkboxes = []; for (const layer of layers) { this._checkboxes.push(new CheckBox( - layer.isDisplayed, - new Combine([layer.layerDef.name, `${layer.layerDef.icon}`]), - layer.layerDef.name)); + new Combine([layer.layerDef.name, `layer.layerDef.icon`]), + layer.layerDef.name, + layer.isDisplayed)); } } diff --git a/index.ts b/index.ts index 30798b2..f6dcf70 100644 --- a/index.ts +++ b/index.ts @@ -314,7 +314,8 @@ locationControl.ping(); // --------------- Setting up filter ui -------- -new LayerSelection(flayers).AttachTo("filter__selection"); +new CheckBox(new LayerSelection(flayers), `Click here`).AttachTo("filter__selection") + // --------------- Setting up toggle button for filter ui --------