@defra/interactive-map 0.0.58-alpha → 0.0.59-alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/dist/esm/im-core.js +1 -1
  2. package/dist/umd/im-core.js +1 -1
  3. package/docs/plugins/draw.md +95 -13
  4. package/package.json +1 -1
  5. package/plugins/draw/dist/esm/im-draw-ml-adapter.js +1 -1
  6. package/plugins/draw/dist/esm/im-draw-ol-adapter.js +1 -1
  7. package/plugins/draw/dist/esm/im-draw-plugin.js +1 -1
  8. package/plugins/draw/dist/esm/index.js +1 -1
  9. package/plugins/draw/dist/esm/liveDrawChecks.js +1 -1
  10. package/plugins/draw/dist/umd/im-draw-ml-adapter.js +1 -1
  11. package/plugins/draw/dist/umd/im-draw-ol-adapter.js +1 -1
  12. package/plugins/draw/dist/umd/im-draw-plugin.js +1 -1
  13. package/plugins/draw/dist/umd/index.js +1 -1
  14. package/plugins/draw/src/adapterEvents.js +2 -0
  15. package/plugins/draw/src/adapters/adapterContract.test.js +1 -0
  16. package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.js +15 -3
  17. package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.test.js +27 -0
  18. package/plugins/draw/src/adapters/maplibre/modes/editPointMode/pointerHandlers.js +8 -19
  19. package/plugins/draw/src/adapters/maplibre/modes/editPointMode/pointerHandlers.test.js +20 -0
  20. package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/pointerHandlers.js +6 -17
  21. package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/pointerHandlers.test.js +19 -0
  22. package/plugins/draw/src/adapters/maplibre/utils/editModeEvents.js +29 -1
  23. package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.js +13 -3
  24. package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.test.js +28 -0
  25. package/plugins/draw/src/api/addFeature.js +9 -6
  26. package/plugins/draw/src/api/addFeature.test.js +37 -10
  27. package/plugins/draw/src/api/editFeature.js +1 -1
  28. package/plugins/draw/src/api/recheckGeometry.js +1 -1
  29. package/plugins/draw/src/api/recheckGeometry.test.js +2 -2
  30. package/plugins/draw/src/api/setProperties.js +39 -0
  31. package/plugins/draw/src/api/setProperties.test.js +74 -0
  32. package/plugins/draw/src/api/setStyle.js +16 -19
  33. package/plugins/draw/src/api/setStyle.test.js +17 -2
  34. package/plugins/draw/src/api/split.js +7 -4
  35. package/plugins/draw/src/api/split.test.js +25 -2
  36. package/plugins/draw/src/events.js +95 -53
  37. package/plugins/draw/src/events.test.js +425 -6
  38. package/plugins/draw/src/manifest.js +6 -4
  39. package/plugins/draw/src/manifest.test.js +20 -26
  40. package/plugins/draw/src/reducer.js +7 -0
  41. package/plugins/draw/src/reducer.test.js +11 -0
  42. package/plugins/draw/src/utils/flattenStyleProperties.js +54 -2
  43. package/plugins/draw/src/utils/flattenStyleProperties.test.js +74 -1
  44. package/plugins/draw/src/utils/isPlainObject.js +14 -0
  45. package/plugins/draw/src/utils/isPlainObject.test.js +24 -0
  46. package/plugins/draw/src/utils/mergeFeatureProperties.js +45 -0
  47. package/plugins/draw/src/utils/mergeFeatureProperties.test.js +48 -0
  48. package/plugins/draw/src/utils/stripInternalProperties.js +3 -2
  49. package/plugins/draw/src/validation/commitChecks.js +29 -11
  50. package/plugins/draw/src/validation/commitChecks.test.js +67 -11
  51. package/plugins/draw/src/validation/validateGeometry.js +12 -5
  52. package/plugins/draw/src/validation/validateGeometry.test.js +18 -0
  53. package/src/App/store/MapProvider.jsx +1 -0
  54. package/src/App/store/MapProvider.test.jsx +25 -0
  55. package/src/App/store/mapActionsMap.js +6 -0
  56. package/src/App/store/mapActionsMap.test.js +7 -0
  57. package/src/App/store/mapReducer.js +2 -0
  58. package/src/App/store/mapReducer.test.js +2 -0
