Improve map behavior

This commit is contained in:
Skylar Ittner 2021-11-05 16:42:40 -06:00
parent 217fe63249
commit d570d1b525

View File

@ -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,