From 4a86a693c6a14d5e78d00411bdc4e57f7412c008 Mon Sep 17 00:00:00 2001 From: KK Date: Wed, 15 May 2024 09:07:00 +0200 Subject: [PATCH] fix(apis_entities): fix, update map JS Fix references to longitude, latitude values, incorrect check for existing map; update variable names, keywords following JavaScript best practices, reorder statements for readabilty. Closes: #639 --- .../apis_entities/abstractentity_form.html | 40 +++++++++++-------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/apis_core/apis_entities/templates/apis_core/apis_entities/abstractentity_form.html b/apis_core/apis_entities/templates/apis_core/apis_entities/abstractentity_form.html index fe46449a3..845998581 100644 --- a/apis_core/apis_entities/templates/apis_core/apis_entities/abstractentity_form.html +++ b/apis_core/apis_entities/templates/apis_core/apis_entities/abstractentity_form.html @@ -172,25 +172,31 @@ }; activate_editing(); -function showmap(element) { +function showMap(element) { $('.popover').remove(); - var rect = element.getBoundingClientRect(); - - mapdiv = document.createElement("div"); - mapdiv.classList.add("popover"); - mapdiv.setAttribute("id", "popovermap"); - ptop = rect.top + window.scrollY - 250; - pleft = rect.left + window.scrollX - 550; - $(mapdiv).offset({top: ptop, left: pleft}); - document.body.appendChild(mapdiv); - - if (typeof map != "undefined") { map.off(); map.remove(); } - map = L.map('popovermap', { center: [element.dataset.lat, element.dataset.lng], zoom: 5 }); - L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { attribution: '© OpenStreetMap contributors' }).addTo(map); - L.marker([element.dataset.lat, element.dataset.lng]).addTo(map); -}; + let map; + + let rect = element.getBoundingClientRect(); + let pTop = rect.top + window.scrollY - 250; + let pLeft = rect.left + window.scrollX - 550; + + let mapDiv = document.createElement("div"); + mapDiv.classList.add("popover"); + mapDiv.setAttribute("id", "popovermap"); + + $(mapDiv).offset({top: pTop, left: pLeft}); + document.body.appendChild(mapDiv); + + if (typeof map !== "undefined") { map.off(); map.remove(); } + + map = L.map('popovermap', { center: [parseInt(element.dataset.latitude), parseInt(element.dataset.longitude)], zoom: 5 }); + L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { + attribution: '© OpenStreetMap contributors' + }).addTo(map); + L.marker([parseInt(element.dataset.latitude), parseInt(element.dataset.longitude)]).addTo(map); +} -function delmap(element) { +function delMap(element) { $('.popover').remove(); }