Implement marker and marker-set sorting

This commit is contained in:
Lukas Rieger (Blue) 2023-02-07 17:09:01 +01:00
parent 7d263c8b7f
commit 6ea755d366
No known key found for this signature in database
GPG Key ID: 2D09EC5ED2687FF2
11 changed files with 142 additions and 11 deletions

@ -1 +1 @@
Subproject commit 1d0d63f08853581a447f818fbacc7e5c14aa514e Subproject commit 2a3cc1c2709bb13021db9c8064715d569db40ca3

View File

@ -17,6 +17,14 @@
markerSet: "Markerset | Markersets" markerSet: "Markerset | Markersets"
searchPlaceholder: "Suche..." searchPlaceholder: "Suche..."
followPlayerTitle: "Spieler folgen" followPlayerTitle: "Spieler folgen"
sort {
title: "Sortieren nach"
by {
default: "Standard"
label: "Name"
distance: "Distanz"
}
}
} }
settings: { settings: {
title: "Einstellungen" title: "Einstellungen"

View File

@ -17,6 +17,14 @@
markerSet: "marker-set | marker-sets" markerSet: "marker-set | marker-sets"
searchPlaceholder: "Search..." searchPlaceholder: "Search..."
followPlayerTitle: "Follow Player" followPlayerTitle: "Follow Player"
sort {
title: "Sort by"
by {
default: "default"
label: "name"
distance: "distance"
}
}
} }
settings: { settings: {
title: "Settings" title: "Settings"

View File

@ -0,0 +1,70 @@
<template>
<div class="choice-box">
<div v-if="title" class="title">{{ title }}</div>
<div class="choices">
<div class="choice" v-for="choice of choices" :key="choice.id"
:class="{selected: selection === choice.id}"
@click="$emit('choice', choice)"
>
{{ choice.name }}
</div>
</div>
</div>
</template>
<script>
export default {
name: "ChoiceBox",
props: {
title: {
type: String,
required: false,
default: ''
},
choices: Array,
selection: String
}
}
</script>
<style lang="scss">
.choice-box {
display: flex;
font-size: 0.8rem;
text-align: center;
//margin-bottom: 0.5em;
border: solid 2px var(--theme-bg-hover);
//border-radius: 1em;
overflow: hidden;
.title, .choice {
padding: 0.3em 0.5em;
}
.title {
background-color: var(--theme-bg-hover);
}
.choices {
display: flex;
flex-grow: 1;
.choice {
flex-grow: 1;
cursor: pointer;
user-select: none;
background-color: var(--theme-bg);
&:hover {
background-color: var(--theme-bg-hover);
}
&.selected {
background-color: var(--theme-bg-light);
}
}
}
}
</style>

View File

@ -6,6 +6,16 @@
<hr v-if="filteredMarkerSets.length > 0 & thisMarkerSet.markers.length > 0"> <hr v-if="filteredMarkerSets.length > 0 & thisMarkerSet.markers.length > 0">
<div class="markers" v-if="thisMarkerSet.markers.length > 0"> <div class="markers" v-if="thisMarkerSet.markers.length > 0">
<TextInput :value="filter.search" @input="filter.search = $event.target.value" :placeholder="$t('markers.searchPlaceholder')" /> <TextInput :value="filter.search" @input="filter.search = $event.target.value" :placeholder="$t('markers.searchPlaceholder')" />
<ChoiceBox
:title="$t('markers.sort.title')"
:choices="[
{id: 'default', name: $t('markers.sort.by.default')},
{id: 'label', name: $t('markers.sort.by.label')},
{id: 'distance', name: $t('markers.sort.by.distance')}
]"
:selection="filter.order"
@choice="filter.order = $event.id"
/>
<MarkerItem v-for="marker of filteredMarkers" :key="marker.id" :marker="marker" /> <MarkerItem v-for="marker of filteredMarkers" :key="marker.id" :marker="marker" />
</div> </div>
</div> </div>
@ -15,17 +25,23 @@
import MarkerItem from "./MarkerItem.vue"; import MarkerItem from "./MarkerItem.vue";
import TextInput from "./TextInput.vue"; import TextInput from "./TextInput.vue";
import MarkerSet from "./MarkerSet.vue"; import MarkerSet from "./MarkerSet.vue";
import Group from "./Group.vue";
import SimpleButton from "./SimpleButton.vue";
import {MainMenu} from "../../js/MainMenu"; import {MainMenu} from "../../js/MainMenu";
import ChoiceBox from "./ChoiceBox.vue";
export default { export default {
name: "MarkerSetMenu", name: "MarkerSetMenu",
components: {MarkerSet, TextInput, MarkerItem}, components: {ChoiceBox, SimpleButton, MarkerSet, TextInput, MarkerItem, Group},
props: { props: {
menu: MainMenu menu: MainMenu
}, },
data() { data() {
return { return {
controls: this.$bluemap.mapViewer.controlsManager.data,
filter: { filter: {
search: "", search: "",
order: "default"
} }
} }
}, },
@ -34,20 +50,28 @@ export default {
return this.menu.currentPage().markerSet; return this.menu.currentPage().markerSet;
}, },
filteredMarkers() { filteredMarkers() {
return [...this.thisMarkerSet.markers].sort((a, b) => { return [...this.thisMarkerSet.markers].filter(marker => {
if (a.id < b.id) return -1;
if (a.id > b.id) return 1;
return 0;
}).filter(marker => {
if (!this.filter.search) return true; if (!this.filter.search) return true;
if (marker.id.includesCI(this.filter.search)) return true; if (marker.id.includesCI(this.filter.search)) return true;
if (marker.label && marker.label.includesCI(this.filter.search)) return true; if (marker.label && marker.label.includesCI(this.filter.search)) return true;
return marker.type === "player" && (marker.name.includesCI(this.filter.search) || marker.playerUuid.includesCI(this.filter.search)); return marker.type === "player" && (marker.name.includesCI(this.filter.search) || marker.playerUuid.includesCI(this.filter.search));
}).sort((a, b) => {
if (this.filter.order === "label") {
if (a.label < b.label) return -1;
if (a.label > b.label) return 1;
return 0;
}
if (this.filter.order === "distance") {
return a.position.distanceToSquared(this.controls.position) - b.position.distanceToSquared(this.controls.position);
}
return (a.sorting || 0) - (b.sorting || 0);
}); });
}, },
filteredMarkerSets() { filteredMarkerSets() {
return this.thisMarkerSet.markerSets.filter(markerSet => { return this.thisMarkerSet.markerSets.filter(markerSet => {
return (markerSet.id !== "bm-popup-set"); return (markerSet.id !== "bm-popup-set");
}).sort((a, b) => {
return (a.sorting || 0) - (b.sorting || 0);
}); });
} }
}, },

