add: multi select filter

v0.3
rrr-marble 4 years ago
parent 75d97dee8d
commit c48199276c

@ -6,7 +6,7 @@
<gis-category-filter @filter="$emit('filter', $event)" /> <gis-category-filter @filter="$emit('filter', $event)" />
<h3>Scanner</h3> <h3>Scanner</h3>
<scanner-filter @filter="$emit('filter', $event)" /> <scanner-filter @filter="$emit('filter', $event)" />
<h3>Organiztion</h3> <h3>Organization</h3>
<org-filter @filter="$emit('filter', $event)" /> <org-filter @filter="$emit('filter', $event)" />
<h3>Stratum</h3> <h3>Stratum</h3>
<stratum-filter @filter="$emit('filter', $event)" /> <stratum-filter @filter="$emit('filter', $event)" />

@ -7,13 +7,13 @@
<script> <script>
import maplibregl from "maplibre-gl"; import maplibregl from "maplibre-gl";
import { markRaw, onMounted, onUnmounted, shallowRef, } from "vue"; import { markRaw, onMounted, onUnmounted, reactive, shallowRef, } from "vue";
export default { export default {
name: "map-component", name: "map-component",
setup(_props, context) { setup(_props, context) {
const mapContainer = shallowRef(null); const mapContainer = shallowRef(null);
const map = shallowRef(null); const map = shallowRef(null);
let currentFadr = { "fadr": "Any" }; let currentFadr = reactive({ "fadr": [] });
onMounted(() => { onMounted(() => {
const apiKey = "pk.eyJ1IjoiZ2hlcm1hbnQiLCJhIjoiY2pncDUwcnRmNDQ4ZjJ4czdjZXMzaHZpNyJ9.3rFyYRRtvLUngHm027HZ7A"; const apiKey = "pk.eyJ1IjoiZ2hlcm1hbnQiLCJhIjoiY2pncDUwcnRmNDQ4ZjJ4czdjZXMzaHZpNyJ9.3rFyYRRtvLUngHm027HZ7A";
@ -103,40 +103,38 @@ export default {
.setLngLat(e.lngLat) .setLngLat(e.lngLat)
.setHTML(JSON.stringify(e.features[0].properties)) .setHTML(JSON.stringify(e.features[0].properties))
.addTo(map.value); .addTo(map.value);
let fadr = { let newFadr = e.features[0].properties["fadr"];
"fadr": e.features[0].properties["fadr"]
}; let newFadrFound = currentFadr["fadr"].indexOf(newFadr)
fadr = currentFadr["fadr"] == fadr["fadr"] ? if (newFadrFound > -1) {
{ "fadr": "Any" } : //remove old paint
fadr;
// check if we need to remove any old paint
if (currentFadr["fadr"] !== "Any") {
map.value.setFeatureState( map.value.setFeatureState(
{ {
source: 'samples', source: 'samples',
sourceLayer: 'public.geodata', sourceLayer: 'public.geodata',
id: currentFadr["fadr"] id: newFadr
}, },
{ beenClicked: false } { beenClicked: false }
); );
};
// check if we need to apply any new paint // remove from filters
if (fadr["fadr"] !== "Any") { currentFadr["fadr"].splice(newFadrFound, 1)
} else {
// apply new paint
map.value.setFeatureState( map.value.setFeatureState(
{ {
source: 'samples', source: 'samples',
sourceLayer: 'public.geodata', sourceLayer: 'public.geodata',
id: fadr["fadr"] id: newFadr
}, },
{ beenClicked: true } { beenClicked: true }
); );
};
currentFadr = fadr; // add to filters
currentFadr["fadr"].push(newFadr);
}
context.emit('mapClick', fadr); context.emit('mapClick', currentFadr);
}); });
}); });

@ -1,6 +1,6 @@
<template> <template>
<div> <div>
<va-sidebar color="primary" text-color="white" gradient class="sidebar-proper"> <va-sidebar color="primary" text-color="white" gradient class="sidebar-proper" width="18rem">
<slot></slot> <slot></slot>
</va-sidebar> </va-sidebar>
</div> </div>

@ -1,13 +1,8 @@
<template> <template>
<div> <div>
<va-radio <va-select class="multi-selector" :options="categoryOptions" v-model="selectedOptions"
class="radio-switcher" @update:model-value="applyFilter" multiple searchable>
v-for="(option, index) in categoryOptions" </va-select>
:key="index"
v-model="selectedOption"
:option="option"
@update:model-value="applyFilter"
></va-radio>
</div> </div>
</template> </template>
@ -22,15 +17,13 @@ export default {
"Biology", "Biology",
"Archeology", "Archeology",
"Materials", "Materials",
"Any"
], ],
selectedOption: "Any" selectedOptions: [],
} }
}, },
methods: { methods: {
applyFilter() { applyFilter() {
const filter = { "category": this.selectedOptions }
const filter = { "category": this.selectedOption }
this.$emit('filter', filter, this.name) this.$emit('filter', filter, this.name)
}, },
}, },
@ -39,4 +32,7 @@ export default {
<style lang="css"> <style lang="css">
.multi-selector {
--va-select-min-width: 12 rem;
}
</style> </style>

@ -1,13 +1,8 @@
<template> <template>
<div> <div>
<va-radio <va-select class="multi-selector" :options="categoryOptions" v-model="selectedOptions"
class="radio-switcher" @update:model-value="applyFilter" multiple searchable>
v-for="(option, index) in categoryOptions" </va-select>
:key="index"
v-model="selectedOption"
:option="option"
@update:model-value="applyFilter"
></va-radio>
</div> </div>
</template> </template>
@ -23,15 +18,14 @@ export default {
"Geology", "Geology",
"Materials", "Materials",
"Soil", "Soil",
"Any",
], ],
selectedOption: "Any" selectedOptions: []
} }
}, },
methods: { methods: {
applyFilter() { applyFilter() {
const filter = { "gis_category": this.selectedOption } const filter = { "gis_category": this.selectedOptions }
this.$emit('filter', filter) this.$emit('filter', filter)
}, },
}, },