@@ -13,12 +13,14 @@ jest.mock('./mapReducer.js', () => {
13
13
 
14
14
  const setMapReady = jest.fn((state) => ({ ...state, isMapReady: true }))
15
15
  const setMapStyle = jest.fn((state, payload) => ({ ...state, mapStyle: payload }))
16
+ const setMapStyles = jest.fn((state, payload) => ({ ...state, mapStyles: payload }))
16
17
  const setMapSize = jest.fn((state, payload) => ({ ...state, mapSize: payload }))
17
18
  const updateCrossHair = jest.fn((state, payload) => ({ ...state, crossHair: payload }))
18
19
 
19
20
  const actionsMap = {
20
21
  SET_MAP_READY: setMapReady,
21
22
  SET_MAP_STYLE: setMapStyle,
23
+ SET_MAP_STYLES: setMapStyles,
22
24
  SET_MAP_SIZE: setMapSize,
23
25
  UPDATE_CROSS_HAIR: updateCrossHair
24
26
  }
@@ -103,6 +105,29 @@ describe('MapProvider', () => {
103
105
  })
104
106
  })
105
107
 
108
+ test('keeps every announced map style, and selects the saved one', () => {
109
+ let contextValue
110
+ const Child = () => {
111
+ contextValue = React.useContext(MapContext)
112
+ return null
113
+ }
114
+ localStorage.setItem('map1:mapStyleId', 'dark')
115
+
116
+ render(
117
+ <MapProvider options={{ id: 'map1', mapSize: '100x100', eventBus: mockEventBus }}>
118
+ <Child />
119
+ </MapProvider>
120
+ )
121
+
122
+ const mapStyles = [{ id: 'outdoor' }, { id: 'dark' }]
123
+ act(() => {
124
+ capturedHandlers['map:initmapstyles'](mapStyles)
125
+ })
126
+
127
+ expect(contextValue.mapStyles).toBe(mapStyles)
128
+ expect(contextValue.mapStyle).toEqual({ id: 'dark' })
129
+ })
130
+
106
131
  test('dispatches SET_MAP_READY when MAP_READY fires', () => {
107
132
  let contextValue
108
133
  const Child = () => {
@@ -17,6 +17,11 @@ const setMapStyle = (state, payload) => ({
17
17
  mapStyle: payload
18
18
  })
19
19
 
20
+ const setMapStyles = (state, payload) => ({
21
+ ...state,
22
+ mapStyles: payload
23
+ })
24
+
20
25
  const setMapSize = (state, payload) => {
21
26
  return {
22
27
  ...state,
@@ -67,6 +72,7 @@ export const actionsMap = {
67
72
  MAP_MOVE_END: mergePayload,
68
73
  MAP_FIRST_IDLE: mergePayload,
69
74
  SET_MAP_STYLE: setMapStyle,
75
+ SET_MAP_STYLES: setMapStyles,
70
76
  SET_MAP_SIZE: setMapSize,
71
77
  UPDATE_CROSS_HAIR: updateCrossHair,
72
78
  UPSERT_LOCATION_MARKER: upsertMarker,
@@ -52,6 +52,13 @@ describe('actionsMap', () => {
52
52
  expect(result.otherProp).toBe(state.otherProp)
53
53
  })
54
54
 
55
+ test('SET_MAP_STYLES sets mapStyles', () => {
56
+ const mapStyles = [{ id: 'outdoor' }, { id: 'dark' }]
57
+ const result = actionsMap.SET_MAP_STYLES(state, mapStyles)
58
+ expect(result.mapStyles).toBe(mapStyles)
59
+ expect(result.otherProp).toBe(state.otherProp)
60
+ })
61
+
55
62
  test('SET_MAP_SIZE sets mapSize', () => {
56
63
  const newSize = { width: 200, height: 200 }
57
64
  const result = actionsMap.SET_MAP_SIZE(state, newSize)
@@ -22,6 +22,8 @@ export const initialState = (config) => {
22
22
  isMapReady: false,
23
23
  mapProvider: null,
24
24
  mapStyle: initialMapStyle,
25
+ // Every map style the user can switch to — set by a plugin that handles map styles
26
+ mapStyles: initialMapStyle ? [initialMapStyle] : [],
25
27
  mapSize,
26
28
  center,
27
29
  zoom,
@@ -39,6 +39,7 @@ describe('mapReducer', () => {
39
39
  expect(state).toMatchObject({
40
40
  isMapReady: false,
41
41
  mapStyle: { id: 'style1' },
42
+ mapStyles: [{ id: 'style1' }],
42
43
  mapSize: '100x100',
43
44
  center: [0, 0],
44
45
  zoom: 5,
@@ -63,6 +64,7 @@ describe('mapReducer', () => {
63
64
  const state = initialState(getConfig({ mapStyle: { id: 'custom' }, center: [10, 20], zoom: 12 }))
64
65
 
65
66
  expect(state.mapStyle).toBeNull()
67
+ expect(state.mapStyles).toEqual([])
66
68
  expect(state.center).toEqual([10, 20])
67
69
  expect(state.zoom).toBe(12)
68
70
  })