Skip to content

Commit

Permalink
[Tech] clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
claire2212 committed Dec 12, 2024
1 parent e33c08d commit 269b891
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useGetVigilanceAreasQuery } from '@api/vigilanceAreasAPI'
import { getIsolatedLayerIsVigilanceArea } from '@features/map/layers/utils'
import { useAppSelector } from '@hooks/useAppSelector'
import { Layers } from 'domain/entities/layers/constants'
import { Feature } from 'ol'
Expand All @@ -21,8 +20,6 @@ export function VigilanceAreasLayer({ map }: BaseMapChildrenProps) {
const myVigilanceAreaIdsDisplayed = useAppSelector(state => state.vigilanceArea.myVigilanceAreaIdsDisplayed)

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

const isLayerVisible = displayVigilanceAreaLayer

Expand All @@ -38,7 +35,7 @@ export function VigilanceAreasLayer({ map }: BaseMapChildrenProps) {
zIndex: Layers.VIGILANCE_AREA.zIndex
})
) as React.MutableRefObject<VectorLayerWithName>
;(vectorLayerRef.current as VectorLayerWithName).name = Layers.VIGILANCE_AREA.code
vectorLayerRef.current.name = Layers.VIGILANCE_AREA.code

useEffect(() => {
if (map) {
Expand All @@ -59,14 +56,7 @@ export function VigilanceAreasLayer({ map }: BaseMapChildrenProps) {
vectorSourceRef.current.addFeatures(features)
}
}
}, [
areLayersFilled,
isolatedLayer,
isolatedLayerIsVigilanceArea,
map,
myVigilanceAreaIdsDisplayed,
vigilanceAreas?.entities
])
}, [isolatedLayer, map, myVigilanceAreaIdsDisplayed, vigilanceAreas?.entities])

useEffect(() => {
map.getLayers().push(vectorLayerRef.current)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { getIsolatedLayerIsVigilanceArea } from '@features/map/layers/utils'
import { OPENLAYERS_PROJECTION, WSG84_PROJECTION } from '@mtes-mct/monitor-ui'
import { Layers } from 'domain/entities/layers/constants'
import { Feature } from 'ol'
Expand All @@ -14,8 +13,6 @@ export const getVigilanceAreaZoneFeature = (
isolatedLayer: IsolatedLayerType | undefined,
isSelected?: boolean
) => {
const isolatedLayerIsVigilanceArea = getIsolatedLayerIsVigilanceArea(isolatedLayer)

const geoJSON = new GeoJSON()
const geometry = geoJSON.readGeometry(vigilanceArea.geom, {
dataProjection: WSG84_PROJECTION,
Expand All @@ -27,6 +24,7 @@ export const getVigilanceAreaZoneFeature = (
geometry
})

const isolatedLayerIsVigilanceArea = isolatedLayer?.type.includes('VIGILANCE_AREA') ?? false
const isLayerFilled = isolatedLayer
? isolatedLayerIsVigilanceArea && isolatedLayer?.id === vigilanceArea.id && isolatedLayer?.isFilled
: true
Expand Down
5 changes: 2 additions & 3 deletions frontend/src/features/map/layers/AMP/AMPGeometryHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import { getFeature } from '@utils/getFeature'
import { getArea } from 'ol/sphere'

import { getIsolatedLayerIsAmp } from '../utils'

export function getAMPFeature({ code, isolatedLayer, layer }) {
const feature = getFeature(layer.geom)
if (!feature) {
return undefined
}
const isolatedLayerTypeIsAmp = getIsolatedLayerIsAmp(isolatedLayer)
const geometry = feature.getGeometry()
const area = geometry && getArea(geometry)
feature.setId(`${code}:${layer.id}`)

const isolatedLayerTypeIsAmp = isolatedLayer?.type.includes('AMP') ?? false
const isLayerFilled = isolatedLayer
? isolatedLayerTypeIsAmp && isolatedLayer?.id === layer.id && isolatedLayer?.isFilled
: true

feature.setProperties({
area,
isFilled: isLayerFilled,
Expand Down
5 changes: 2 additions & 3 deletions frontend/src/features/map/layers/AMP/AMPPreviewLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,10 @@ export function AMPPreviewLayer({ map }: BaseMapChildrenProps) {
}, [ampLayers?.entities, ampLayers?.ids, ampMetadataLayerId, ampsSearchResult, isolatedLayer, showedAmpLayerIds])

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

if (ampLayersFeatures) {
vectorSource.addFeatures(ampLayersFeatures)
ampPreviewVectorSourceRef.current?.addFeatures(ampLayersFeatures)
}
}, [ampLayersFeatures])

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { getFeature } from '@utils/getFeature'
import { getArea } from 'ol/sphere'

import { getIsolatedLayerIsRegulatoryArea } from '../utils'

import type { IsolatedLayerType } from 'domain/shared_slices/Map'

type RegulatoryFeatureType = {
Expand All @@ -19,7 +17,7 @@ export function getRegulatoryFeature({ code, isolatedLayer, layer }: RegulatoryF
const area = geometry && getArea(geometry)
feature.setId(`${code}:${layer.id}`)

const isolatedLayerTypeIsRegulatory = getIsolatedLayerIsRegulatoryArea(isolatedLayer)
const isolatedLayerTypeIsRegulatory = isolatedLayer?.type.includes('REGULATORY') ?? false
const isLayerFilled = isolatedLayer
? isolatedLayerTypeIsRegulatory && isolatedLayer?.id === layer.id && isolatedLayer?.isFilled
: true
Expand Down
10 changes: 0 additions & 10 deletions frontend/src/features/map/layers/utils.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
import type { IsolatedLayerType } from 'domain/shared_slices/Map'
import type { SerializedFeature } from 'domain/types/map'

export const hasAlreadyFeature = (
currentFeatureOver: SerializedFeature<Record<string, any>> | undefined,
layersId: string[]
) => layersId.some(layerId => typeof currentFeatureOver?.id === 'string' && currentFeatureOver.id.includes(layerId))

export const getIsolatedLayerIsRegulatoryArea = (isolatedLayer: IsolatedLayerType | undefined): boolean =>
isolatedLayer?.type.includes('REGULATORY') ?? false

export const getIsolatedLayerIsAmp = (isolatedLayer: IsolatedLayerType | undefined): boolean =>
isolatedLayer?.type.includes('AMP') ?? false

export const getIsolatedLayerIsVigilanceArea = (isolatedLayer: IsolatedLayerType | undefined): boolean =>
isolatedLayer?.type.includes('VIGILANCE_AREA') ?? false

0 comments on commit 269b891

Please sign in to comment.