@ -1,13 +1,8 @@
<template> <template>
<div> <div>
<va-radio <va-select class="multi-selector" v-model="selectedOptions" :options="orgOptions"
class="radio-switcher" @update:model-value="applyFilter" multiple searchable>
v-for="(option, index) in orgOptions" </va-select>
:key="index"
v-model="selectedOption"
:option="option"
@update:model-value="applyFilter"
></va-radio>
</div> </div>
</template> </template>
@ -24,15 +19,14 @@ export default {
"ОАО \"Газпром Промгаз\"", "ОАО \"Газпром Промгаз\"",
"ИАЭТ СО РАН, Новосибирск", "ИАЭТ СО РАН, Новосибирск",
"ИОНХ РАН", "ИОНХ РАН",
"Any"
], ],
selectedOption: "Any" selectedOptions: []
} }
}, },
methods: { methods: {
applyFilter() { applyFilter() {
const filter = { "org": this.selectedOption } const filter = { "org": this.selectedOptions }
this.$emit('filter', filter, this.name) this.$emit('filter', filter, this.name)
}, },
}, },

@ -1,13 +1,8 @@
<template> <template>
<div> <div>
<va-radio <va-select class="multi-selector" v-model="selectedOptions" :options="scannerOptions"
class="radio-switcher" @update:model-value="applyFilter" multiple searchable>
v-for="(option, index) in scannerOptions" </va-select>
:key="index"
v-model="selectedOption"
:option="option"
@update:model-value="applyFilter"
></va-radio>
</div> </div>
</template> </template>
@ -23,15 +18,14 @@ export default {
"v tome x", "v tome x",
"РКТ-180", "РКТ-180",
"SIEMENS Somatom Perspective", "SIEMENS Somatom Perspective",
"Any"
], ],
selectedOption: "Any" selectedOptions: []
} }
}, },
methods: { methods: {
applyFilter() { applyFilter() {
const filter = { "scanner": this.selectedOption } const filter = { "scanner": this.selectedOptions }
this.$emit('filter', filter, this.name) this.$emit('filter', filter, this.name)
}, },
}, },

@ -1,13 +1,8 @@
<template> <template>
<div> <div>
<va-radio <va-select class="multi-selector" v-model="selectedOptions" :options="stratumOptions"
class="radio-switcher" @update:model-value="applyFilter" multiple searchable>
v-for="(option, index) in stratumOptions" </va-select>
:key="index"
v-model="selectedOption"
:option="option"
@update:model-value="applyFilter"
></va-radio>
</div> </div>
</template> </template>
@ -21,15 +16,13 @@ export default {
"баженовская свита", "баженовская свита",
"тюменская свита", "тюменская свита",
"турон ", "турон ",
"Any"
], ],
selectedOption: "Any" selectedOptions: []
} }
}, },
methods: { methods: {
applyFilter() { applyFilter() {
const filter = { "stratum": this.selectedOptions }
const filter = { "stratum": this.selectedOption }
this.$emit('filter', filter, this.name) this.$emit('filter', filter, this.name)
}, },
}, },

@ -23,6 +23,7 @@ import {
VaCardTitle, VaCardTitle,
VaCardContent, VaCardContent,
VaInnerLoading, VaInnerLoading,
VaSelect,
} from 'vuestic-ui' } from 'vuestic-ui'
import 'vuestic-ui/dist/styles/essential.css' import 'vuestic-ui/dist/styles/essential.css'
import 'vuestic-ui/dist/styles/grid.css' import 'vuestic-ui/dist/styles/grid.css'
@ -60,6 +61,7 @@ app.use(createVuesticEssential({
VaCardTitle, VaCardTitle,
VaCardContent, VaCardContent,
VaInnerLoading, VaInnerLoading,
VaSelect,
} }
})); }));

@ -51,11 +51,8 @@ export default {
applyFilters(filter) { applyFilters(filter) {
for (let key in filter) { for (let key in filter) {
if (filter[key] != "Any") { if (Array.isArray(filter[key]) && filter[key].length) {
if (key in this.currentFilters) this.currentFilters[key] = filter[key];
this.currentFilters[key].push(filter[key]);
else
this.currentFilters[key] = [filter[key]];
} else { } else {
delete this.currentFilters[key] delete this.currentFilters[key]
} }

Loading…
Cancel
Save