Focus du resultat dans la liste et dans l'URL
This commit is contained in:
parent
7d45e2f717
commit
af337ea0bf
2 changed files with 26 additions and 12 deletions
22
js/index.js
22
js/index.js
|
|
@ -108,22 +108,26 @@ function openSearchResultItem(feature){
|
|||
panel.activeChildrenIndex = 0
|
||||
}
|
||||
})
|
||||
let newUrl = new URL(window.location)
|
||||
newUrl.hash = feature.id
|
||||
window.history.replaceState(newUrl.toString(), "")
|
||||
updateActiveFeature(feature)
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
} else {
|
||||
delete newUrl.hash;
|
||||
}
|
||||
window.history.replaceState(null, "", newUrl.toString())
|
||||
window.dispatchEvent(new Event("hashchange"))
|
||||
}
|
||||
|
||||
document.getElementById("result-panel").addEventListener("activePanelChange", e => {
|
||||
let activeElement = e.target.children[e.activePanelIndex]
|
||||
if(activeElement instanceof FeatureElement){
|
||||
let feature = activeElement.feature
|
||||
if(feature){
|
||||
MAP.highlight(feature.id)
|
||||
} else {
|
||||
MAP.unhighlight_all()
|
||||
}
|
||||
console.log("active panel changed: "+e.activePanelIndex, feature)
|
||||
updateActiveFeature(feature)
|
||||
} else {
|
||||
MAP.unhighlight_all()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue