forked from Netsyms/PackageHelper
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.
109 lines
3.4 KiB
JavaScript
109 lines
3.4 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() {
|
|
map = leafletMap();
|
|
map.updatePackageLayer(packages);
|
|
}
|
|
|
|
/**
|
|
* Destroy and re-create the map.
|
|
* @returns {undefined}
|
|
*/
|
|
function reloadMap() {
|
|
try {
|
|
if (map != null && typeof map != 'undefined') {
|
|
var mapcenter = map.getCenter();
|
|
var mapzoom = map.getZoom();
|
|
map.off();
|
|
map.remove();
|
|
map = null;
|
|
createMap();
|
|
map.setView(mapcenter, mapzoom);
|
|
} else {
|
|
createMap();
|
|
}
|
|
} catch (ex) {
|
|
// oh well ¯\(°_o)/¯
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Make the toggle button on the popup sheet do things
|
|
*/
|
|
$("#app").on("click", "#package-info-sheet .package-info-toggle-status", function () {
|
|
var pid = $(this).data("id");
|
|
markDelivered(pid);
|
|
map.updatePackageLayer(packages);
|
|
for (var i = 0; i < packages.length; i++) {
|
|
if (packages[i].id == $(this).data("coordid")) {
|
|
openPackageInfoSheet(packages[i], true);
|
|
return;
|
|
}
|
|
}
|
|
});
|
|
|
|
$("#app").on("click", "#package-info-sheet #package-info-get-directions", function () {
|
|
window.open($(this).attr("href"), "_system");
|
|
});
|
|
|
|
function openPackageInfoSheet(coordid, refreshOnly) {
|
|
if (typeof refreshOnly == "undefined") {
|
|
refreshOnly = false;
|
|
}
|
|
|
|
for (var i = 0; i < packages.length; i++) {
|
|
if (packages[i].id == coordid) {
|
|
package = packages[i];
|
|
|
|
$("#package-info-get-directions").attr("href", "geo:" + package.coords[0] + "," + package.coords[1]);
|
|
$("#package-info-sheet-inner").html("");
|
|
|
|
for (var i = 0; i < package.items.length; i++) {
|
|
$("#package-info-sheet-inner").append(''
|
|
+ '<div class="block margin-top-half">'
|
|
+ ' <div>'
|
|
+ ' <span class="package-info-delivery-status">'
|
|
+ ' ' + +(package.items[i].delivered ? '<span class="text-color-green"><i class="fas fa-check-circle"></i> Delivered</span>' : '<i class="fas fa-circle"></i> Not delivered')
|
|
+ ' </span>'
|
|
+ ' </div>'
|
|
+ ' <h3>'
|
|
+ ' <span class="package-info-address">' + package.items[i].address + '</span>'
|
|
+ ' </h3>'
|
|
+ ' <div class="button button-fill margin-top" class="package-info-toggle-status" data-id="' + package.items[i].id + '" data-coordid=' + package.id + '>'
|
|
+ ' ' + (package.items[i].delivered ? "Undeliver" : "Deliver")
|
|
+ ' </div>'
|
|
+ '</div>');
|
|
}
|
|
|
|
if (!refreshOnly) {
|
|
app.sheet.create({el: "#package-info-sheet"}).open();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
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 = 14;
|
|
}
|
|
if (typeof heading == 'undefined') {
|
|
heading = 0;
|
|
}
|
|
map.animateMapIn(latitude, longitude, zoom, heading);
|
|
} |