base checkbox; start filter toggle

This commit is contained in:
Bavo Vanderghote 2020-07-22 11:01:25 +02:00
parent 0f2a2c651a
commit f610b956dc
6 changed files with 86 additions and 40 deletions

View file

@ -107,11 +107,8 @@ export class LayerDefinition {
showOnPopup: (tags: UIEventSource<(any)>) => UIElement): showOnPopup: (tags: UIEventSource<(any)>) => UIElement):
FilteredLayer { FilteredLayer {
return new FilteredLayer( return new FilteredLayer(
this.name, this,
basemap, allElements, changes, basemap, allElements, changes,
this.overpassFilter,
this.maxAllowedOverlapPercentage,
this.style,
selectedElement, selectedElement,
showOnPopup); showOnPopup);

View file

@ -6,6 +6,7 @@ import { Changes } from "./Changes";
import L from "leaflet" import L from "leaflet"
import { GeoOperations } from "./GeoOperations"; import { GeoOperations } from "./GeoOperations";
import { UIElement } from "../UI/UIElement"; import { UIElement } from "../UI/UIElement";
import { LayerDefinition } from "../Customizations/LayerDefinition";
/*** /***
* A filtered layer is a layer which offers a 'set-data' function * A filtered layer is a layer which offers a 'set-data' function
@ -21,7 +22,7 @@ export class FilteredLayer {
public readonly name: string; public readonly name: string;
public readonly filters: TagsFilter; public readonly filters: TagsFilter;
public readonly isDisplayed: UIEventSource<boolean> = new UIEventSource(true); public readonly isDisplayed: UIEventSource<boolean> = new UIEventSource(true);
public readonly layerDef: LayerDefinition;
private readonly _map: Basemap; private readonly _map: Basemap;
private readonly _maxAllowedOverlap: number; private readonly _maxAllowedOverlap: number;
@ -43,29 +44,26 @@ export class FilteredLayer {
private _showOnPopup: (tags: UIEventSource<any>) => UIElement; private _showOnPopup: (tags: UIEventSource<any>) => UIElement;
constructor( constructor(
name: string, layerDef: LayerDefinition,
map: Basemap, storage: ElementStorage, map: Basemap, storage: ElementStorage,
changes: Changes, changes: Changes,
filters: TagsFilter,
maxAllowedOverlap: number,
style: ((properties) => any),
selectedElement: UIEventSource<any>, selectedElement: UIEventSource<any>,
showOnPopup: ((tags: UIEventSource<any>) => UIElement) showOnPopup: ((tags: UIEventSource<any>) => UIElement)
) { ) {
this.layerDef = layerDef;
this._selectedElement = selectedElement; this._selectedElement = selectedElement;
this._showOnPopup = showOnPopup; this._showOnPopup = showOnPopup;
this._style = layerDef.style;
if (style === undefined) { if (this._style === undefined) {
style = function () { this._style = function () {
return {}; return {icon: "", color: "#000000"};
} }
} }
this.name = name; this.name = name;
this._map = map; this._map = map;
this.filters = filters; this.filters = layerDef.overpassFilter;
this._style = style;
this._storage = storage; this._storage = storage;
this._maxAllowedOverlap = maxAllowedOverlap; this._maxAllowedOverlap = layerDef.maxAllowedOverlapPercentage;
const self = this; const self = this;
this.isDisplayed.addCallback(function (isDisplayed) { this.isDisplayed.addCallback(function (isDisplayed) {
if (self._geolayer !== undefined && self._geolayer !== null) { if (self._geolayer !== undefined && self._geolayer !== null) {

View file

@ -5,14 +5,28 @@ import { FilteredLayer } from "../../Logic/FilteredLayer";
export class CheckBox extends UIElement{ export class CheckBox extends UIElement{
constructor(data: UIEventSource<boolean>, name: String) { private readonly _data: UIEventSource<boolean>;
private readonly _showEnabled: string|UIElement;
private readonly _showDisabled: string|UIElement;
constructor(data: UIEventSource<boolean>, showEnabled: string|UIElement, showDisabled: string|UIElement) {
super(data); super(data);
this.data = data; this._data = data;
this.name = name this._showEnabled = showEnabled;
this._showDisabled = showDisabled;
this.onClick(() => {
data.setData(!data.data);
})
} }
protected InnerRender(): string { protected InnerRender(): string {
return `${this.data.data? `<svg class="checkbox__check" width="28" height="20" viewBox="0 0 28 20" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M2.5 8L11.5 17L25.5 3" stroke="#003B8B" stroke-width="5" stroke-linecap="round" stroke-linejoin="round"/></svg><p class="checkbox__label--checked">${this.name}</p>`: `<p class="checkbox__label--unchecked">${this.name}</p>`}`; if (this._data.data) {
return this._showEnabled;
} else {
return this._showDisabled;
}
} }
} }

View file

@ -254,18 +254,42 @@ form {
pointer-events: all; pointer-events: all;
} }
#filterui { /* filter ui */
padding: 2em;
padding-top: 1em; .filter__popup {
padding-bottom: 1em; display: none;
z-index: 5000; position: absolute;
background-color: white; bottom: 0;
border-radius: 2em; z-index: 500;
pointer-events: all; padding-left: 10px;
list-style: none; padding-bottom: 10px;
display: flex;
flex-flow: column-reverse;
align-items: start;
} }
#filterui li span { .filter__button {
outline: none;
border: none;
padding: 1rem;
border-radius: 50%;
box-shadow: 0px 2px 6px rgba(0, 0, 0, 0.25);
background-color: white;
}
.filter__content {
background-color: white;
border-radius: 15px;
padding: 0 15px;
}
#filter__layers {
pointer-events: all;
list-style: none;
padding-left: 0;
}
#filter__layers li span {
display: flex; display: flex;
align-items: center; align-items: center;
} }

