Skip to content

Commit 7d305aa

Browse files
Revert "Add GeometryType enum"
This reverts commit 5ddde77.
1 parent 916330b commit 7d305aa

6 files changed

Lines changed: 43 additions & 58 deletions

File tree

src/client/javascripts/geospatial-map.js

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
getCentroidGridRef,
88
getCoordinateGridRef
99
} from '~/src/client/javascripts/map.js'
10-
import { GeometryType } from '~/src/server/plugins/engine/types.js'
1110

1211
const helpPanelConfig = {
1312
showLabel: true,
@@ -46,7 +45,7 @@ const polygonFeatureProperties = {
4645
}
4746

4847
/**
49-
* @type {Record<GeometryType.Point | GeometryType.LineString | GeometryType.Polygon, string>}
48+
* @type {Record<'Point' | 'LineString' | 'Polygon', string>}
5049
*/
5150
const typeDescriptions = {
5251
Point: 'Point',
@@ -147,13 +146,13 @@ export function processGeospatial(config, geospatial, index) {
147146
*/
148147
export function addFeatureToMap(feature, drawPlugin, map) {
149148
switch (feature.geometry.type) {
150-
case GeometryType.Polygon:
149+
case 'Polygon':
151150
drawPlugin.addFeature({ ...feature, ...polygonFeatureProperties })
152151
break
153-
case GeometryType.LineString:
152+
case 'LineString':
154153
drawPlugin.addFeature({ ...feature, ...lineFeatureProperties })
155154
break
156-
case GeometryType.Point:
155+
case 'Point':
157156
map.addMarker(feature.id, feature.geometry.coordinates)
158157
break
159158
default:
@@ -327,9 +326,9 @@ function prepareGeometry(feature) {
327326
coordinates[1] = +coordinates[1].toFixed(maxPrecision)
328327
}
329328

330-
if (geometry.type === GeometryType.Point) {
329+
if (geometry.type === 'Point') {
331330
formatPrecision(geometry.coordinates)
332-
} else if (geometry.type === GeometryType.LineString) {
331+
} else if (geometry.type === 'LineString') {
333332
geometry.coordinates.forEach(formatPrecision)
334333
} else {
335334
geometry.coordinates.flat().forEach(formatPrecision)
@@ -718,7 +717,7 @@ function onInteractMarkerChangedFactory(context) {
718717
if (activeFeatureId) {
719718
// Editing an existing point
720719
const feature = updateFeature(activeFeatureId, {
721-
type: GeometryType.Point,
720+
type: 'Point',
722721
coordinates: e.coords
723722
})
724723

@@ -739,7 +738,7 @@ function onInteractMarkerChangedFactory(context) {
739738
description: ''
740739
},
741740
geometry: {
742-
type: GeometryType.Point,
741+
type: 'Point',
743742
coordinates: e.coords
744743
},
745744
id
@@ -780,10 +779,10 @@ function onListElClickFactory(context) {
780779
/**
781780
* Delete a feature
782781
* @param {string} id - the feature id
783-
* @param {GeometryType} type - the feature type
782+
* @param {string} type - the feature type
784783
*/
785784
function deleteFeature(id, type) {
786-
if (type === GeometryType.Point) {
785+
if (type === 'Point') {
787786
map.removeMarker(id)
788787
removeFeature(id)
789788
} else {
@@ -797,13 +796,13 @@ function onListElClickFactory(context) {
797796
/**
798797
* Start editing feature
799798
* @param {string} id - the feature id
800-
* @param {GeometryType} type - the feature type
799+
* @param {string} type - the feature type
801800
*/
802801
function editFeature(id, type) {
803802
setActiveFeature(id)
804803

805804
// "Change" feature link was clicked
806-
if (type === GeometryType.Point) {
805+
if (type === 'Point') {
807806
interactPlugin.selectFeature({ featureId: id })
808807
interactPlugin.enable()
809808
} else {
@@ -845,14 +844,14 @@ function onListElClickFactory(context) {
845844

846845
if (action === 'edit') {
847846
// "Update" feature link was clicked
848-
editFeature(id, /** @type {GeometryType} */ (type))
847+
editFeature(id, type)
849848
} else {
850849
e.preventDefault()
851850
e.stopPropagation()
852851

853852
if (action === 'delete') {
854853
// "Remove" feature link was clicked
855-
deleteFeature(id, /** @type {GeometryType} */ (type))
854+
deleteFeature(id, type)
856855
}
857856
}
858857
}

src/client/javascripts/map.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import OsGridRef, { LatLon } from 'geodesy/osgridref.js'
44

55
import { processGeospatial } from '~/src/client/javascripts/geospatial-map.js'
66
import { processLocation } from '~/src/client/javascripts/location-map.js'
7-
import { GeometryType } from '~/src/server/plugins/engine/types.js'
87

98
// Center of UK
109
const DEFAULT_LAT = 53.825564
@@ -74,12 +73,12 @@ export function osGridRefToLatLong(osGridRef) {
7473
* @param {Feature} feature
7574
*/
7675
export function getCoordinateGridRef(feature) {
77-
if (feature.geometry.type === GeometryType.Point) {
76+
if (feature.geometry.type === 'Point') {
7877
const [long, lat] = feature.geometry.coordinates
7978
const point = new LatLon(lat, long)
8079

8180
return point.toOsGrid().toString()
82-
} else if (feature.geometry.type === GeometryType.LineString) {
81+
} else if (feature.geometry.type === 'LineString') {
8382
const [long, lat] = feature.geometry.coordinates[0]
8483
const point = new LatLon(lat, long)
8584

@@ -97,7 +96,7 @@ export function getCoordinateGridRef(feature) {
9796
* @param {Feature} feature
9897
*/
9998
export function getCentroidGridRef(feature) {
100-
if (feature.geometry.type === GeometryType.Point) {
99+
if (feature.geometry.type === 'Point') {
101100
const [long, lat] = feature.geometry.coordinates
102101
const point = new LatLon(lat, long)
103102

src/server/plugins/engine/components/helpers/__stubs__/geospatial.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import {
2-
GeometryType,
3-
type GeospatialState
4-
} from '~/src/server/plugins/engine/types.js'
1+
import { type GeospatialState } from '~/src/server/plugins/engine/types.js'
52

63
export const validState: GeospatialState = [
74
{
@@ -13,7 +10,7 @@ export const validState: GeospatialState = [
1310
},
1411
geometry: {
1512
coordinates: [-2.5723699109417737, 53.2380485215034],
16-
type: GeometryType.Point
13+
type: 'Point'
1714
},
1815
id: 'a'
1916
},
@@ -29,7 +26,7 @@ export const validState: GeospatialState = [
2926
[-2.570496516462896, 53.239162468888566],
3027
[-2.5722447488110447, 53.238174174285746]
3128
],
32-
type: GeometryType.LineString
29+
type: 'LineString'
3330
},
3431
id: 'b'
3532
},
@@ -52,7 +49,7 @@ export const validState: GeospatialState = [
5249
[-2.573552894955583, 53.238229751360706]
5350
]
5451
],
55-
type: GeometryType.Polygon
52+
type: 'Polygon'
5653
},
5754
id: 'c'
5855
},
@@ -65,7 +62,7 @@ export const validState: GeospatialState = [
6562
},
6663
geometry: {
6764
coordinates: [-2.5724, 53.239],
68-
type: GeometryType.Point
65+
type: 'Point'
6966
},
7067
id: 'd'
7168
}
@@ -81,7 +78,7 @@ export const validSingleState: GeospatialState = [
8178
},
8279
geometry: {
8380
coordinates: [-2.5723699109417737, 53.2380485215034],
84-
type: GeometryType.Point
81+
type: 'Point'
8582
},
8683
id: 'a'
8784
}

src/server/plugins/engine/components/helpers/geospatial.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import Bourne from '@hapi/bourne'
22
import JoiBase from 'joi'
33

44
import {
5-
GeometryType,
65
type Coordinates,
76
type Feature,
87
type FeatureProperties,
@@ -59,19 +58,17 @@ const featurePropertiesSchema = Joi.object<FeatureProperties>()
5958
.required()
6059

6160
const featureGeometrySchema = Joi.object<Geometry>().keys({
62-
type: Joi.string()
63-
.valid(GeometryType.Point, GeometryType.LineString, GeometryType.Polygon)
64-
.required(),
61+
type: Joi.string().valid('Point', 'LineString', 'Polygon').required(),
6562
coordinates: Joi.array()
6663
.when('type', {
6764
switch: [
68-
{ is: GeometryType.Point, then: coordinatesSchema },
65+
{ is: 'Point', then: coordinatesSchema },
6966
{
70-
is: GeometryType.LineString,
67+
is: 'LineString',
7168
then: Joi.array().items(coordinatesSchema).min(2)
7269
},
7370
{
74-
is: GeometryType.Polygon,
71+
is: 'Polygon',
7572
then: Joi.array().items(Joi.array().items(coordinatesSchema).min(3))
7673
}
7774
]

src/server/plugins/engine/types.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -288,12 +288,6 @@ export interface RepeatItemState extends FormPayload {
288288

289289
export type RepeatListState = RepeatItemState[]
290290

291-
export enum GeometryType {
292-
Point = 'Point',
293-
LineString = 'LineString',
294-
Polygon = 'Polygon'
295-
}
296-
297291
/**
298292
* A longitude/latitude coordinate pair in WGS84 format
299293
* Format: [longitude, latitude]
@@ -304,23 +298,23 @@ export type Coordinates = [longitude: number, latitude: number]
304298
* GeoJSON Point geometry
305299
*/
306300
export interface PointGeometry {
307-
type: GeometryType.Point
301+
type: 'Point'
308302
coordinates: Coordinates
309303
}
310304

311305
/**
312306
* GeoJSON LineString geometry
313307
*/
314308
export interface LineStringGeometry {
315-
type: GeometryType.LineString
309+
type: 'LineString'
316310
coordinates: Coordinates[]
317311
}
318312

319313
/**
320314
* GeoJSON Polygon geometry
321315
*/
322316
export interface PolygonGeometry {
323-
type: GeometryType.Polygon
317+
type: 'Polygon'
324318
coordinates: Coordinates[][]
325319
}
326320

test/client/javascripts/map.test.js

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
initMaps,
66
makeTileRequestTransformer
77
} from '~/src/client/javascripts/map.js'
8-
import { GeometryType } from '~/src/server/plugins/engine/types.js'
98

109
describe('Maps Client JS', () => {
1110
/** @type {jest.Mock} */
@@ -606,7 +605,7 @@ describe('Maps Client JS', () => {
606605
centroidGridReference: 'TQ 29031 79662'
607606
},
608607
geometry: {
609-
type: GeometryType.Point,
608+
type: 'Point',
610609
coordinates: [-0.14242385752663722, 51.50118200993498]
611610
},
612611
id: '6d67810c-7228-4f71-b6ec-0d16b132fcd7'
@@ -635,7 +634,7 @@ describe('Maps Client JS', () => {
635634
[-0.13995851581486818, 51.50204381014825]
636635
]
637636
],
638-
type: GeometryType.Polygon
637+
type: 'Polygon'
639638
}
640639
},
641640
{
@@ -651,7 +650,7 @@ describe('Maps Client JS', () => {
651650
[-0.14969813781837615, 51.502534952613814],
652651
[-0.1404050934734471, 51.50217984872572]
653652
],
654-
type: GeometryType.LineString
653+
type: 'LineString'
655654
}
656655
}
657656
]
@@ -870,7 +869,7 @@ describe('Maps Client JS', () => {
870869
id: 'guid',
871870
type: 'Feature',
872871
geometry: {
873-
type: GeometryType.Polygon,
872+
type: 'Polygon',
874873
coordinates: [
875874
[
876875
[-2.0868919921875886, 53.896834237148596],
@@ -908,7 +907,7 @@ describe('Maps Client JS', () => {
908907
id: 'guid1',
909908
type: 'Feature',
910909
geometry: {
911-
type: GeometryType.LineString,
910+
type: 'LineString',
912911
coordinates: [
913912
[-1.3068626953125317, 54.019651598965936],
914913
[-2.0868919921875886, 53.896834237148596]
@@ -969,7 +968,7 @@ describe('Maps Client JS', () => {
969968
const updatedPolygonFeature = {
970969
...features[1],
971970
geometry: {
972-
type: GeometryType.Polygon,
971+
type: 'Polygon',
973972
coordinates: [
974973
[
975974
[0, 0],
@@ -1055,7 +1054,7 @@ describe('Maps Client JS', () => {
10551054
...features,
10561055
{
10571056
geometry: {
1058-
type: GeometryType.Point,
1057+
type: 'Point',
10591058
coordinates: [-2.086892, 53.8968342]
10601059
},
10611060
properties: {
@@ -1358,7 +1357,7 @@ describe('Maps Client JS', () => {
13581357
id: 'id',
13591358
type: 'Feature',
13601359
geometry: {
1361-
type: GeometryType.Point,
1360+
type: 'Point',
13621361
coordinates: [-0.1356213, 51.5121161]
13631362
},
13641363
properties: {
@@ -1374,7 +1373,7 @@ describe('Maps Client JS', () => {
13741373
id: 'id',
13751374
type: 'Feature',
13761375
geometry: {
1377-
type: GeometryType.LineString,
1376+
type: 'LineString',
13781377
coordinates: [
13791378
[-0.1356213, 51.5121161],
13801379
[-0.0578579, 51.5182996]
@@ -1393,7 +1392,7 @@ describe('Maps Client JS', () => {
13931392
id: 'id',
13941393
type: 'Feature',
13951394
geometry: {
1396-
type: GeometryType.Polygon,
1395+
type: 'Polygon',
13971396
coordinates: [
13981397
[
13991398
[-0.1356213, 51.5121161],
@@ -1416,7 +1415,7 @@ describe('Maps Client JS', () => {
14161415
id: 'id',
14171416
type: 'Feature',
14181417
geometry: {
1419-
type: GeometryType.Point,
1418+
type: 'Point',
14201419
coordinates: [-0.1356213, 51.5121161]
14211420
},
14221421
properties: {
@@ -1432,7 +1431,7 @@ describe('Maps Client JS', () => {
14321431
id: 'id',
14331432
type: 'Feature',
14341433
geometry: {
1435-
type: GeometryType.LineString,
1434+
type: 'LineString',
14361435
coordinates: [
14371436
[-0.1356213, 51.5121161],
14381437
[-0.0578579, 51.5182996]
@@ -1451,7 +1450,7 @@ describe('Maps Client JS', () => {
14511450
id: 'id',
14521451
type: 'Feature',
14531452
geometry: {
1454-
type: GeometryType.Polygon,
1453+
type: 'Polygon',
14551454
coordinates: [
14561455
[
14571456
[-0.1356213, 51.5121161],

0 commit comments

Comments
 (0)