Ajout des features de la carte vide
This commit is contained in:
parent
9fbf6daafb
commit
03f5bf0215
2 changed files with 33 additions and 6 deletions
27
js/index.js
27
js/index.js
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
for(let feature_el of document.getElementById("result-panel").children) {
|
||||
if(feature_el instanceof FeatureElement){
|
||||
MAP.show(feature_el.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()
|
||||
|
|
|
|||
12
js/places.js
12
js/places.js
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue