Skip to content

Commit

Permalink
fix(apis_entities): fix, update map JS
Browse files Browse the repository at this point in the history
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
  • Loading branch information
koeaw committed May 15, 2024
1 parent 3c7da82 commit 4a86a69
Showing 1 changed file with 23 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> 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: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
L.marker([parseInt(element.dataset.latitude), parseInt(element.dataset.longitude)]).addTo(map);
}

function delmap(element) {
function delMap(element) {
$('.popover').remove();
}
</script>
Expand Down

0 comments on commit 4a86a69

Please sign in to comment.