(null)
+ const { current: mapInstance } = useMap()
+
+ const mapboxMap = mapInstance?.getMap() || null
+
const { isFullscreen } = useFullscreen(mapContainerRef)
const { data: availableSourceTypes, isLoading: isTypeLoading } = useGetCrimeTypes()
@@ -142,6 +154,29 @@ export default function CrimeMap() {
}
}, [selectedSourceType, activeControl]);
+ useEffect(() => {
+ setEwsIncidents(getAllIncidents())
+ }, [])
+
+ const handleTriggerAlert = useCallback((priority: "high" | "medium" | "low") => {
+ const newIncident = addMockIncident({ priority })
+ setEwsIncidents(getAllIncidents())
+ }, [])
+
+ const handleResolveIncident = useCallback((id: string) => {
+ resolveIncident(id)
+ setEwsIncidents(getAllIncidents())
+ }, [])
+
+ const handleResolveAllAlerts = useCallback(() => {
+ ewsIncidents.forEach((incident) => {
+ if (incident.status === "active") {
+ resolveIncident(incident.id)
+ }
+ })
+ setEwsIncidents(getAllIncidents())
+ }, [ewsIncidents])
+
const handleSourceTypeChange = useCallback((sourceType: string) => {
setSelectedSourceType(sourceType);
@@ -283,6 +318,7 @@ export default function CrimeMap() {
sourceType={selectedSourceType}
/>
+
{isFullscreen && (
<>
@@ -304,6 +340,19 @@ export default function CrimeMap() {
/>
+ {mapboxMap && (
+
+ )}
+ {displayPanicDemo && (
+
+
inc.status === "active")}
+ />
+
+ )}
+
- {isFullscreen && (
-
- {showClusters && (
-
- )}
- {showUnclustered && !showClusters && (
-
- )}
-
- )}
- {isFullscreen && showUnitsLayer && (
+
+ {showClusters && (
+
+ )}
+ {showUnclustered && !showClusters && (
+
+ )}
+
+
+
+ {showUnitsLayer && (
)}
- {isFullscreen && showTimelineLayer && (
+ {showTimelineLayer && (
@@ -340,17 +389,17 @@ export default function CrimeMap() {
>
)}
- {isFullscreen && (
-
-
-
- )}
+
+
+
+
+
diff --git a/sigap-website/app/_components/map/layers/layers.tsx b/sigap-website/app/_components/map/layers/layers.tsx
index 2031f63..8ece396 100644
--- a/sigap-website/app/_components/map/layers/layers.tsx
+++ b/sigap-website/app/_components/map/layers/layers.tsx
@@ -93,6 +93,7 @@ export default function Layers({
sourceType = "cbt",
}: LayersProps) {
const animationRef = useRef(null)
+
const { current: map } = useMap()
if (!map) {
@@ -115,28 +116,28 @@ export default function Layers({
const [showPanicDemo, setShowPanicDemo] = useState(true)
const [displayPanicDemo, setDisplayPanicDemo] = useState(showEWS && showPanicDemo)
- useEffect(() => {
- setEwsIncidents(getAllIncidents())
- }, [])
+ // useEffect(() => {
+ // setEwsIncidents(getAllIncidents())
+ // }, [])
- const handleTriggerAlert = useCallback((priority: "high" | "medium" | "low") => {
- const newIncident = addMockIncident({ priority })
- setEwsIncidents(getAllIncidents())
- }, [])
+ // const handleTriggerAlert = useCallback((priority: "high" | "medium" | "low") => {
+ // const newIncident = addMockIncident({ priority })
+ // setEwsIncidents(getAllIncidents())
+ // }, [])
- const handleResolveIncident = useCallback((id: string) => {
- resolveIncident(id)
- setEwsIncidents(getAllIncidents())
- }, [])
+ // const handleResolveIncident = useCallback((id: string) => {
+ // resolveIncident(id)
+ // setEwsIncidents(getAllIncidents())
+ // }, [])
- const handleResolveAllAlerts = useCallback(() => {
- ewsIncidents.forEach((incident) => {
- if (incident.status === "active") {
- resolveIncident(incident.id)
- }
- })
- setEwsIncidents(getAllIncidents())
- }, [ewsIncidents])
+ // const handleResolveAllAlerts = useCallback(() => {
+ // ewsIncidents.forEach((incident) => {
+ // if (incident.status === "active") {
+ // resolveIncident(incident.id)
+ // }
+ // })
+ // setEwsIncidents(getAllIncidents())
+ // }, [ewsIncidents])
const handlePopupClose = useCallback(() => {
selectedDistrictRef.current = null
@@ -534,9 +535,9 @@ export default function Layers({
- {showEWS && }
+ {/* {showEWS && } */}
- {showEWS && displayPanicDemo && (
+ {/* {showEWS && displayPanicDemo && (
inc.status === "active")}
/>
- )}
+ )} */}
>
diff --git a/sigap-website/app/_components/map/layers/units-layer.tsx b/sigap-website/app/_components/map/layers/units-layer.tsx
index ffe9def..03544cb 100644
--- a/sigap-website/app/_components/map/layers/units-layer.tsx
+++ b/sigap-website/app/_components/map/layers/units-layer.tsx
@@ -30,6 +30,20 @@ interface IDistrictIncidents {
timestamp: Date
}
+// New interface to better type the incident properties
+interface IncidentProperties {
+ id: string
+ description: string
+ category: string
+ date: string
+ district: string
+ district_id: string
+ categoryColor: string
+ distance_to_unit: number | "Unknown"
+ longitude: number
+ latitude: number
+}
+
export default function UnitsLayer({ crimes, units = [], filterCategory, visible = false, map }: UnitsLayerProps) {
const [loadedUnits, setLoadedUnits] = useState([])
const loadedUnitsRef = useRef([])
@@ -50,6 +64,9 @@ export default function UnitsLayer({ crimes, units = [], filterCategory, visible
5
)
+ // Add a ref to store pre-processed incidents by district for optimization
+ const districtIncidentsCache = useRef