Skip to content
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

explorer pages: update Dvpn Map and changes in UI #109

Merged
merged 1 commit into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 108 additions & 23 deletions components/DvpnMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,64 +2,112 @@ import dynamic from 'next/dynamic';
import { useEffect, useState } from 'react';
import 'leaflet/dist/leaflet.css';
import L from 'leaflet';
import geojsonData from '../utils/countries.json';

// Dynamically import components with ssr: false
const MapContainer = dynamic(() => import('react-leaflet').then((module) => module.MapContainer), { ssr: false });
const TileLayer = dynamic(() => import('react-leaflet').then((module) => module.TileLayer), { ssr: false });
const Marker = dynamic(() => import('react-leaflet').then((module) => module.Marker), { ssr: false });
const Popup = dynamic(() => import('react-leaflet').then((module) => module.Popup), { ssr: false });
const GeoJSON = dynamic(() => import('react-leaflet').then((module) => module.GeoJSON), { ssr: false });

// Define a custom animated icon
const animatedIcon = L.divIcon({
className: 'custom-animated-icon',
html: `
<div style="
width: 20px;
height: 20px;
background: radial-gradient(circle, blue, white);
background: radial-gradient(circle, #007bff, white);
border-radius: 50%;
animation: pulse 2s infinite;
border: 2px solid white;
animation: pulse 1.5s infinite;
"></div>
`,
iconSize: [20, 20],
iconAnchor: [10, 10],
popupAnchor: [0, -10],
});

const getCircularOffset = (index, total, radius = 0.05) => {
const angle = (index / total) * 2 * Math.PI;
return [Math.cos(angle) * radius, Math.sin(angle) * radius];
};

