You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
1.9 KiB
JavaScript
74 lines
1.9 KiB
JavaScript
/*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
var map = null;
|
|
|
|
function createMap() {
|
|
if (mapboxgl.supported()) {
|
|
$("#mapbox").css("display", "");
|
|
map = maplibreMap();
|
|
centerMapOnPackage();
|
|
} else {
|
|
console.log("maplibre-gl not supported, disabling map");
|
|
$("#mapbox").css("display", "none");
|
|
}
|
|
}
|
|
|
|
function centerMapOnPackage() {
|
|
var latitude = $("#mapbox").data("latitude");
|
|
var longitude = $("#mapbox").data("longitude");
|
|
var accurate = $("#mapbox").data("accurate") == "true";
|
|
|
|
map.removeMarkers();
|
|
map.addMarker(latitude, longitude);
|
|
map.animateMapIn(latitude, longitude, (accurate ? 14 : 10));
|
|
}
|
|
|
|
/**
|
|
* Destroy and re-create the map.
|
|
* @returns {undefined}
|
|
*/
|
|
function reloadMap() {
|
|
try {
|
|
if (map != null && typeof map != 'undefined') {
|
|
map.off();
|
|
map.remove();
|
|
map = null;
|
|
|
|
if (document.getElementById("mapbox") != null) {
|
|
createMap();
|
|
} else {
|
|
console.log("Info", "Not re-creating map because #mapbox is not in DOM. Creation will be automatically triggered when map page is loaded.");
|
|
}
|
|
} else {
|
|
createMap();
|
|
}
|
|
} catch (ex) {
|
|
// oh well ¯\(°_o)/¯
|
|
console.log(ex);
|
|
$("#mapbox").css("display", "none");
|
|
}
|
|
}
|
|
|
|
function setMapLocation(latitude, longitude) {
|
|
if (map == null) {
|
|
return;
|
|
}
|
|
map.setMapLocation(latitude, longitude);
|
|
}
|
|
|
|
function animateMapIn(latitude, longitude, zoom, heading) {
|
|
if (map == null) {
|
|
return;
|
|
}
|
|
if (typeof zoom == 'undefined') {
|
|
zoom = 10;
|
|
}
|
|
if (typeof heading == 'undefined') {
|
|
heading = 0;
|
|
}
|
|
map.animateMapIn(latitude, longitude, zoom, heading);
|
|
} |