Improve map behavior
This commit is contained in:
parent
217fe63249
commit
d570d1b525
@ -18,17 +18,30 @@ function maplibreMap() {
|
|||||||
pitch: 0,
|
pitch: 0,
|
||||||
zoom: 1,
|
zoom: 1,
|
||||||
maxZoom: 20,
|
maxZoom: 20,
|
||||||
|
continuousWorld: false,
|
||||||
|
noWrap: true,
|
||||||
center: [-97, 38]
|
center: [-97, 38]
|
||||||
});
|
});
|
||||||
|
|
||||||
map.on('click', function (e) {
|
map.on('click', function (e) {
|
||||||
var coordinates = e.lngLat;
|
var coordinates = e.lngLat;
|
||||||
|
// Fix coordinates if map wrapped around
|
||||||
|
while (coordinates.lng < -180) {
|
||||||
|
coordinates.lng += 180;
|
||||||
|
}
|
||||||
|
while (coordinates.lng > 180) {
|
||||||
|
coordinates.lng -= 180;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
var words = FixPhrase.encode(coordinates.lat, coordinates.lng);
|
var words = FixPhrase.encode(coordinates.lat, coordinates.lng);
|
||||||
var popup = new mapboxgl.Popup();
|
var popup = new mapboxgl.Popup();
|
||||||
popup.setLngLat(coordinates);
|
popup.setLngLat(e.lngLat);
|
||||||
popup.setHTML("<b>" + words + "</b><br>" + (Math.round(coordinates.lat * 10000) / 10000) + ", " + (Math.round(coordinates.lng * 10000) / 10000));
|
popup.setHTML("<b class='copyonclick'>" + words + "</b><br>" + (Math.round(coordinates.lat * 10000) / 10000) + ", " + (Math.round(coordinates.lng * 10000) / 10000));
|
||||||
popup.addTo(map);
|
popup.addTo(map);
|
||||||
|
map.flyTo({
|
||||||
|
center: e.lngLat,
|
||||||
|
zoom: Math.max(map.getZoom(), 14)
|
||||||
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
alert(e);
|
alert(e);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user