-
-
Notifications
You must be signed in to change notification settings - Fork 95
[feature] Update URL with node click of map interactions #238 #417
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
Open
dee077
wants to merge
18
commits into
master
Choose a base branch
from
feature/238-update-url-on-map-actions
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
7f60640
[feature] Update URL with node click of map interactions #238
dee077 f343b5a
[fix] Add south west and north east bounds in params on user actions
dee077 4e6578f
[feature] Implement for graph, geoMap and indoorMap
dee077 cddf8ea
[fix] Imrpove implementation to make libary more generic
dee077 d98ec8d
[fix] Add indoor maps as overlay example and fix minor bugs
dee077 128cbb1
[fix] Qa
dee077 f44bc07
[fix] Make applyUrlFragmentState wait for onReady to complete
dee077 6bf92da
[fix] Generalized location object
dee077 12ca49a
[tests] Add tests
dee077 e6d018f
[fix] Add comments and nitpicks
dee077 f27c33c
[fix] Update name of config to bookmarkableActions and some corner cases
dee077 a8d5105
[feature] Change map state on browser go back or forward
dee077 07ae1c1
[fix] Add comments and minor refactoring
dee077 061b6f0
[fix] Qa
dee077 c96fae7
[fix] Dont push state for links
dee077 463ed3b
[fix] Add support for link on url fragments and added tests
dee077 8b1039b
[fix] Setting ~ instead of - causing issues on uuid
dee077 6866b9b
[fix] Setting the nodeIndex causing sideffects so created a new looku…
dee077 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 | ||||
---|---|---|---|---|---|---|
|
@@ -465,6 +465,22 @@ NetJSON format used internally is based on [networkgraph](http://netjson.org/rfc | |||||
|
||||||
You can customize the style of GeoJSON features using `style` property. The list of all available properties can be found in the [Leaflet documentation](https://leafletjs.com/reference.html#geojson). | ||||||
|
||||||
- `bookmarkableActions` | ||||||
|
||||||
Configuration for adding url fragments when a node is clicked. | ||||||
|
||||||
```JS | ||||||
bookmarkableActions:{ | ||||||
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.
Suggested change
|
||||||
enabled: boolean, | ||||||
id: string | ||||||
} | ||||||
``` | ||||||
|
||||||
You can enable or disable adding url fragments by setting enabled to true or false. When enabled, the following parameters are added to the URL: | ||||||
1. id – A prefix used to uniquely identify the map. | ||||||
2. nodeId – The id of the selected node. | ||||||
When a URL containing these fragments is opened, the click event associated with the given nodeId is triggered, and if the map is based on Leaflet, the view will automatically center on that node. | ||||||
|
||||||
- `onInit` | ||||||
|
||||||
The callback function executed on initialization of `NetJSONGraph` instance. | ||||||
|
This file contains hidden or 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
This file contains hidden or 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
201 changes: 201 additions & 0 deletions
201
public/example_templates/netjsonmap-indoormap-overlay.html
This file contains hidden or 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,201 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<title>Network Map Visualization</title> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<link | ||
rel="stylesheet" | ||
href="https://unpkg.com/leaflet@1.8.0/dist/leaflet.css" | ||
integrity="sha512-hoalWLoI8r4UszCkZ5kL8vayOGVae1oxXe/2A4AO6J9+580uKHDO3JdHb7NzwwzK5xr/Fs0W40kiNHxM9vyTtQ==" | ||
crossorigin="" | ||
/> | ||
<!-- theme can be easily customized via css --> | ||
<link href="../lib/css/netjsongraph-theme.css" rel="stylesheet" /> | ||
<link href="../lib/css/netjsongraph.css" rel="stylesheet" /> | ||
<style> | ||
body{ | ||
margin: 0; | ||
padding: 0; | ||
} | ||
#map-container { | ||
position: relative; | ||
width: 100%; | ||
height: 100vh; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
} | ||
#map-content { | ||
width: 100%; | ||
height: 100%; | ||
} | ||
#indoormap-container { | ||
position: absolute; /* overlay */ | ||
top: 50%; | ||
left: 50%; | ||
transform: translate(-50%, -50%); | ||
width: 80%; | ||
height: 90%; | ||
padding: 20px; | ||
border-radius: 8px; | ||
align-items: center; | ||
justify-content: center; | ||
z-index: 9999; | ||
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5); | ||
border-radius: 7px; | ||
background-color: white; | ||
} | ||
#indoormap-close { | ||
position: absolute; | ||
top: 2px; | ||
right: 5px; | ||
color: gray; | ||
border: none; | ||
padding: 2px, 5px; | ||
cursor: pointer; | ||
border-radius: 4px; | ||
font-size: 18px; | ||
z-index: 9999; | ||
} | ||
#netjson-indoormap { | ||
width: 100%; | ||
height: 100%; | ||
flex: 1; | ||
} | ||
#indoormap-container .njg-container .sideBarHandle { | ||
top: 35px; | ||
left: 390px | ||
} | ||
#indoormap-container .njg-container .hidden .sideBarHandle { | ||
left: 35px; | ||
} | ||
</style> | ||
dee077 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</head> | ||
<body> | ||
<div id="map-container"> | ||
<div id="map-content"></div> | ||
</div> | ||
|
||
<script> | ||
const netjsonmap = new NetJSONGraph("../assets/data/netjsonmap.json", { | ||
el: "#map-content", | ||
render: "map", | ||
mapOptions: { | ||
center: [46.86764405052012, 19.675998687744144], | ||
zoom: 5, | ||
nodeConfig: { | ||
label: { | ||
show: false, | ||
offset: [0, -10], | ||
}, | ||
}, | ||
baseOptions: {media: [{option: {tooltip: {show: true}}}]}, | ||
}, | ||
bookmarkableActions: { | ||
enabled: true, | ||
id: "geoMap", | ||
}, | ||
prepareData: (data) => { | ||
data.nodes.forEach((n) => { | ||
n.label = n.name; | ||
n.properties = n.properties || {}; | ||
n.properties.location = n.location; | ||
}); | ||
data.links.forEach((l) => { | ||
l.properties = l.properties || {}; | ||
l.category = l.properties.status || "up"; | ||
}); | ||
return data; | ||
}, | ||
onClickElement(type, data) { | ||
openIndoorMap(); | ||
}, | ||
}); | ||
netjsonmap.render(); | ||
|
||
function createIndoorMapContainer() { | ||
const container = document.createElement("div"); | ||
container.id = "indoormap-container"; | ||
|
||
const closeBtn = document.createElement("span"); | ||
closeBtn.id = "indoormap-close"; | ||
closeBtn.innerHTML = "×"; | ||
|
||
const netjsonDiv = document.createElement("div"); | ||
netjsonDiv.id = "netjson-indoormap"; | ||
|
||
container.appendChild(closeBtn); | ||
container.appendChild(netjsonDiv); | ||
|
||
return container; | ||
} | ||
|
||
function closeButtonHandler(container) { | ||
const closeBtn = container.querySelector("#indoormap-close"); | ||
closeBtn.addEventListener("click", () => { | ||
container.remove(); | ||
}); | ||
} | ||
|
||
function openIndoorMap() { | ||
const indoorMapContainer = createIndoorMapContainer(); | ||
closeButtonHandler(indoorMapContainer); | ||
const mapContainer = document.getElementById("map-container"); | ||
mapContainer.appendChild(indoorMapContainer); | ||
|
||
const indoor = new NetJSONGraph( | ||
"../assets/data/netjsonmap-indoormap.json", | ||
{ | ||
el: "#netjson-indoormap", | ||
render: "map", | ||
crs: L.CRS.Simple, | ||
mapOptions: { | ||
center: [50, 50], | ||
zoom: 1, | ||
minZoom: -2, | ||
maxZoom: 2, | ||
nodeConfig: { | ||
label: { | ||
show: false, | ||
}, | ||
animation: false, | ||
}, | ||
baseOptions: {media: [{option: {tooltip: {show: true}}}]}, | ||
}, | ||
bookmarkableActions:{ | ||
enabled: true, | ||
id: "indoorMap", | ||
}, | ||
prepareData: (data) => { | ||
data.nodes.forEach((n) => { | ||
n.label = n.name; | ||
n.properties = n.properties || {}; | ||
n.properties.location = n.location; | ||
}); | ||
}, | ||
onReady: async function () { | ||
const map = this.leaflet; | ||
map.eachLayer((layer) => layer._url && map.removeLayer(layer)); | ||
const img = new Image(); | ||
imageUrl = "../assets/images/floorplan.png"; | ||
img.src = imageUrl; | ||
await img.decode() | ||
const aspectRatio = img.width / img.height; | ||
const h = 700; | ||
const w = aspectRatio * h; | ||
const zoom = map.getMaxZoom() - 1; | ||
const sw = map.unproject([0, h * 2], zoom); | ||
const ne = map.unproject([w * 2, 0], zoom); | ||
const bnds = new L.LatLngBounds(sw, ne); | ||
L.imageOverlay(imageUrl, bnds).addTo(map); | ||
map.fitBounds(bnds); | ||
map.setMaxBounds(bnds); | ||
}, | ||
}, | ||
); | ||
indoor.render(); | ||
} | ||
</script> | ||
</body> | ||
</html> |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Shouldn't this be: