Ajout des features de la carte vide

This commit is contained in:
EpicKiwi 2026-06-14 12:21:50 +02:00
parent 9fbf6daafb
commit 03f5bf0215
Signed by: epickiwi
GPG key ID: C4B28FD2729941CE
2 changed files with 33 additions and 6 deletions

View file

@ -32,8 +32,13 @@ window.addEventListener("hashchange", () => {
if (feature) {
MAP.highlight(place_id)
if(document.getElementById("search-result")) {
// If we have a search in progress, opening search item
openSearchResultItem(feature)
} else {
let foundIndex = null;
let panelChildren = document.getElementById("result-panel").children
for(let i = 0; i<panelChildren.length; i++) {
@ -45,25 +50,35 @@ window.addEventListener("hashchange", () => {
}
if(foundIndex != null){
// If a panel with this feature was already added to dom, scrolling to this item
document.getElementById("result-panel").setActiveChildrenIndex(foundIndex, {behavior: "instant"})
} else {
// If nothing was selected and there is no search result, opening feature only
openFeature(feature)
}
}
if(document.getElementById("result-panel").children.length > 1){
for(let feature_el of document.getElementById("result-panel").children) {
if(feature_el instanceof FeatureElement){
MAP.show(feature_el.feature)
}
}
} else {
for(let feature of places.featuresShownOnEmptyMap){
MAP.show(feature)
}
}
}
} else {
MAP.unhighlight_all()
for(let feature of places.featuresShownOnEmptyMap){
MAP.show(feature)
}
}
})
if(location.hash){
window.dispatchEvent(new Event("hashchange"))
}
window.dispatchEvent(new Event("hashchange"))
search_form.addEventListener("submit", e => {
e.preventDefault()

View file

@ -13,7 +13,12 @@ export const FEATURE_ID = Symbol("Feature id")
*/
export class PlaceDatabase extends EventTarget {
/** @type {Object<string, MapFeature>} */
featuresById = {}
/** @type {MapFeature[]} */
featuresShownOnEmptyMap = []
fullTextIndex = null
/**
@ -166,6 +171,9 @@ export class PlaceDatabase extends EventTarget {
buildIndex(){
let database = this;
this.featuresShownOnEmptyMap = []
let showOnEmptyMap = this.featuresShownOnEmptyMap
this.fullTextIndex = lunr(function(){
this.ref("id")
this.field("name")
@ -184,6 +192,10 @@ export class PlaceDatabase extends EventTarget {
synonyms.push(...sym.indexSynonyms)
}
if(feature.properties["show-on-empty-map"]){
showOnEmptyMap.push(feature)
}
this.add({
id,
name: feature.properties.name || sym.genericName,