-
-
Notifications
You must be signed in to change notification settings - Fork 116
[feature] Added configurable popup on node click #402 #542
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -73,6 +73,31 @@ | |||||||
| #indoormap-container .njg-container .hidden .sideBarHandle { | ||||||||
| left: 35px; | ||||||||
| } | ||||||||
| .njg-container .njg-sideBar { | ||||||||
| display: none; | ||||||||
| } | ||||||||
| .njg-container .leaflet-popup-tip-container { | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||
| bottom: -5%; | ||||||||
| } | ||||||||
| .njg-container .default-popup .njg-popup-button-container { | ||||||||
| display: flex; | ||||||||
| justify-content: center; | ||||||||
|
Comment on lines
+83
to
+84
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't this simpler alternative obtain the same effect?
Suggested change
|
||||||||
| } | ||||||||
| .njg-container .default-popup .njg-popup-button { | ||||||||
| padding: 6px 12px; | ||||||||
| border: none; | ||||||||
| border-radius: 5px; | ||||||||
| background-color: black; | ||||||||
| color: white; | ||||||||
| cursor: pointer; | ||||||||
| margin-top: 5px; | ||||||||
| } | ||||||||
| .njg-container .default-popup .njg-popup-button:hover { | ||||||||
| background-color: rgb(85, 85, 85); | ||||||||
| } | ||||||||
| .njg-container .leaflet-popup-tip { | ||||||||
| box-shadow: none; | ||||||||
| } | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as |
||||||||
| </style> | ||||||||
| </head> | ||||||||
| <body> | ||||||||
|
|
@@ -95,6 +120,15 @@ | |||||||
| }, | ||||||||
| }, | ||||||||
| baseOptions: {media: [{option: {tooltip: {show: true}}}]}, | ||||||||
| nodePopup: { | ||||||||
| show: true, | ||||||||
| content: createCustomPopup, | ||||||||
| config: { | ||||||||
| autoPan: true, | ||||||||
| autoPanPadding: [25, 25], | ||||||||
| offset: [-8, -8], | ||||||||
| }, | ||||||||
| }, | ||||||||
| }, | ||||||||
| bookmarkableActions: { | ||||||||
| enabled: true, | ||||||||
|
|
@@ -113,11 +147,7 @@ | |||||||
| }); | ||||||||
| return data; | ||||||||
| }, | ||||||||
| onClickElement(type, data) { | ||||||||
| if (type === "node") { | ||||||||
| openIndoorMap(); | ||||||||
| } | ||||||||
| }, | ||||||||
| onClickElement(type, data) {}, | ||||||||
|
dee077 marked this conversation as resolved.
|
||||||||
| }); | ||||||||
| netjsonmap.setUtils({ | ||||||||
| // Added to open popup for a specific location Id in selenium tests | ||||||||
|
|
@@ -154,6 +184,67 @@ | |||||||
| // needed for selenium tests | ||||||||
| window._geoMap = netjsonmap; | ||||||||
|
|
||||||||
| function getIndoorMapFragment() { | ||||||||
| let decodedHash = ""; | ||||||||
| try { | ||||||||
| decodedHash = decodeURIComponent( | ||||||||
| window.location.hash.replace(/^#/, ""), | ||||||||
| ); | ||||||||
| } catch (err) { | ||||||||
| return null; | ||||||||
| } | ||||||||
| const fragments = decodedHash.split(";").filter(Boolean); | ||||||||
|
|
||||||||
| return fragments.find((fragment) => { | ||||||||
| const params = new URLSearchParams(fragment); | ||||||||
| return params.get("id") === "indoorMap"; | ||||||||
| }); | ||||||||
|
coderabbitai[bot] marked this conversation as resolved.
|
||||||||
| } | ||||||||
| if (getIndoorMapFragment()) { | ||||||||
| openIndoorMap(); | ||||||||
| } | ||||||||
|
coderabbitai[bot] marked this conversation as resolved.
|
||||||||
|
|
||||||||
| function createCustomPopup(node) { | ||||||||
| const popupContent = document.createElement("div"); | ||||||||
| popupContent.classList.add("default-popup"); | ||||||||
| const location = node?.location || node?.properties?.location; | ||||||||
| const fields = { | ||||||||
| name: node?.name, | ||||||||
| id: node?.id, | ||||||||
| label: node?.label, | ||||||||
| location: location | ||||||||
| ? `${location.lat.toFixed(8)}, ${location.lng.toFixed(8)}` | ||||||||
| : null, | ||||||||
| }; | ||||||||
| Object.keys(fields).forEach((key) => { | ||||||||
| const value = fields[key]; | ||||||||
| if (!value) { | ||||||||
| return; | ||||||||
| } | ||||||||
| const item = document.createElement("div"); | ||||||||
| item.classList.add("njg-tooltip-item"); | ||||||||
| const keyLabel = document.createElement("span"); | ||||||||
| keyLabel.classList.add("njg-tooltip-key"); | ||||||||
| keyLabel.textContent = key; | ||||||||
| const valueLabel = document.createElement("span"); | ||||||||
| valueLabel.classList.add("njg-tooltip-value"); | ||||||||
| valueLabel.textContent = String(value); | ||||||||
| item.appendChild(keyLabel); | ||||||||
| item.appendChild(valueLabel); | ||||||||
| popupContent.appendChild(item); | ||||||||
| }); | ||||||||
| const buttonContainer = document.createElement("div"); | ||||||||
| buttonContainer.classList.add("njg-popup-button-container"); | ||||||||
|
|
||||||||
| const button = document.createElement("button"); | ||||||||
| button.classList.add("njg-popup-button"); | ||||||||
| button.innerHTML = "Open Floorplan"; | ||||||||
| buttonContainer.appendChild(button); | ||||||||
| popupContent.appendChild(buttonContainer); | ||||||||
| button.addEventListener("click", () => openIndoorMap()); | ||||||||
| return popupContent; | ||||||||
| } | ||||||||
|
|
||||||||
| function createIndoorMapContainer() { | ||||||||
| const container = document.createElement("div"); | ||||||||
| container.id = "indoormap-container"; | ||||||||
|
|
@@ -180,10 +271,13 @@ | |||||||
| onClose(); | ||||||||
| } | ||||||||
| container.remove(); | ||||||||
| window._indoorMap = null; | ||||||||
| }); | ||||||||
| } | ||||||||
|
|
||||||||
| function openIndoorMap() { | ||||||||
| if (window._indoorMap) { | ||||||||
| return window._indoorMap; | ||||||||
| } | ||||||||
| let indoorMapContainer = document.getElementById("indoormap-container"); | ||||||||
| if (!indoorMapContainer) { | ||||||||
| indoorMapContainer = createIndoorMapContainer(); | ||||||||
|
|
@@ -211,6 +305,15 @@ | |||||||
| animation: false, | ||||||||
| }, | ||||||||
| baseOptions: {media: [{option: {tooltip: {show: true}}}]}, | ||||||||
| nodePopup: { | ||||||||
| show: true, | ||||||||
| content: null, | ||||||||
| config: { | ||||||||
| autoPan: true, | ||||||||
| autoPanPadding: [25, 25], | ||||||||
| offset: [-8, -8], | ||||||||
| }, | ||||||||
| }, | ||||||||
| }, | ||||||||
| bookmarkableActions: { | ||||||||
| enabled: true, | ||||||||
|
|
@@ -254,12 +357,14 @@ | |||||||
|
|
||||||||
| const mapOptions = this.echarts.getOption(); | ||||||||
| // Refer netjsonmap-indoormap.html for full explanation of this workaround | ||||||||
| mapOptions.series[0].data.forEach((data) => { | ||||||||
| mapOptions.series[0].data.forEach((data, index) => { | ||||||||
| const node = data.node; | ||||||||
| const px = Number(node.location.lng); | ||||||||
| const py = -Number(node.location.lat); | ||||||||
| const nodeProjected = L.point(topLeft.x + px, topLeft.y + py); | ||||||||
| const nodeLatLng = map.unproject(nodeProjected, zoom); | ||||||||
| this.data.nodes[index].location = nodeLatLng; | ||||||||
| this.data.nodes[index].properties.location = nodeLatLng; | ||||||||
| node.location = nodeLatLng; | ||||||||
| node.properties.location = nodeLatLng; | ||||||||
| data.value = [nodeLatLng.lng, nodeLatLng.lat]; | ||||||||
|
|
@@ -302,6 +407,7 @@ | |||||||
| map.setMaxBounds(bnds); | ||||||||
| map.invalidateSize(); | ||||||||
| }, | ||||||||
| onClickElement: function () {}, | ||||||||
| }, | ||||||||
| ); | ||||||||
| indoor.setUtils({ | ||||||||
|
|
@@ -337,9 +443,16 @@ | |||||||
| const popstateHandler = () => { | ||||||||
| const fragments = indoor.utils.parseUrlFragments(); | ||||||||
| const id = indoor.config.bookmarkableActions.id; | ||||||||
| if (!fragments[id]) { | ||||||||
| indoorMapContainer.remove(); | ||||||||
| window.removeEventListener("popstate", popstateHandler); | ||||||||
| if (fragments[id]) { | ||||||||
| if (!document.getElementById("indoormap-container")) { | ||||||||
| openIndoorMap(); | ||||||||
| } | ||||||||
| } else { | ||||||||
| const container = document.getElementById("indoormap-container"); | ||||||||
| if (container) { | ||||||||
| container.remove(); | ||||||||
| window._indoorMap = null; | ||||||||
| } | ||||||||
| } | ||||||||
| }; | ||||||||
| window.addEventListener("popstate", popstateHandler); | ||||||||
|
dee077 marked this conversation as resolved.
|
||||||||
|
|
||||||||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I comment out this, I see no difference. What does this do?