Amelioration de la navigation sur la carte
This commit is contained in:
parent
aa8ea624c7
commit
799dd817ae
5 changed files with 171 additions and 46 deletions
66
js/map.js
66
js/map.js
|
|
@ -107,22 +107,38 @@ export async function init_places(places_db){
|
|||
// La couche des zones disponibles
|
||||
const area_highlight = L.geoJSON(null, {
|
||||
pointToLayer: function(feature, latlng) {
|
||||
let contentEl = document.createElement("a")
|
||||
|
||||
if(feature.id){
|
||||
contentEl.href = `#${encodeURIComponent(feature.id)}`
|
||||
} else if(feature.parentFeature?.id){
|
||||
contentEl.href = `#${encodeURIComponent(feature.parentFeature.id)}`
|
||||
}
|
||||
|
||||
let symbol = feature.mapSymbol;
|
||||
if(symbol.markerUrl) {
|
||||
|
||||
let iconEl = document.createElement("img");
|
||||
iconEl.src = symbol.markerUrl;
|
||||
|
||||
if(iconEl){
|
||||
return L.marker(latlng, {
|
||||
icon: L.divIcon({
|
||||
className: "highlight-point-icon",
|
||||
html: iconEl,
|
||||
iconSize: [0, 0]
|
||||
})
|
||||
})
|
||||
}
|
||||
let iconEl = document.createElement("img")
|
||||
iconEl.src = symbol.markerUrl
|
||||
contentEl.append(iconEl)
|
||||
}
|
||||
|
||||
if(symbol.borderColor && symbol.borderColor != "white"){
|
||||
contentEl.style.setProperty("--symbol-border-color", symbol.borderColor);
|
||||
}
|
||||
|
||||
if(feature.properties.name){
|
||||
let nameEl = document.createElement("h3")
|
||||
nameEl.textContent = feature.properties.name
|
||||
contentEl.append(nameEl)
|
||||
}
|
||||
|
||||
return L.marker(latlng, {
|
||||
icon: L.divIcon({
|
||||
className: "highlight-point-icon",
|
||||
html: contentEl,
|
||||
iconSize: [0, 0]
|
||||
})
|
||||
})
|
||||
},
|
||||
style: function(feature){
|
||||
let symbol = feature.mapSymbol;
|
||||
|
|
@ -171,6 +187,24 @@ export function highlight(place_or_placeid){
|
|||
place = place_or_placeid
|
||||
}
|
||||
|
||||
show(place_or_placeid)
|
||||
|
||||
let centroid = turf.centroid(place)
|
||||
map.panTo(L.latLng(
|
||||
centroid.geometry.coordinates[1],
|
||||
centroid.geometry.coordinates[0]
|
||||
))
|
||||
}
|
||||
|
||||
export function show(place_or_placeid){
|
||||
let place;
|
||||
|
||||
if(typeof place_or_placeid == "string"){
|
||||
place = places.getFeatureById(place_or_placeid)
|
||||
} else {
|
||||
place = place_or_placeid
|
||||
}
|
||||
|
||||
if(place[HIGHLIGHT_LAYER]){
|
||||
place[HIGHLIGHT_LAYER].getElement()
|
||||
.classList.add("active")
|
||||
|
|
@ -181,10 +215,4 @@ export function highlight(place_or_placeid){
|
|||
point_layer.getElement()
|
||||
.classList.add("active")
|
||||
}
|
||||
|
||||
let centroid = turf.centroid(place)
|
||||
map.panTo(L.latLng(
|
||||
centroid.geometry.coordinates[1],
|
||||
centroid.geometry.coordinates[0]
|
||||
))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue