Skip to content

Commit

Permalink
[Layers] handle isFilled prop in each feature definition
Browse files Browse the repository at this point in the history
  • Loading branch information
claire2212 committed Dec 12, 2024
1 parent dcfdf73 commit e33c08d
Show file tree
Hide file tree
Showing 14 changed files with 108 additions and 148 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import type { Geometry } from 'ol/geom'
export function ActiveDashboardLayer({ map }: BaseMapChildrenProps) {
const displayDashboardLayer = useAppSelector(state => state.global.displayDashboardLayer)

const isolatedLayer = useAppSelector(state => state.map.isolatedLayer)

const activeDashboardId = useAppSelector(state => state.dashboard.activeDashboardId)
const displayGeometry = useAppSelector(state =>
activeDashboardId ? state.dashboard.dashboards?.[activeDashboardId]?.displayGeometry : false
Expand Down Expand Up @@ -85,6 +87,7 @@ export function ActiveDashboardLayer({ map }: BaseMapChildrenProps) {
if (layer && layer?.geom && layer?.geom?.coordinates.length > 0) {
const feature = getRegulatoryFeature({
code: Dashboard.featuresCode.DASHBOARD_REGULATORY_AREAS,
isolatedLayer,
layer
})
if (!feature) {
Expand Down Expand Up @@ -113,7 +116,7 @@ export function ActiveDashboardLayer({ map }: BaseMapChildrenProps) {
const layer = ampLayers.entities[layerId]

if (layer && layer?.geom && layer?.geom?.coordinates.length > 0) {
const feature = getAMPFeature({ code: Dashboard.featuresCode.DASHBOARD_AMP, layer })
const feature = getAMPFeature({ code: Dashboard.featuresCode.DASHBOARD_AMP, isolatedLayer, layer })

if (!feature) {
return feats
Expand All @@ -140,7 +143,11 @@ export function ActiveDashboardLayer({ map }: BaseMapChildrenProps) {
const features = vigilanceAreaLayersIds.reduce((feats: Feature[], layerId) => {
const layer = vigilanceAreas.entities[layerId]
if (layer && layer?.geom && layer?.geom?.coordinates.length > 0) {
const feature = getVigilanceAreaZoneFeature(layer, Dashboard.featuresCode.DASHBOARD_VIGILANCE_AREAS)
const feature = getVigilanceAreaZoneFeature(
layer,
Dashboard.featuresCode.DASHBOARD_VIGILANCE_AREAS,
isolatedLayer
)
feats.push(feature)
}

Expand Down Expand Up @@ -190,7 +197,8 @@ export function ActiveDashboardLayer({ map }: BaseMapChildrenProps) {
reportings,
dashboard?.dashboard.geom,
drawBorder,
displayGeometry
displayGeometry,
isolatedLayer
])

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import type { Geometry } from 'ol/geom'
export function DashboardPreviewLayer({ map }: BaseMapChildrenProps) {
const displayDashboardLayer = useAppSelector(state => state.global.displayDashboardLayer)

const isolatedLayer = useAppSelector(state => state.map.isolatedLayer)

const activeDashboardId = useAppSelector(state => state.dashboard.activeDashboardId)

const dashboard = useAppSelector(state => getDashboardById(state.dashboard, activeDashboardId))
Expand Down Expand Up @@ -73,6 +75,7 @@ export function DashboardPreviewLayer({ map }: BaseMapChildrenProps) {
if (layer && layer?.geom && layer?.geom?.coordinates.length > 0) {
const feature = getRegulatoryFeature({
code: Dashboard.featuresCode.DASHBOARD_REGULATORY_AREAS,
isolatedLayer,
layer
})
if (!feature) {
Expand All @@ -99,7 +102,7 @@ export function DashboardPreviewLayer({ map }: BaseMapChildrenProps) {
const features = ampToDisplay.reduce((feats: Feature[], layerId) => {
const layer = ampLayers.entities[layerId]
if (layer && layer?.geom && layer?.geom?.coordinates.length > 0) {
const feature = getAMPFeature({ code: Dashboard.featuresCode.DASHBOARD_AMP, layer })
const feature = getAMPFeature({ code: Dashboard.featuresCode.DASHBOARD_AMP, isolatedLayer, layer })
if (!feature) {
return feats
}
Expand All @@ -118,7 +121,11 @@ export function DashboardPreviewLayer({ map }: BaseMapChildrenProps) {
if (vigilanceAreas?.entities && openPanelIsVigilanceArea) {
const layer = vigilanceAreas.entities[openPanel?.id]
if (layer && layer?.geom && layer?.geom?.coordinates.length > 0) {
const feature = getVigilanceAreaZoneFeature(layer, Dashboard.featuresCode.DASHBOARD_VIGILANCE_AREAS)
const feature = getVigilanceAreaZoneFeature(
layer,
Dashboard.featuresCode.DASHBOARD_VIGILANCE_AREAS,
isolatedLayer
)
feature.set('isSelected', true)

previewLayersVectorSourceRef.current.addFeature(feature)
Expand All @@ -135,7 +142,16 @@ export function DashboardPreviewLayer({ map }: BaseMapChildrenProps) {
}
}
}
}, [ampLayers?.entities, dashboard, drawBorder, map, openPanel, regulatoryLayers?.entities, vigilanceAreas?.entities])
}, [
ampLayers?.entities,
dashboard,
drawBorder,
map,
openPanel,
regulatoryLayers?.entities,
vigilanceAreas?.entities,
isolatedLayer
])

useEffect(() => {
map.getLayers().push(previewLayersVectorLayerRef.current)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export function SelectedDashboardLayer({ map }: BaseMapChildrenProps) {
const { displayDashboardLayer } = useAppSelector(state => state.global)
const selectedDashboardOnMap = useAppSelector(state => state.dashboard.selectedDashboardOnMap)

const isolatedLayer = useAppSelector(state => state.map.isolatedLayer)

const dashboardDatasVectorSourceRef = useRef(new VectorSource()) as MutableRefObject<VectorSource<Feature<Geometry>>>
const dashboardDatasVectorLayerRef = useRef(
new VectorLayer({
Expand Down Expand Up @@ -88,6 +90,7 @@ export function SelectedDashboardLayer({ map }: BaseMapChildrenProps) {
selectedDashboardOnMap.amps.forEach(amp => {
const ampFeature = getAMPFeature({
code: Dashboard.featuresCode.DASHBOARD_AMP,
isolatedLayer,
layer: amp
})

Expand All @@ -100,6 +103,7 @@ export function SelectedDashboardLayer({ map }: BaseMapChildrenProps) {
selectedDashboardOnMap.regulatoryAreas.forEach(regulatoryArea => {
const regulatoryAreaFeature = getRegulatoryFeature({
code: Dashboard.featuresCode.DASHBOARD_REGULATORY_AREAS,
isolatedLayer,
layer: regulatoryArea
})
if (!regulatoryAreaFeature) {
Expand All @@ -111,13 +115,14 @@ export function SelectedDashboardLayer({ map }: BaseMapChildrenProps) {
selectedDashboardOnMap.vigilanceAreas.forEach(vigilanceArea => {
const vigilanceAreaFeature = getVigilanceAreaZoneFeature(
vigilanceArea,
Dashboard.featuresCode.DASHBOARD_VIGILANCE_AREAS
Dashboard.featuresCode.DASHBOARD_VIGILANCE_AREAS,
isolatedLayer
)

feats.push(vigilanceAreaFeature)
})

dashboardDatasVectorSourceRef.current?.addFeatures(feats)
}
}, [dispatch, selectedDashboardOnMap])
}, [dispatch, selectedDashboardOnMap, isolatedLayer])
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export function EditingVigilanceAreaLayer({ map }: BaseMapChildrenProps) {
const ampToAdd = useAppSelector(state => state.vigilanceArea.ampToAdd)
const vigilanceAreaGeom = useAppSelector(state => state.vigilanceArea.geometry)

const isolatedLayer = useAppSelector(state => state.map.isolatedLayer)

const isLayerVisible = !!editingVigilanceAreaId

// Vigilance Area
Expand All @@ -42,11 +44,11 @@ export function EditingVigilanceAreaLayer({ map }: BaseMapChildrenProps) {
}

if (editingVigilanceArea) {
return getVigilanceAreaZoneFeature(editingVigilanceArea, Layers.VIGILANCE_AREA.code, true)
return getVigilanceAreaZoneFeature(editingVigilanceArea, Layers.VIGILANCE_AREA.code, isolatedLayer, true)
}

return undefined
}, [editingVigilanceArea, vigilanceAreaGeom])
}, [editingVigilanceArea, vigilanceAreaGeom, isolatedLayer])

const vectorSourceRef = useRef(new VectorSource()) as React.MutableRefObject<VectorSource<Feature<Geometry>>>
const vectorLayerRef = useRef(
Expand All @@ -72,6 +74,7 @@ export function EditingVigilanceAreaLayer({ map }: BaseMapChildrenProps) {
if (regulatorylayer) {
const feature = getRegulatoryFeature({
code: Layers.REGULATORY_AREAS_LINKED_TO_VIGILANCE_AREA.code,
isolatedLayer,
layer: regulatorylayer
})
if (!feature) {
Expand All @@ -83,7 +86,7 @@ export function EditingVigilanceAreaLayer({ map }: BaseMapChildrenProps) {

return feats
}, [])
}, [regulatoryLayers, regulatoryAreasToAdd])
}, [regulatoryLayers, regulatoryAreasToAdd, isolatedLayer])

const regulatoryAreasVectorSourceRef = useRef(new VectorSource()) as MutableRefObject<VectorSource<Feature<Geometry>>>
const regulatoryAreasVectorLayerRef = useRef(
Expand Down Expand Up @@ -111,6 +114,7 @@ export function EditingVigilanceAreaLayer({ map }: BaseMapChildrenProps) {
if (ampLayer) {
const feature = getAMPFeature({
code: Layers.AMP_LINKED_TO_VIGILANCE_AREA.code,
isolatedLayer,
layer: ampLayer
})
if (!feature) {
Expand All @@ -125,7 +129,7 @@ export function EditingVigilanceAreaLayer({ map }: BaseMapChildrenProps) {

[]
)
}, [ampLayers, ampToAdd])
}, [ampLayers, ampToAdd, isolatedLayer])

const ampVectorSourceRef = useRef(new VectorSource()) as MutableRefObject<VectorSource<Feature<Geometry>>>
const ampVectorLayerRef = useRef(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { getIsolatedLayerIsVigilanceArea } from '@features/map/layers/utils'
import { useGetFilteredVigilanceAreasQuery } from '@features/VigilanceArea/hooks/useGetFilteredVigilanceAreasQuery'
import { useAppSelector } from '@hooks/useAppSelector'
import { Layers } from 'domain/entities/layers/constants'
import { convertToFeature } from 'domain/types/map'
import { Feature } from 'ol'
import VectorLayer from 'ol/layer/Vector'
import VectorSource from 'ol/source/Vector'
Expand All @@ -15,7 +13,7 @@ import type { BaseMapChildrenProps } from '@features/map/BaseMap'
import type { VectorLayerWithName } from 'domain/types/layer'
import type { Geometry } from 'ol/geom'

export function PreviewVigilanceAreasLayer({ currentFeatureOver, map }: BaseMapChildrenProps) {
export function PreviewVigilanceAreasLayer({ map }: BaseMapChildrenProps) {
const displayVigilanceAreaLayer = useAppSelector(state => state.global.displayVigilanceAreaLayer)

const vigilanceAreaSearchResult = useAppSelector(state => state.layerSearch.vigilanceAreaSearchResult)
Expand All @@ -26,10 +24,8 @@ export function PreviewVigilanceAreasLayer({ currentFeatureOver, map }: BaseMapC
const isLayerVisible = displayVigilanceAreaLayer && isVigilanceAreaSearchResultsVisible && isLayersSidebarVisible

const isolatedLayer = useAppSelector(state => state.map.isolatedLayer)
const isolatedLayerIsVigilanceArea = getIsolatedLayerIsVigilanceArea(isolatedLayer)

const { vigilanceAreas } = useGetFilteredVigilanceAreasQuery()
const areLayersFilled = isolatedLayer === undefined

const vectorSourceRef = useRef(new VectorSource()) as React.MutableRefObject<VectorSource<Feature<Geometry>>>
const vectorLayerRef = useRef(
Expand All @@ -41,7 +37,7 @@ export function PreviewVigilanceAreasLayer({ currentFeatureOver, map }: BaseMapC
zIndex: Layers.VIGILANCE_AREA_PREVIEW.zIndex
})
) as React.MutableRefObject<VectorLayerWithName>
;(vectorLayerRef.current as VectorLayerWithName).name = Layers.VIGILANCE_AREA_PREVIEW.code
vectorLayerRef.current.name = Layers.VIGILANCE_AREA_PREVIEW.code

const vigilanceAreasFeatures = useMemo(() => {
let features: Feature[] = []
Expand All @@ -52,10 +48,8 @@ export function PreviewVigilanceAreasLayer({ currentFeatureOver, map }: BaseMapC
const layer = vigilanceAreas?.entities[id]

if (layer && layer?.geom && layer?.geom?.coordinates.length > 0) {
const feature = getVigilanceAreaZoneFeature(layer, Layers.VIGILANCE_AREA_PREVIEW.code, false, areLayersFilled)
if (isolatedLayerIsVigilanceArea && isolatedLayer?.id === id) {
feature.set('isFilled', isolatedLayer.isFilled)
}
const feature = getVigilanceAreaZoneFeature(layer, Layers.VIGILANCE_AREA_PREVIEW.code, isolatedLayer)

layers.push(feature)
}

Expand All @@ -64,36 +58,14 @@ export function PreviewVigilanceAreasLayer({ currentFeatureOver, map }: BaseMapC
}

return features
}, [areLayersFilled, isolatedLayer, isolatedLayerIsVigilanceArea, vigilanceAreaSearchResult, vigilanceAreas])
}, [isolatedLayer, vigilanceAreaSearchResult, vigilanceAreas])

useEffect(() => {
const vectorSource = vectorSourceRef.current
vectorSource.clear(true)

const feature = convertToFeature(currentFeatureOver)

vectorSourceRef.current?.clear(true)
if (vigilanceAreasFeatures) {
const isHoveredFeature = feature?.getId()?.toString()?.includes(Layers.VIGILANCE_AREA_PREVIEW.code)

if (feature && isHoveredFeature && !areLayersFilled) {
feature.set('isFilled', true)

// Exclude the current feature and re-add it with updated properties
const filteredFeatures = vigilanceAreasFeatures.filter(f => f.getId() !== feature?.getId()) ?? []
vectorSource.addFeatures([...filteredFeatures, feature])

return
}

vectorSource.addFeatures(vigilanceAreasFeatures)

return
}

if (feature) {
vectorSource.addFeature(feature)
vectorSourceRef.current?.addFeatures(vigilanceAreasFeatures)
}
}, [vigilanceAreasFeatures, areLayersFilled, currentFeatureOver])
}, [vigilanceAreasFeatures])

useEffect(() => {
if (map) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,18 @@ export function SelectedVigilanceAreaLayer({ map }: BaseMapChildrenProps) {
skip: !selectedVigilanceAreaId
})

const isolatedLayer = useAppSelector(state => state.map.isolatedLayer)

const isLayerVisible = !!selectedVigilanceAreaId && selectedVigilanceAreaId !== editingVigilanceAreaId

// Vigilance Area
const vigilanceAreasFeature = useMemo(() => {
if (selectedVigilanceArea) {
return getVigilanceAreaZoneFeature(selectedVigilanceArea, Layers.VIGILANCE_AREA.code, true)
return getVigilanceAreaZoneFeature(selectedVigilanceArea, Layers.VIGILANCE_AREA.code, isolatedLayer, true)
}

return undefined
}, [selectedVigilanceArea])
}, [selectedVigilanceArea, isolatedLayer])

const vectorSourceRef = useRef(new VectorSource()) as React.MutableRefObject<VectorSource<Feature<Geometry>>>
const vectorLayerRef = useRef(
Expand Down Expand Up @@ -79,6 +81,7 @@ export function SelectedVigilanceAreaLayer({ map }: BaseMapChildrenProps) {
if (regulatorylayer && isRegulatoryAreaShouldBeDisplayed) {
const feature = getRegulatoryFeature({
code: Layers.REGULATORY_AREAS_LINKED_TO_VIGILANCE_AREA.code,
isolatedLayer,
layer: regulatorylayer
})

Expand All @@ -94,7 +97,8 @@ export function SelectedVigilanceAreaLayer({ map }: BaseMapChildrenProps) {
selectedVigilanceArea?.linkedRegulatoryAreas,
regulatoryLayers,
regulatoryAreaIdsToBeDisplayed,
showedPinnedRegulatoryLayerIds
showedPinnedRegulatoryLayerIds,
isolatedLayer
])

const regulatoryAreasVectorSourceRef = useRef(new VectorSource()) as MutableRefObject<VectorSource<Feature<Geometry>>>
Expand Down Expand Up @@ -130,6 +134,7 @@ export function SelectedVigilanceAreaLayer({ map }: BaseMapChildrenProps) {
if (AMPlayer && isAMPShouldBeDisplayed) {
const feature = getAMPFeature({
code: Layers.AMP_LINKED_TO_VIGILANCE_AREA.code,
isolatedLayer,
layer: AMPlayer
})
if (!feature) {
Expand All @@ -140,7 +145,7 @@ export function SelectedVigilanceAreaLayer({ map }: BaseMapChildrenProps) {

return feats
}, [])
}, [ampLayers, selectedVigilanceArea?.linkedAMPs, ampIdsToBeDisplayed, showedPinnedAMPLayerIds])
}, [ampLayers, selectedVigilanceArea?.linkedAMPs, ampIdsToBeDisplayed, showedPinnedAMPLayerIds, isolatedLayer])

const ampVectorSourceRef = useRef(new VectorSource()) as MutableRefObject<VectorSource<Feature<Geometry>>>
const ampVectorLayerRef = useRef(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,8 @@ export function VigilanceAreasLayer({ map }: BaseMapChildrenProps) {
const features = myVigilanceAreaIdsDisplayed.reduce((feats: Feature[], layerId) => {
const layer = vigilanceAreas.entities[layerId]
if (layer && layer?.geom && layer?.geom?.coordinates.length > 0) {
const feature = getVigilanceAreaZoneFeature(layer, Layers.VIGILANCE_AREA.code, false, areLayersFilled)
if (isolatedLayerIsVigilanceArea && isolatedLayer?.id === layerId) {
feature.set('isFilled', isolatedLayer.isFilled)
}
const feature = getVigilanceAreaZoneFeature(layer, Layers.VIGILANCE_AREA.code, isolatedLayer)

feats.push(feature)
}

Expand All @@ -63,8 +61,7 @@ export function VigilanceAreasLayer({ map }: BaseMapChildrenProps) {
}
}, [
areLayersFilled,
isolatedLayer?.id,
isolatedLayer?.isFilled,
isolatedLayer,
isolatedLayerIsVigilanceArea,
map,
myVigilanceAreaIdsDisplayed,
Expand Down
Loading

0 comments on commit e33c08d

Please sign in to comment.