-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Carte] sélection des couches au survol (#1321)
- Loading branch information
Showing
62 changed files
with
992 additions
and
338 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { MonitorEnvLayers, type RegulatoryOrAMPLayerType } from 'domain/entities/layers/constants' | ||
|
||
import type { AMPProperties } from 'domain/entities/AMPs' | ||
import type { RegulatoryLayerCompactProperties } from 'domain/entities/regulatory' | ||
|
||
export const getTitle = name => (name ? `${name?.replace(/[_]/g, ' ')}` : '') | ||
|
||
export const getGroupName = ( | ||
layer: AMPProperties | RegulatoryLayerCompactProperties, | ||
layerType: RegulatoryOrAMPLayerType | ||
) => { | ||
if (layerType === MonitorEnvLayers.AMP || layerType === MonitorEnvLayers.AMP_PREVIEW) { | ||
return (layer as AMPProperties).name | ||
} | ||
|
||
return (layer as RegulatoryLayerCompactProperties).layer_name | ||
} | ||
|
||
export const getName = ( | ||
layer: AMPProperties | RegulatoryLayerCompactProperties, | ||
layerType: RegulatoryOrAMPLayerType | ||
) => { | ||
if (layerType === MonitorEnvLayers.AMP || layerType === MonitorEnvLayers.AMP_PREVIEW) { | ||
return (layer as AMPProperties).type | ||
} | ||
|
||
return (layer as RegulatoryLayerCompactProperties).entity_name | ||
} | ||
|
||
export const getLegendKey = ( | ||
layer: AMPProperties | RegulatoryLayerCompactProperties, | ||
layerType: RegulatoryOrAMPLayerType | ||
) => { | ||
if (layerType === MonitorEnvLayers.AMP || layerType === MonitorEnvLayers.AMP_PREVIEW) { | ||
return (layer as AMPProperties).name | ||
} | ||
|
||
return (layer as RegulatoryLayerCompactProperties).entity_name | ||
} | ||
|
||
export const getLegendType = ( | ||
layer: AMPProperties | RegulatoryLayerCompactProperties, | ||
layerType: RegulatoryOrAMPLayerType | ||
) => { | ||
if (layerType === MonitorEnvLayers.AMP || layerType === MonitorEnvLayers.AMP_PREVIEW) { | ||
return (layer as AMPProperties).type | ||
} | ||
|
||
return (layer as RegulatoryLayerCompactProperties).thematique | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,78 @@ | ||
import type { InteractionListener, InteractionType } from '../entities/map/constants' | ||
import Feature, { type FeatureLike } from 'ol/Feature' | ||
import { GeoJSON } from 'ol/format' | ||
|
||
import { OPENLAYERS_PROJECTION, type InteractionListener, type InteractionType } from '../entities/map/constants' | ||
|
||
import type { Coordinate } from 'ol/coordinate' | ||
import type { Geometry } from 'ol/geom' | ||
|
||
export type OverlayItem<T, P> = { | ||
layerType: T | ||
properties: P | ||
} | ||
export type MapClickEvent = { | ||
coordinates: Coordinate | undefined | ||
ctrlKeyPressed: boolean | ||
feature: Object | ||
feature: SerializedFeature<Record<string, any>> | undefined | ||
featureList: SerializedFeature<Record<string, any>>[] | undefined | ||
} | ||
|
||
export type InteractionTypeAndListener = { | ||
listener: InteractionListener | ||
type: InteractionType | ||
} | ||
|
||
export type SerializedFeature<T> = { | ||
geometry: Geometry | ||
id: string | number | ||
properties: T | ||
} | ||
|
||
export const convertToSerializedFeature = <P>( | ||
feature: Feature<Geometry> | undefined | ||
): SerializedFeature<P> | undefined => { | ||
if (!feature) { | ||
return undefined | ||
} | ||
const geometry = feature.getGeometry() | ||
if (!geometry) { | ||
return undefined | ||
} | ||
|
||
return { | ||
geometry, | ||
id: feature.getId() as string | number, | ||
properties: feature.getProperties() as P | ||
} | ||
} | ||
|
||
const parser = new GeoJSON({ featureProjection: OPENLAYERS_PROJECTION }) | ||
|
||
export function getGeoJSONFromFeature<P>(feature: Feature<Geometry> | FeatureLike | undefined) { | ||
if (!feature || !(feature instanceof Feature)) { | ||
return undefined | ||
} | ||
|
||
return parser.writeFeatureObject(feature) as SerializedFeature<P> | ||
} | ||
|
||
export const getGeoJSONFromFeatureList = (features: (Feature<Geometry> | FeatureLike | undefined)[]) => | ||
features.reduce((acc, feature) => { | ||
const geoJSONFeature = getGeoJSONFromFeature(feature) | ||
if (geoJSONFeature) { | ||
acc.push(geoJSONFeature) | ||
} | ||
|
||
return acc | ||
}, [] as SerializedFeature<any>[]) | ||
|
||
export const convertToFeature = <P>( | ||
serializedFeature: SerializedFeature<P> | undefined | ||
): Feature<Geometry> | undefined => { | ||
if (!serializedFeature) { | ||
return undefined | ||
} | ||
const feature = parser.readFeature(serializedFeature) | ||
|
||
return feature | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.