fix map cluster glitch

This commit is contained in:
Matteo Rosati
2026-01-18 13:59:26 +01:00
parent 9727ddeb7c
commit cb2f232bd4
2 changed files with 26 additions and 0 deletions

View File

@@ -7,6 +7,7 @@ import "leaflet.markercluster/dist/MarkerCluster.Default.css";
import type { Plext } from "../types"; import type { Plext } from "../types";
import { useMapGeolocation } from "../hooks/useMapGeolocation"; import { useMapGeolocation } from "../hooks/useMapGeolocation";
import { useMapBounds } from "../hooks/useMapBounds"; import { useMapBounds } from "../hooks/useMapBounds";
import { useEffect } from "react";
// Fix Leaflet marker icons // Fix Leaflet marker icons
delete (L.Icon.Default.prototype as any)._getIconUrl; delete (L.Icon.Default.prototype as any)._getIconUrl;
@@ -86,6 +87,19 @@ export function PlayerMap({ plexts, onCenterChange, onRadiusChange }: PlayerMapP
}) })
.filter(Boolean); .filter(Boolean);
// Show markers after a short delay to allow clustering to complete
// This prevents individual markers from being visible before clusters are formed
useEffect(() => {
const timer = setTimeout(() => {
const markers = document.querySelectorAll('.leaflet-marker-icon:not(.marker-cluster)');
markers.forEach((marker) => {
marker.classList.add('visible');
});
}, 100); // Small delay to allow cluster group to process markers
return () => clearTimeout(timer);
}, [playerLocations]);
return ( return (
<div className="map-container" style={{ height: "600px", width: "100%" }}> <div className="map-container" style={{ height: "600px", width: "100%" }}>
<MapContainer <MapContainer

View File

@@ -428,3 +428,15 @@ body {
.chart-card { .chart-card {
animation: fadeIn 0.5s ease-out; animation: fadeIn 0.5s ease-out;
} }
/* Marker Cluster - Hide individual markers initially to prevent glitch */
/* This prevents individual markers from being visible before clustering is complete */
.leaflet-marker-icon:not(.marker-cluster) {
opacity: 0;
transition: opacity 0.3s ease-in-out;
}
/* Show markers after a short delay to allow clustering to complete */
.leaflet-marker-icon:not(.marker-cluster).visible {
opacity: 1;
}