This commit is contained in:
Luiz Costa 2024-06-07 16:40:32 +01:00
parent 35b27be53d
commit 296452214e

View File

@ -34,13 +34,22 @@ function create_dialog_and_init_map(frm) {
}; };
dialog.show(); dialog.show();
setTimeout(() => init_map(frm), 500); // Add a delay to ensure the map loads correctly
// Ensure the map container expands to fit its parent after the dialog is shown
setTimeout(() => {
const mapElement = document.getElementById('map');
if (mapElement) {
mapElement.style.width = "100%";
mapElement.style.height = "100%";
init_map(frm); // Initialize the map
}
}, 500); // Add a delay to ensure the map loads correctly
} }
var currentMap = null; var currentMap = null;
function init_map(frm) { function init_map(frm) {
console.table(window.L); //console.table(window.L);
console.log("Initializing map with MyLeaflet..."); console.log("Initializing map with MyLeaflet...");
if (currentMap !== null) { if (currentMap !== null) {
currentMap.remove(); // Remove the previous map if it exists currentMap.remove(); // Remove the previous map if it exists
@ -87,7 +96,7 @@ function init_map(frm) {
}, },
callback: function (r) { callback: function (r) {
if (r.message) { if (r.message) {
console.table(r.message); //console.table(r.message);
const data = r.message; const data = r.message;
const routeCoordinates = data.map(entry => [entry.latitude, entry.longitude]); const routeCoordinates = data.map(entry => [entry.latitude, entry.longitude]);
const polyline = window.L.polyline(routeCoordinates, { color: 'red' }).addTo(map); const polyline = window.L.polyline(routeCoordinates, { color: 'red' }).addTo(map);