Set max zoom according to map center
This commit is contained in:
parent
a65b1981af
commit
72c7a51594
1 changed files with 12 additions and 4 deletions
16
js/map.js
16
js/map.js
|
|
@ -49,10 +49,10 @@ export async function init(){
|
|||
// Polygone définissant les limites de la carte
|
||||
fetch("./couches/emprise.geojson").then(res => res.json()).then(geojson => {
|
||||
let coordinate_list = geojson.features[0].geometry.coordinates[0]
|
||||
let first_point = map.project(L.latLng([...coordinate_list[0]].reverse()))
|
||||
let bounds = L.bounds(first_point, first_point)
|
||||
let first_point = L.latLng([...coordinate_list[0]].reverse())
|
||||
let bounds = L.latLngBounds(first_point, first_point)
|
||||
for(let i = 1; i<coordinate_list.length; i++){
|
||||
let point = map.project([...coordinate_list[i]].reverse())
|
||||
let point = [...coordinate_list[i]].reverse()
|
||||
bounds.extend(point)
|
||||
}
|
||||
map_bounds = bounds
|
||||
|
|
@ -60,6 +60,14 @@ export async function init(){
|
|||
}),
|
||||
])
|
||||
|
||||
map.addEventListener("move", () => {
|
||||
if(map_bounds.contains(map.getCenter())){
|
||||
map.setMaxZoom(21)
|
||||
} else {
|
||||
map.setMaxZoom(18)
|
||||
}
|
||||
})
|
||||
|
||||
// La couche Openstreetmap standard
|
||||
L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
||||
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
|
||||
|
|
@ -84,7 +92,7 @@ export async function init(){
|
|||
).addTo(map)
|
||||
|
||||
// Parametrage de la carte initiale
|
||||
map.setMaxBounds(map_bounds)
|
||||
//map.setMaxBounds(map_bounds)
|
||||
map.setView(map_center, 19, {
|
||||
animate: false,
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue