/* * 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("packageid"); markDelivered(pid); map.updatePackageLayer(packages); openPackageInfoSheet(packages[pid], true); }); $("#app").on("click", "#package-info-sheet #package-info-get-directions", function () { window.open($(this).attr("href"), "_blank"); }); function openPackageInfoSheet(package, refreshOnly) { if (typeof refreshOnly == "undefined") { refreshOnly = false; } $("#package-info-toggle-status").data("packageid", packages.findIndex(function (p) { return p == package; })); $("#package-info-address").text(package.address); $("#package-info-get-directions").attr("href", "geo:" + package.coords[0] + "," + package.coords[1]); if (package.delivered) { $("#package-info-delivery-status").html(' Delivered'); $("#package-info-toggle-status").text("Mark undelivered"); } else { $("#package-info-delivery-status").html(' Not delivered'); $("#package-info-toggle-status").text("Mark delivered"); } 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); }