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
21
js/index.js
21
js/index.js
|
|
@ -32,8 +32,13 @@ window.addEventListener("hashchange", () => {
|
||||||
if (feature) {
|
if (feature) {
|
||||||
MAP.highlight(place_id)
|
MAP.highlight(place_id)
|
||||||
if(document.getElementById("search-result")) {
|
if(document.getElementById("search-result")) {
|
||||||
|
|
||||||
|
// If we have a search in progress, opening search item
|
||||||
openSearchResultItem(feature)
|
openSearchResultItem(feature)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
|
||||||
let foundIndex = null;
|
let foundIndex = null;
|
||||||
let panelChildren = document.getElementById("result-panel").children
|
let panelChildren = document.getElementById("result-panel").children
|
||||||
for(let i = 0; i<panelChildren.length; i++) {
|
for(let i = 0; i<panelChildren.length; i++) {
|
||||||
|
|
@ -45,25 +50,35 @@ window.addEventListener("hashchange", () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(foundIndex != null){
|
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"})
|
document.getElementById("result-panel").setActiveChildrenIndex(foundIndex, {behavior: "instant"})
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
// If nothing was selected and there is no search result, opening feature only
|
||||||
openFeature(feature)
|
openFeature(feature)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(document.getElementById("result-panel").children.length > 1){
|
||||||
for(let feature_el of document.getElementById("result-panel").children) {
|
for(let feature_el of document.getElementById("result-panel").children) {
|
||||||
if(feature_el instanceof FeatureElement){
|
if(feature_el instanceof FeatureElement){
|
||||||
MAP.show(feature_el.feature)
|
MAP.show(feature_el.feature)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
for(let feature of places.featuresShownOnEmptyMap){
|
||||||
|
MAP.show(feature)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
MAP.unhighlight_all()
|
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 => {
|
search_form.addEventListener("submit", e => {
|
||||||
e.preventDefault()
|
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 {
|
export class PlaceDatabase extends EventTarget {
|
||||||
|
|
||||||
|
/** @type {Object<string, MapFeature>} */
|
||||||
featuresById = {}
|
featuresById = {}
|
||||||
|
|
||||||
|
/** @type {MapFeature[]} */
|
||||||
|
featuresShownOnEmptyMap = []
|
||||||
|
|
||||||
fullTextIndex = null
|
fullTextIndex = null
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -166,6 +171,9 @@ export class PlaceDatabase extends EventTarget {
|
||||||
buildIndex(){
|
buildIndex(){
|
||||||
let database = this;
|
let database = this;
|
||||||
|
|
||||||
|
this.featuresShownOnEmptyMap = []
|
||||||
|
let showOnEmptyMap = this.featuresShownOnEmptyMap
|
||||||
|
|
||||||
this.fullTextIndex = lunr(function(){
|
this.fullTextIndex = lunr(function(){
|
||||||
this.ref("id")
|
this.ref("id")
|
||||||
this.field("name")
|
this.field("name")
|
||||||
|
|
@ -184,6 +192,10 @@ export class PlaceDatabase extends EventTarget {
|
||||||
synonyms.push(...sym.indexSynonyms)
|
synonyms.push(...sym.indexSynonyms)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(feature.properties["show-on-empty-map"]){
|
||||||
|
showOnEmptyMap.push(feature)
|
||||||
|
}
|
||||||
|
|
||||||
this.add({
|
this.add({
|
||||||
id,
|
id,
|
||||||
name: feature.properties.name || sym.genericName,
|
name: feature.properties.name || sym.genericName,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue