Improve map behavior
This commit is contained in:
parent
217fe63249
commit
d570d1b525
@ -18,22 +18,35 @@ function maplibreMap() {
|
||||
pitch: 0,
|
||||
zoom: 1,
|
||||
maxZoom: 20,
|
||||
continuousWorld: false,
|
||||
noWrap: true,
|
||||
center: [-97, 38]
|
||||
});
|
||||
|
||||
map.on('click', function (e) {
|
||||
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 {
|
||||
var words = FixPhrase.encode(coordinates.lat, coordinates.lng);
|
||||
var popup = new mapboxgl.Popup();
|
||||
popup.setLngLat(coordinates);
|
||||
popup.setHTML("<b>" + words + "</b><br>" + (Math.round(coordinates.lat * 10000) / 10000) + ", " + (Math.round(coordinates.lng * 10000) / 10000));
|
||||
popup.setLngLat(e.lngLat);
|
||||
popup.setHTML("<b class='copyonclick'>" + words + "</b><br>" + (Math.round(coordinates.lat * 10000) / 10000) + ", " + (Math.round(coordinates.lng * 10000) / 10000));
|
||||
popup.addTo(map);
|
||||
map.flyTo({
|
||||
center: e.lngLat,
|
||||
zoom: Math.max(map.getZoom(), 14)
|
||||
});
|
||||
} catch (e) {
|
||||
alert(e);
|
||||
}
|
||||
return;
|
||||
|
||||
|
||||
// Example of accessing the PHP API instead of using JS
|
||||
$.getJSON("lookup.php", {
|
||||
latitude: coordinates.lat,
|
||||
|
Loading…
x
Reference in New Issue
Block a user