Here is the scenario: There are about 30 sightseeing places of a european city. The user has the possibility to activate the geolocation feature. The code:
var map = L.map('karte').setView([47.373413911923, 8.5508944440887], 15.5);
L.tileLayer('https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token={accessToken}', {
attribution: 'Map data © <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
maxZoom: 18,
id: 'mapbox/streets-v8',
tileSize: 512,
zoomOffset: -1,
accessToken: 'my_token_here'
}).addTo(map);
var node_11 = L.marker([47.37175260846774, 8.551678744507681]).addTo(map);
node_11.bindPopup('<h3><a href="my_page_here">Page Name</a></h3>');
var node_12 = ...
...
map.locate({setView: true, maxZoom: 18});
function onLocationFound(e) {
var radius = e.accuracy;
L.marker(e.latlng).addTo(map)
.bindPopup("Sie sind innerhalb " + radius + " Meter von diesem Punkt aus");
L.circle(e.latlng, radius).addTo(map);
}
map.on('locationfound', onLocationFound);
This code can be found on the Leaflet documentation. It works as desired.
Question: Is it possible to preserve the map boundaries (i.e. keep showing the markers) if the user is located outside these boundaries and they have accepted the geolocation request?
I guess some kind of conditional logic is needed, but I'm not that far with my coding skills.
Thanks for any hint!