-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(apis_entites): introduce js and css for showing a popover map
This javascript and css file provide functions to show a map in a popover html element. The element is placed near the element and uses the elements data-latitude and data-longitude parameters for showing a marker on the map. This can be used in lists of entities with location information.
- Loading branch information
Showing
3 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#popovermap { | ||
width: 500px; | ||
height: 500px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* show a map in a popover | ||
*/ | ||
function showMap(element) { | ||
document.querySelectorAll(".popovermap").forEach(el => el.remove()); | ||
|
||
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("popovermap"); | ||
mapDiv.setAttribute("id", "popovermap"); | ||
|
||
mapDiv.style.position = "absolute"; | ||
mapDiv.style.top = pTop + "px"; | ||
mapDiv.style.left = pLeft + "px"; | ||
|
||
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: '© <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) { | ||
document.querySelectorAll(".popovermap").forEach(el => el.remove()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters