import { Layer, Source } from "react-map-gl/mapbox"; import { useMemo } from "react"; import { ICrimes } from "@/app/_utils/types/crimes"; interface HeatmapLayerProps { crimes: ICrimes[]; year: string; month: string; filterCategory: string | "all"; visible?: boolean; } export default function HeatmapLayer({ crimes, visible = true }: HeatmapLayerProps) { // Convert crime data to GeoJSON format for the heatmap const heatmapData = useMemo(() => { const features = crimes.flatMap(crime => crime.crime_incidents .filter(incident => incident.locations?.latitude && incident.locations?.longitude) .map(incident => ({ type: "Feature" as const, properties: { id: incident.id, category: incident.crime_categories?.name || "Unknown", intensity: 1, // Base intensity value }, geometry: { type: "Point" as const, coordinates: [incident.locations!.longitude, incident.locations!.latitude], }, })) ); return { type: "FeatureCollection" as const, features, }; }, [crimes]); if (!visible) return null; return ( ); }