diff --git a/js/index.js b/js/index.js index 8f12cbe..0d43fea 100644 --- a/js/index.js +++ b/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 { } 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() diff --git a/js/places.js b/js/places.js index 85c44f8..40725c9 100644 --- a/js/places.js +++ b/js/places.js @@ -13,7 +13,12 @@ export const FEATURE_ID = Symbol("Feature id") */ export class PlaceDatabase extends EventTarget { + /** @type {Object} */ 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,