-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dff9138
commit a2ce0b1
Showing
2 changed files
with
125 additions
and
123 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
57 changes: 57 additions & 0 deletions
57
frontend/src/features/Measurement/useCases/addCustomCircleMeasurement.ts
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,57 @@ | ||
import { measurementStyle, measurementStyleWithCenter } from '@features/Measurement/layers/measurement.style' | ||
import { saveMeasurement } from '@features/Measurement/useCases/saveMeasurement' | ||
import Feature from 'ol/Feature' | ||
import { circular } from 'ol/geom/Polygon' | ||
import { METERS_PER_UNIT, transform } from 'ol/proj' | ||
|
||
import { OPENLAYERS_PROJECTION, WSG84_PROJECTION } from '../../../domain/entities/map/constants' | ||
|
||
import type { MeasurementInProgress } from '@features/Measurement/types' | ||
import type { Coordinate } from 'ol/coordinate' | ||
|
||
export const addCustomCircleMeasurement = | ||
(measurementInProgress: MeasurementInProgress | undefined) => (dispatch, getState) => { | ||
const { circleMeasurementToAdd } = getState().measurement | ||
const metersForOneNauticalMile = 1852 | ||
const longitude = 1 | ||
const latitude = 0 | ||
const numberOfVertices = 64 | ||
|
||
if ( | ||
!circleMeasurementHasCoordinatesAndRadiusFromForm() && | ||
!circleMeasurementHasRadiusFromFormAndCoordinatesFromDraw() | ||
) { | ||
return | ||
} | ||
|
||
const radiusInMeters = | ||
METERS_PER_UNIT.m * ((circleMeasurementToAdd?.circleRadiusToAdd ?? 0) as number) * metersForOneNauticalMile | ||
|
||
let coordinates: Coordinate = [] | ||
if (circleMeasurementHasCoordinatesAndRadiusFromForm()) { | ||
coordinates = [ | ||
circleMeasurementToAdd!.circleCoordinatesToAdd![longitude]!, | ||
circleMeasurementToAdd!.circleCoordinatesToAdd![latitude]! | ||
] | ||
} else if (circleMeasurementHasRadiusFromFormAndCoordinatesFromDraw()) { | ||
coordinates = transform(measurementInProgress!.center!, OPENLAYERS_PROJECTION, WSG84_PROJECTION) | ||
} | ||
|
||
const circleFeature = new Feature({ | ||
geometry: circular(coordinates, radiusInMeters, numberOfVertices).transform( | ||
WSG84_PROJECTION, | ||
OPENLAYERS_PROJECTION | ||
), | ||
style: [measurementStyle, measurementStyleWithCenter] | ||
}) | ||
|
||
dispatch(saveMeasurement(circleFeature, `r = ${circleMeasurementToAdd?.circleRadiusToAdd} nm`)) | ||
|
||
function circleMeasurementHasCoordinatesAndRadiusFromForm() { | ||
return circleMeasurementToAdd?.circleCoordinatesToAdd?.length === 2 && circleMeasurementToAdd?.circleRadiusToAdd | ||
} | ||
|
||
function circleMeasurementHasRadiusFromFormAndCoordinatesFromDraw() { | ||
return circleMeasurementToAdd?.circleRadiusToAdd && measurementInProgress?.center?.length === 2 | ||
} | ||
} |