const DvpnMap = ({ nodes }) => {
const [isClient, setIsClient] = useState(false);
const [offsets, setOffsets] = useState({});

useEffect(() => {
setIsClient(true);

// Initialize offsets
const offsetMap = {};
nodes.forEach((node) => {
const [lat, lon] = node.ipinfolocation.split(',').map(Number);
const key = `${lat},${lon}`;

if (!offsetMap[key]) {
offsetMap[key] = [0, 0];
} else {
// Apply a small offset if multiple markers have the same coordinates
offsetMap[key] = [offsetMap[key][0] + 0.01, offsetMap[key][1] + 0.01];
offsetMap[key] = [];
}
offsetMap[key].push(node);
});
setOffsets(offsetMap);

// Apply circular offsets
const finalOffsets = {};
for (const key in offsetMap) {
const nodesAtLocation = offsetMap[key];
nodesAtLocation.forEach((node, index) => {
finalOffsets[node.id] = getCircularOffset(index, nodesAtLocation.length);
});
}

setOffsets(finalOffsets);
}, [nodes]);

if (!isClient) {
return null;
}

// Function to style each country based on the node count
const getCountryStyle = (feature) => {
const country = feature.properties.ISO_A2;
const count = nodes.filter(node => node.ipinfocountry === country).length;

return {
fillColor: count > 3 ? '#0e038c' :
count > 2 ? '#1500ff' :
count > 1 ? '#007bff' :
count > 0 ? '#7fd0f5' :
'#f7f7f7', // Default color for zero nodes
weight: 2,
opacity: 1,
color: 'white',
dashArray: '3',
fillOpacity: 0.7
};
};

// Function to create a tooltip with the node count only for countries with nodes
const onEachCountry = (feature, layer) => {
const country = feature.properties.ISO_A2;
const count = nodes.filter(node => node.ipinfocountry === country).length;

if (count > 0) {
layer.bindTooltip(`${feature.properties.ADMIN}: ${count} nodes`, {
permanent: true,
direction: 'center',
className: 'country-tooltip',
});
}
};

return (
<div className="relative h-full w-full p-20 pl-20 pr-20">
<div className="relative h-full w-full p-20 px-15 bg-[#20253A] mb-5">

<MapContainer
center={[20, 0]}
zoom={2}
minZoom={2}
maxZoom={5}
style={{ height: '100%', width: '100%', padding: '20px', }}
maxZoom={10}
style={{ height: '100%', width: '100%', padding: '20px', borderRadius: '20px', border: '2px solid gray', boxShadow: '0 0px 25px black'}}
// className="leaflet-container"
// maxBounds={[[-90, -180], [90, 180]]}
// maxBoundsViscosity={1.0}
Expand All @@ -68,7 +116,7 @@ const DvpnMap = ({ nodes }) => {
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
attribution='&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
/>
{/* <TileLayer
{/* <TileLayer
url="https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}{r}.png" // CartoDB Dark theme URL
attribution='&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors | Map tiles by <a href="https://carto.com/attributions">CartoDB</a>'
noWrap={true}
Expand All @@ -78,16 +126,19 @@ const DvpnMap = ({ nodes }) => {
attribution='&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> &copy; <a href="http://cartodb.com/attributions">CartoDB</a>'
noWrap={true}
/> */}

{/* Add GeoJSON layer for the choropleth */}
<GeoJSON
data={geojsonData}
style={getCountryStyle}
onEachFeature={onEachCountry}
/>

{nodes.map((node, index) => {
const [lat, lon] = node.ipinfolocation.split(',').map(Number);
const key = `${lat},${lon}`;
const offset = offsets[key] || [0, 0];
const [offsetLat, offsetLon] = offsets[node.id] || [0, 0];
return (
<Marker
key={index}
position={[lat + offset[0], lon + offset[1]]}
icon={animatedIcon}
>
<Marker key={index} position={[lat + offsetLat, lon + offsetLon]} icon={animatedIcon}>
<Popup>
<div className="text-blue-800">
<h3 className="text-blue-900 text-lg font-semibold">{node.name}</h3>
Expand All @@ -105,19 +156,53 @@ const DvpnMap = ({ nodes }) => {
<style jsx>{`
@keyframes pulse {
0% {
transform: scale(1);
transform: scale(0.5);
}
50% {
transform: scale(1.2);
}
100% {
transform: scale(1);
transform: scale(0.5);
}
}

.popup-content {
font-family: Arial, sans-serif;
font-size: 14px;
line-height: 1.6;
color: #333;
background-color: #f9f9f9;
border-radius: 8px;
padding: 10px;
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.popup-title {
margin-top: 0;
font-size: 16px;
font-weight: bold;
color: #FF5F6D;
}

.popup-content p {
margin: 5px 0;
}

.popup-content strong {
color: #333;
}

.country-tooltip {
font-size: 12px;
background-color: #ffffff;
border: 1px solid #dddddd;
border-radius: 4px;
padding: 4px;
}
`}</style>
</div>
);
};

export default DvpnMap;

4 changes: 2 additions & 2 deletions components/DwifiMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ export default function DwifiMap() {
}, []); // Empty dependency array ensures this runs once

return (
<div className="relative h-full w-full p-20 pl-20 pr-20">
<div className="relative h-full w-full p-20 px-15 bg-[#20253A]">
<MapContainer
center={[20.5937, 78.9629]}
zoom={5}
style={{ height: '100%', width: '100%', padding: '20px', }}
style={{ height: '100%', width: '100%', padding: '20px', borderRadius: '20px', border: '2px solid gray', boxShadow: '0 0px 25px black' }}
maxBounds={[[6, 68], [37, 97]]}
maxBoundsViscosity={1.0}
>
Expand Down
9 changes: 9 additions & 0 deletions pages/dwifi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ const Dwifi = () => {
</motion.div>
</div>
</div>
<div className="bg-[#20253A] pt-16 px-20">
<div className="text-2xl font-semibold text-gray-300 mb-8 ">
Erebrus Decentralized Wi-Fi (ÐWi-Fi) Network Nodes Overview
</div>
<div className="text-white">
<p>
Discover the Erebrus decentralized Wi-Fi network with our interactive map. View real-time details about Wi-Fi hotspots, including their location, performance, and usage stats. This dashboard helps you find secure and fast Wi-Fi connections globally. </p>
</div>
</div>
<div className="map-page" style={{ height: '100vh', width: '100vw' }}>

<div className="map-controls" style={{ position: 'absolute', top: 10, left: 10, zIndex: 1000 }}>
Expand Down
17 changes: 13 additions & 4 deletions pages/explorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,19 @@ const Explorer = () => {
</div>
</div>
{/* <img src="/mapRegions.png"/> */}
<div className="bg-[#20253A] pt-16 px-20">
<div className="text-2xl font-semibold text-gray-300 mb-8 "
>
Erebrus Decentralized VPN (ÐVPN) Network Nodes Overview
</div>
<div className="text-white"
>
<p>
Explore the Erebrus decentralized VPN network with our interactive map. View detailed information on active nodes, including their location, network performance, and status. This map provides real-time insights into the global distribution and operation of our secure and private VPN infrastructure.
</p>
</div>
</div>
<div className="map-page" style={{ height: '100vh', width: '100vw' }}>

<div className="map-controls" style={{ position: 'absolute', top: 10, left: 10, zIndex: 1000 }}>
</div>
<div className="map-container" style={{ height: '100%', width: '100%' }}>
<DvpnMap nodes={nodes} />
</div>
Expand All @@ -77,4 +86,4 @@ const Explorer = () => {
)
}

export default Explorer;
export default Explorer;
261 changes: 261 additions & 0 deletions utils/countries.json

Large diffs are not rendered by default.