View File

@ -93,6 +93,7 @@ export class HtmlMarker extends Marker {
* @param markerData {{ * @param markerData {{
* position: {x: number, y: number, z: number}, * position: {x: number, y: number, z: number},
* label: string, * label: string,
* sorting: number,
* anchor: {x: number, y: number}, * anchor: {x: number, y: number},
* html: string, * html: string,
* classes: string[], * classes: string[],
@ -109,7 +110,14 @@ export class HtmlMarker extends Marker {
this.position.setZ(pos.z || 0); this.position.setZ(pos.z || 0);
// update label // update label
this.data.label = markerData.label || null; if (this.data.label !== markerData.label) {
this.data.label = markerData.label || null;
}
//update sorting
if (this.data.sorting !== markerData.sorting) {
this.data.sorting = markerData.sorting || 0;
}
// update anchor // update anchor
let anch = markerData.anchor || {}; let anch = markerData.anchor || {};

View File

@ -37,6 +37,7 @@ export class Marker extends Object3D {
this.data = reactive({ this.data = reactive({
id: markerId, id: markerId,
type: "marker", type: "marker",
sorting: 0,
position: this.position, position: this.position,
visible: this.visible visible: this.visible
}); });
@ -67,7 +68,7 @@ export class Marker extends Object3D {
/** /**
* @param position {Vector3} * @param position {Vector3}
* @param camera {THREE.Camera} * @param camera {Camera}
* @param fadeDistanceMax {number} * @param fadeDistanceMax {number}
* @param fadeDistanceMin {number} * @param fadeDistanceMin {number}
* @returns {number} - opacity between 0 and 1 * @returns {number} - opacity between 0 and 1
@ -84,7 +85,7 @@ export class Marker extends Object3D {
/** /**
* @param position {Vector3} * @param position {Vector3}
* @param camera {THREE.Camera} * @param camera {Camera}
* @returns {number} * @returns {number}
*/ */
static calculateDistanceToCameraPlane (position, camera) { static calculateDistanceToCameraPlane (position, camera) {

View File

@ -50,6 +50,7 @@ export class MarkerSet extends Scene {
label: id, label: id,
toggleable: true, toggleable: true,
defaultHide: false, defaultHide: false,
sorting: 0,
markerSets: [], markerSets: [],
markers: [], markers: [],
visible: this.visible, visible: this.visible,
@ -66,6 +67,7 @@ export class MarkerSet extends Scene {
this.data.label = data.label || this.data.id; this.data.label = data.label || this.data.id;
this.data.toggleable = !!data.toggleable; this.data.toggleable = !!data.toggleable;
this.data.defaultHide = !!data.defaultHidden; this.data.defaultHide = !!data.defaultHidden;
this.data.sorting = data.sorting || this.data.sorting;
// update markerSets // update markerSets
this.updateMarkerSetsFromData(data.markerSets); this.updateMarkerSetsFromData(data.markerSets);

View File

@ -73,6 +73,7 @@ export class ObjectMarker extends Marker {
* position: {x: number, y: number, z: number}, * position: {x: number, y: number, z: number},
* label: string, * label: string,
* detail: string, * detail: string,
* sorting: number,
* link: string, * link: string,
* newTab: boolean * newTab: boolean
* }} * }}
@ -91,6 +92,9 @@ export class ObjectMarker extends Marker {
//update detail //update detail
this.data.detail = markerData.detail || null; this.data.detail = markerData.detail || null;
//update sorting
this.data.sorting = markerData.sorting || 0;
// update link // update link
this.data.link = markerData.link || null; this.data.link = markerData.link || null;
this.data.newTab = !!markerData.newTab; this.data.newTab = !!markerData.newTab;

View File

@ -90,6 +90,7 @@ export class PoiMarker extends HtmlMarker {
* iconAnchor: {x: number, y: number}, * iconAnchor: {x: number, y: number},
* label: string, * label: string,
* detail: string, * detail: string,
* sorting: number,
* icon: string, * icon: string,
* classes: string[], * classes: string[],
* minDistance: number, * minDistance: number,
@ -116,6 +117,11 @@ export class PoiMarker extends HtmlMarker {
this.data.label = markerData.label || ""; this.data.label = markerData.label || "";
} }
//update sorting
if (this.data.sorting !== markerData.sorting) {
this.data.sorting = markerData.sorting || 0;
}
// update detail // update detail
if (this.data.detail !== markerData.detail){ if (this.data.detail !== markerData.detail){
this.data.detail = markerData.detail || this.data.label; this.data.detail = markerData.detail || this.data.label;

View File

@ -166,7 +166,7 @@ public Color straight() {
/** /**
* Parses the color from a string and sets it to this Color instance. * Parses the color from a string and sets it to this Color instance.
* The value can be an integer in String-Format or a string in hexadecimal format prefixed with # (css-style: e.g. #f16 becomes #ff1166). * The value can be an integer in String-Format or a string in hexadecimal format prefixed with # (css-style: e.g. #f16 becomes #ff1166).
* @param val The String to parse * @param value The String to parse
* @return The parsed Integer * @return The parsed Integer
* @throws NumberFormatException If the value is not formatted correctly or if there is no value present. * @throws NumberFormatException If the value is not formatted correctly or if there is no value present.
*/ */