feat([2fd88f42]): add auto zoom-to-fit and dynamic legend

This commit is contained in:
2026-02-04 13:51:58 +00:00
parent a00951500e
commit 030c66b258
2 changed files with 28 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
// src/components/MapBoundsManager.tsx
import React, { useEffect } from 'react';
import { useMap } from 'react-leaflet';
import L from 'leaflet';
import { HeatmapPoint } from '../App';
interface MapBoundsManagerProps {
data: HeatmapPoint[];
}
const MapBoundsManager: React.FC<MapBoundsManagerProps> = ({ data }) => {
const map = useMap();
useEffect(() => {
if (data && data.length > 0) {
const bounds = L.latLngBounds(data.map(p => [p.lat, p.lon]));
if (bounds.isValid()) {
map.fitBounds(bounds, { padding: [50, 50] });
}
}
}, [data, map]);
return null; // This component does not render anything
};
export default MapBoundsManager;

View File

@@ -7,6 +7,7 @@ import 'leaflet.heat';
import type { HeatmapPoint, MapMode } from '../App'; import type { HeatmapPoint, MapMode } from '../App';
import MarkerClusterGroup from 'react-leaflet-cluster'; import MarkerClusterGroup from 'react-leaflet-cluster';
import Legend from './Legend'; import Legend from './Legend';
import MapBoundsManager from './MapBoundsManager';
interface MapDisplayProps { interface MapDisplayProps {
heatmapData: HeatmapPoint[]; heatmapData: HeatmapPoint[];
@@ -84,6 +85,7 @@ const MapDisplay: React.FC<MapDisplayProps> = ({ heatmapData, radiusMultiplier,
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
attribution='&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors' attribution='&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
/> />
<MapBoundsManager data={heatmapData} />
{viewMode === 'points' ? renderPoints() : renderHeatmap()} {viewMode === 'points' ? renderPoints() : renderHeatmap()}
{viewMode === 'points' && <Legend getColor={getColor} maxCount={maxCount} />} {viewMode === 'points' && <Legend getColor={getColor} maxCount={maxCount} />}
</MapContainer> </MapContainer>