-
-
Notifications
You must be signed in to change notification settings - Fork 98
[feature] Allow showing moving device in geo map #443 #444
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?
Conversation
Adds the ability to animate a node's position on the map by dynamically updating its coordinates. by adding a utility function which uses echarts.setOptions to update the node location Fixes #443
pandafy
left a comment
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.
@dee077 we need to add an example here to demonstrate the movement of node. I tried to come up with the following example:
netjsonmap-moving-node.json
{
"type": "NetworkGraph",
"label": "Moving Node Demo",
"protocol": "OLSR",
"version": "0.6.6.2",
"metric": "ETX",
"date": "2024-12-04T00:00:00.000Z",
"nodes": [
{
"id": "10.0.0.1",
"name": "India-1",
"location": {
"lng": 72.8777,
"lat": 19.076
},
"properties": {
"time": "2025-12-04T00:00:00.000Z"
}
}
],
"links": []
}netjsonmap-moving-node.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>netjsongraph.js: moving node example</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link
rel="stylesheet"
href="https://unpkg.com/[email protected]/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 type="text/css">
#legend h4 {
margin: 10px 0;
text-align: center;
}
#legend {
position: absolute;
right: 25px;
bottom: 25px;
width: auto;
height: auto;
max-width: 250px;
padding: 8px 15px;
background: #fbfbfb;
border-radius: 8px;
color: #000;
font-family: Arial, sans-serif;
font-family: sans-serif;
font-size: 14px;
z-index: 1000;
user-select: text;
}
#legend p {
margin: 10px 0;
display: flex;
align-items: center;
}
#legend span {
width: 16px;
margin-right: 5px;
}
#legend .link-up,
#legend .link-down {
display: inline-block;
height: 5px;
border-bottom-width: 6px;
border-bottom-style: solid;
}
#legend .link-up {
color: #3acc38;
margin-right: 10px;
}
#legend .link-down {
color: red;
margin-right: 10px;
}
@media only screen and (max-width: 850px) {
#legend {
right: 15px;
}
}
</style>
</head>
<body>
<script type="text/javascript">
// Top 10 most popular cities in India with their coordinates
const cities = [
{ lng: 72.8777, lat: 19.076 },
{ lng: 77.1025, lat: 28.7041 },
{ lng: 77.5946, lat: 12.9716 },
{ lng: 78.4867, lat: 17.385 },
{ lng: 72.5714, lat: 23.0225 },
{ lng: 80.2707, lat: 13.0827 },
{ lng: 88.3639, lat: 22.5726 },
{ lng: 73.8567, lat: 18.5204 },
{ lng: 75.7873, lat: 26.9124 },
{ lng: 72.8311, lat: 21.1702 },
];
let currentCityIndex = 0;
const map = new NetJSONGraph("../assets/data/netjsonmap-moving-node.json", {
render: "map",
mapOptions: {
center: [20.5937, 78.9629],
zoom: 5,
nodeConfig: {
label: {
offset: [0, -10],
},
},
},
prepareData: (data) => {
data.nodes.map((node) => {
node.label = node.name;
node.properties = Object.assign(node.properties || {}, {
location: node.location,
});
});
},
});
map.render();
// Function to move the node to the next city
const moveNodeToNextCity = () => {
currentCityIndex = (currentCityIndex + 1) % cities.length;
const nextCity = cities[currentCityIndex];
// Use the moveNodeInRealTime method to update the node's location
map.utils.moveNodeInRealTime(map, "10.0.0.1", nextCity);
};
// Start moving the node every 2 seconds
setInterval(moveNodeToNextCity, 2000);
</script>
</body>
</html>But, it is giving an error that series is undefined.
| // Todo: Romove before merge | ||
| window.map = map |
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.
Do we still need this?
| const dataIndex = series.data.findIndex(d => d.node.id === id); | ||
| const node = self.data.nodes[dataIndex] |
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.
thinking out loud
Are seies.data and self.data.nodes always same or can they be different? If they are always same, can we avoid finding index in series.data and then accessing it in self.data.nodes?
| } | ||
|
|
||
| moveNodeInRealTime(self, id, location) { | ||
| const dataIndex = series.data.findIndex(d => d.node.id === id); |
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.
Where is series coming from?
Adds the ability to animate a node's position on the map by dynamically updating its coordinates. by adding a utility function which uses echarts.setOptions to update the node location
Fixes #443
Checklist
Reference to Existing Issue
Closes #443.
Screen recording
Screencast.from.2025-09-19.22-13-00.webm