/* * 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)/¯ } } $("#app").on("click", "#package-info-sheet #package-info-get-directions", function () { window.open($(this).attr("href"), "_system"); }); $("#app").on("click", "#package-info-sheet #package-info-sheet-inner .list ul li .item-content", function () { markDelivered($(this).data("id")); map.updatePackageLayer(packages); openPackageInfoSheet($(this).data("coordid"), true); }); 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 .list ul").html(""); for (var i = 0; i < package.items.length; i++) { var classes = ""; var icon = getIconForType(package.items[i].type); var statusicon = "far fa-circle"; if (package.items[i].delivered) { classes = "text-color-green"; statusicon = "far fa-check-circle"; } $("#package-info-sheet-inner .list ul").append('' + '
  • ' + '
    ' + '
    ' + '
    ' + '
    ' + package.items[i].address + '
    ' + '
    ' + '
    ' + '
    ' + '
  • '); } 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); }