Ajout des categories

This commit is contained in:
EpicKiwi 2026-06-29 21:54:50 +02:00
parent 8b4e21f32e
commit 7e654b4640
Signed by: epickiwi
GPG key ID: C4B28FD2729941CE
6 changed files with 803 additions and 7 deletions

View file

@ -23,7 +23,7 @@ class CoordsElement extends HTMLElement {
}
updateContent(){
this.#shadow.replaceChildren(
this.#shadow?.replaceChildren(
this.formatCoordComponent(this.lat),
", ",
this.formatCoordComponent(this.lon)

View file

@ -163,21 +163,27 @@ function openSearchResultItem(feature){
}
}
function openFeature(feature){
function openFeature(...feature){
let panel = document.getElementById("result-panel")
let root = document.createElement("camp-feature")
root.feature = feature
let root = document.createDocumentFragment()
for(let featureItem of feature){
let featureEl = document.createElement("camp-feature")
featureEl.feature = featureItem
root.append(featureEl)
}
panel.replaceChildren(root)
requestAnimationFrame(() => {
panel.setActiveChildrenIndex(0, {behavior: "instant"})
})
updateActiveFeature(feature)
updateActiveFeature(feature[0])
}
function updateActiveFeature(feature_or_featureid){
let newUrl = new URL(window.location)
if(feature_or_featureid){
newUrl.hash = encodeURIComponent(feature_or_featureid.id || feature_or_featureid)
if(typeof feature_or_featureid == "string"){
newUrl.hash = encodeURIComponent(feature_or_featureid)
} else if(feature_or_featureid){
newUrl.hash = encodeURIComponent(feature_or_featureid.id)
} else {
newUrl.hash = "";
}
@ -200,6 +206,23 @@ document.getElementById("result-panel").addEventListener("activePanelChange", e
}
})
document.getElementById("explore-toggle-btn").addEventListener("click", () => {
let details = document.querySelector("#explore > details")
details.open = !details.open
})
function bindButtonToCategory(button, category){
button.addEventListener("click", e => {
e.preventDefault()
openFeature(...places.featuresByCategory[category]);
})
}
bindButtonToCategory(document.getElementById("explore-drinking-water"), "drinking-water")
bindButtonToCategory(document.getElementById("explore-on-schedule"), "on-schedule")
bindButtonToCategory(document.getElementById("explore-dodo"), "dodo")
bindButtonToCategory(document.getElementById("explore-bin"), "bin")
{
const RESULT_PANEL = document.getElementById("result-panel")
/** @type {HTMLDialogElement} */

View file

@ -8,6 +8,13 @@ lunrFr(lunr)
const FEATURE_INDEX = Symbol("Feature index")
export const FEATURE_ID = Symbol("Feature id")
const CATEGORIES = {
"drinking-water": (feature) => feature.properties["eau potable"] || feature.properties["douches"] || feature.properties["toilettes"],
"bin": (feature) => feature.properties["poubelle"],
"dodo": (feature) => feature.properties["n couchage"] > 0 || feature.properties["camping"],
"on-schedule": (feature) => feature.properties["pretalx-room-id"] || feature.properties["pretalx-room-id"] == 0
}
/**
* Base de données locale des différents endroits du lieu
*/
@ -21,6 +28,8 @@ export class PlaceDatabase extends EventTarget {
fullTextIndex = null
featuresByCategory = {}
/**
* Résultats d'une recherche dans la base de données
* @typedef {Object} SearchResult
@ -178,6 +187,9 @@ export class PlaceDatabase extends EventTarget {
this.featuresShownOnEmptyMap = []
let showOnEmptyMap = this.featuresShownOnEmptyMap
let placesThis = this
this.featuresByCategory = {}
this.fullTextIndex = lunr(function(){
this.ref("id")
this.field("name", {boost: 3})
@ -219,6 +231,16 @@ export class PlaceDatabase extends EventTarget {
boost = sym.searchBoost
}
for(let [categoryName, categoryFilter] of Object.entries(CATEGORIES)){
if(!Array.isArray(placesThis.featuresByCategory[categoryName])){
placesThis.featuresByCategory[categoryName] = []
}
if(categoryFilter(feature)){
placesThis.featuresByCategory[categoryName].push(feature)
}
}
this.add({
id,
name: feature.properties.name || sym.genericName,