View file

@ -36,10 +36,23 @@
<div id="collapseButton"></div> <div id="collapseButton"></div>
<div id="messagesbox"></div> <div id="messagesbox"></div>
</div> </div>
<ul id="filterui">
</ul>
</div> </div>
<div id="filter__popup" class="filter__popup">
<!-- <div class="filter__popup--wrapper"> -->
<button id="filter__button" class="filter__button">
<svg width="27" height="27" viewBox="0 0 27 27" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M26.5353 8.13481C26.4422 8.35428 26.2683 8.47598 26.0632 8.58537C21.9977 10.7452 17.935 12.9085 13.8758 15.0799C13.6475 15.2016 13.4831 15.1962 13.2568 15.0751C9.19822 12.903 5.13484 10.7404 1.07215 8.5758C0.490599 8.26608 0.448478 7.52562 0.991303 7.13796C1.0803 7.07438 1.17813 7.0231 1.2746 6.97045C5.15862 4.86462 9.04536 2.7629 12.9246 0.648187C13.3805 0.399316 13.7779 0.406837 14.2311 0.65434C18.0954 2.76153 21.9658 4.85779 25.8383 6.94926C26.1569 7.12155 26.411 7.32872 26.5353 7.67604C26.5353 7.82919 26.5353 7.98166 26.5353 8.13481Z" fill="#003B8B"/>
<path d="M13.318 26.535C12.1576 25.9046 10.9972 25.2736 9.83614 24.6439C6.96644 23.0877 4.09674 21.533 1.22704 19.9762C0.694401 19.6876 0.466129 19.2343 0.669943 18.7722C0.759621 18.5691 0.931505 18.3653 1.11969 18.2512C1.66659 17.9182 2.23727 17.6228 2.80863 17.3329C2.89423 17.2892 3.04981 17.3206 3.14493 17.3712C6.40799 19.1031 9.66969 20.837 12.9239 22.5845C13.3703 22.8238 13.7609 22.83 14.208 22.59C17.4554 20.8472 20.7117 19.1202 23.9605 17.3801C24.1493 17.2789 24.2838 17.283 24.4632 17.3876C24.8926 17.6386 25.3301 17.8772 25.7751 18.1001C26.11 18.2683 26.3838 18.4857 26.5346 18.8385C26.5346 18.9916 26.5346 19.1441 26.5346 19.2972C26.4049 19.6528 26.1399 19.8613 25.8152 20.0363C22.9964 21.5549 20.1831 23.0829 17.3684 24.609C16.1863 25.2496 15.0055 25.893 13.8248 26.535C13.6556 26.535 13.4865 26.535 13.318 26.535Z" fill="#003B8B"/>
<path d="M26.3988 13.7412C26.2956 13.9661 26.1026 14.081 25.8927 14.1924C21.8198 16.3577 17.749 18.5258 13.6815 20.7013C13.492 20.8025 13.3602 20.7902 13.1795 20.6938C9.09638 18.5114 5.01059 16.3359 0.924798 14.1582C0.399637 13.8786 0.307921 13.2646 0.735251 12.838C0.829005 12.7443 0.947217 12.6705 1.06407 12.6055C1.56545 12.3279 2.07635 12.0654 2.57297 11.7789C2.74214 11.6812 2.86579 11.6921 3.03291 11.7817C6.27492 13.5155 9.52303 15.2378 12.761 16.9792C13.2352 17.2343 13.6394 17.2322 14.1129 16.9772C17.3509 15.2358 20.5996 13.5142 23.8416 11.7796C24.0095 11.69 24.1338 11.6818 24.3016 11.7789C24.7384 12.0339 25.1821 12.2794 25.6352 12.5037C25.9701 12.6691 26.2426 12.8831 26.3995 13.2304C26.3988 13.4014 26.3988 13.5716 26.3988 13.7412Z" fill="#003B8B"/>
</svg>
</button>
<div class="filter__content">
<p>Maplayers</p>
<ul id="filter__layers"></ul>
</div>
<!-- </div> -->
</div>
<div id="centermessage"></div> <div id="centermessage"></div>
<div id="bottomRight" style="display: none">ADD</div> <div id="bottomRight" style="display: none">ADD</div>

View file

@ -288,13 +288,13 @@ messageBox.update();
for (let i = 0; i < flayers.length; i++) { for (let i = 0; i < flayers.length; i++) {
const listItem = document.createElement(`li`); const listItem = document.createElement(`li`);
listItem.setAttribute(`id`,`${flayers[i].name}`) listItem.setAttribute(`id`,`${flayers[i].name}`)
document.querySelector(`#filterui`).appendChild(listItem); document.querySelector(`#filter__layers`).appendChild(listItem);
const eventSource = new UIEventSource(flayers[i].isDisplayed.data); new CheckBox(flayers[i].isDisplayed, flayers[i])
new CheckBox(eventSource, flayers[i].name)
.onClick(() => {
eventSource.setData(!eventSource.data);
flayers[i].isDisplayed.setData(eventSource.data);
})
.AttachTo(flayers[i].name); .AttachTo(flayers[i].name);
} }
// --------------- Setting up toggle button for filter ui --------
document.querySelector(`#filter__button`).addEventListener(`click`, e => {
document.querySelector(`#filter__popup`).classList.toggle(`filter__popup--show`)
});