@defra/interactive-map 0.0.31-alpha → 0.0.32-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 (98) hide show
  1. package/README.md +2 -2
  2. package/assets/images/bright-ofm-thumb.jpg +0 -0
  3. package/assets/images/dark-ofm-thumb.jpg +0 -0
  4. package/assets/images/road-ofm-thumb.jpg +0 -0
  5. package/assets/templates/add-polygons.njk +143 -0
  6. package/assets/templates/add-symbols.njk +119 -0
  7. package/assets/templates/{map.njk → basic-map.njk} +9 -17
  8. package/assets/templates/button-map.njk +56 -0
  9. package/assets/templates/draw-tools.njk +161 -0
  10. package/assets/templates/marker-panel.njk +91 -0
  11. package/assets/templates/place-marker.njk +104 -0
  12. package/assets/templates/search-control.njk +98 -0
  13. package/assets/templates/select-feature.njk +101 -0
  14. package/assets/templates/style-switcher.njk +87 -0
  15. package/assets/templates/toggle-marker-label.njk +74 -0
  16. package/dist/esm/im-core.js +1 -1
  17. package/dist/esm/im-shell.js +1 -1
  18. package/dist/umd/im-core.js +1 -1
  19. package/dist/umd/index.js +1 -1
  20. package/docs/api.md +55 -0
  21. package/docs/assets/css/docusaurus.scss +22 -6
  22. package/docs/assets/images/add-polygons.jpg +0 -0
  23. package/docs/assets/images/add-symbols.jpg +0 -0
  24. package/docs/assets/images/place-marker.jpg +0 -0
  25. package/docs/assets/images/screenshot.jpg +0 -0
  26. package/docs/examples/add-marker-with-panel.mdx +1 -1
  27. package/docs/examples/add-polygons.mdx +225 -0
  28. package/docs/examples/add-symbols.mdx +177 -0
  29. package/docs/examples/{draw.mdx → draw-tools.mdx} +2 -2
  30. package/docs/examples/index.mdx +38 -2
  31. package/docs/examples/place-marker.mdx +151 -0
  32. package/docs/plugins/datasets.md +144 -96
  33. package/docs/plugins/interact.md +1 -4
  34. package/docusaurus.config.cjs +5 -2
  35. package/govuk-prototype-kit.config.json +52 -2
  36. package/package.json +1 -1
  37. package/plugins/beta/datasets/dist/css/index.css +1 -2
  38. package/plugins/beta/datasets/dist/esm/im-datasets-ml-adapter.js +1 -1
  39. package/plugins/beta/datasets/dist/esm/im-datasets-plugin.js +1 -1
  40. package/plugins/beta/datasets/dist/umd/im-datasets-ml-adapter.js +1 -1
  41. package/plugins/beta/datasets/dist/umd/im-datasets-plugin.js +1 -1
  42. package/plugins/beta/datasets/dist/umd/index.js +1 -1
  43. package/plugins/beta/datasets/src/adapters/maplibre/registry/mapLibreDataset.js +27 -9
  44. package/plugins/beta/datasets/src/adapters/maplibre/registry/mapLibreDataset.test.js +46 -4
  45. package/plugins/beta/datasets/src/api/setFeatureVisibility.js +10 -1
  46. package/plugins/beta/datasets/src/api/setFeatureVisibility.test.js +48 -6
  47. package/plugins/beta/datasets/src/components/LayersMenu/Layers.module.scss +12 -12
  48. package/plugins/beta/datasets/src/reducers/datasetsToMenu.js +11 -6
  49. package/plugins/beta/datasets/src/reducers/datasetsToMenu.test.js +49 -0
  50. package/plugins/beta/datasets/src/reducers/mappedDatasetsReducer.js +8 -1
  51. package/plugins/beta/datasets/src/reducers/pluginState.js +1 -1
  52. package/plugins/beta/datasets/src/registry/dataset.js +7 -3
  53. package/plugins/beta/datasets/src/registry/dataset.test.js +14 -0
  54. package/plugins/beta/datasets/src/registry/dynamicGeoJson.js +1 -1
  55. package/plugins/beta/draw-es/dist/esm/im-draw-es-plugin.js +1 -1
  56. package/plugins/beta/draw-es/src/api/addFeature.js +12 -3
  57. package/plugins/beta/draw-es/src/events.js +8 -3
  58. package/plugins/beta/draw-es/src/events.test.js +2 -0
  59. package/plugins/beta/draw-es/src/graphic.js +26 -2
  60. package/plugins/beta/draw-ml/dist/esm/im-draw-ml-plugin.js +1 -1
  61. package/plugins/beta/draw-ml/dist/umd/im-draw-ml-plugin.js +1 -1
  62. package/plugins/beta/draw-ml/src/DrawInit.jsx +8 -0
  63. package/plugins/beta/draw-ml/src/api/newLine.js +1 -0
  64. package/plugins/beta/draw-ml/src/api/newPolygon.js +1 -0
  65. package/plugins/beta/draw-ml/src/modes/createDrawMode.js +21 -12
  66. package/plugins/beta/draw-ml/src/modes/editVertexMode.js +4 -0
  67. package/plugins/beta/draw-ol/dist/esm/EditMode.js +1 -1
  68. package/plugins/beta/draw-ol/dist/esm/im-draw-ol-plugin.js +1 -1
  69. package/plugins/beta/draw-ol/src/edit/keyboardHandler.js +4 -2
  70. package/plugins/beta/map-styles/src/mapStyles.scss +41 -41
  71. package/plugins/interact/dist/esm/im-interact-plugin.js +1 -1
  72. package/plugins/interact/dist/umd/im-interact-plugin.js +1 -1
  73. package/plugins/interact/dist/umd/index.js +1 -1
  74. package/plugins/interact/src/InteractInit.jsx +1 -3
  75. package/plugins/interact/src/InteractInit.test.js +0 -2
  76. package/plugins/interact/src/events.test.js +1 -1
  77. package/plugins/interact/src/hooks/useCrossHairVisibility.js +4 -10
  78. package/plugins/interact/src/hooks/useCrossHairVisibility.test.js +5 -10
  79. package/plugins/interact/src/hooks/useHighlightSync.js +1 -10
  80. package/plugins/interact/src/hooks/useHighlightSync.test.js +2 -21
  81. package/plugins/interact/src/hooks/useInteractionHandlers.js +5 -11
  82. package/plugins/interact/src/hooks/useInteractionHandlers.test.js +5 -25
  83. package/plugins/interact/src/reducer.js +4 -22
  84. package/plugins/interact/src/reducer.test.js +11 -39
  85. package/plugins/search/dist/css/index.css +5 -2
  86. package/plugins/search/src/components/Form/Form.module.scss +5 -2
  87. package/plugins/search/src/search.scss +4 -4
  88. package/src/App/components/CrossHair/CrossHair.module.scss +8 -8
  89. package/src/App/hooks/useLayoutMeasurements.js +10 -2
  90. package/src/App/hooks/useResizeObserver.js +4 -2
  91. package/src/InteractiveMap/InteractiveMap.js +4 -4
  92. package/src/InteractiveMap/InteractiveMap.test.js +3 -3
  93. package/src/InteractiveMap/behaviourController.js +3 -1
  94. package/src/InteractiveMap/behaviourController.test.js +6 -3
  95. package/src/InteractiveMap/domStateManager.js +2 -0
  96. package/src/config/events.js +21 -3
  97. package/docs/assets/images/screens-blue.jpg +0 -0
  98. package/docs/assets/images/screens-white.jpg +0 -0
package/README.md CHANGED
@@ -14,10 +14,10 @@ See [examples of InteractiveMap](https://google.co.uk).
14
14
 
15
15
  See [getting started](./docs/getting-started.md) developer guide.
16
16
 
17
- **⚠️ This project is currently in beta and is not yet stable. Documentation and support are not yet available.**
17
+ **⚠️ This project is currently in beta and is not yet stable.**
18
18
 
19
19
  <p align="center">
20
- <img src="docs/assets/images/screens-white.jpg" alt="Screenshots of map component">
20
+ <img src="docs/assets/images/screenshot.jpg" alt="Screenshot of map component">
21
21
  </p>
22
22
 
23
23
  ## Documentation
Binary file
Binary file
@@ -0,0 +1,143 @@
1
+ {% extends "layouts/main.html" %}
2
+
3
+ {% block pageTitle %}
4
+ Add polygons – GOV.UK Prototype Kit
5
+ {% endblock %}
6
+
7
+ {% block head %}
8
+ <link href="/public/stylesheets/application.css" rel="stylesheet" type="text/css">
9
+ <link href="/plugin-assets/%40defra%2Finteractive-map/dist/css/index.css" rel="stylesheet" type="text/css">
10
+ <link href="/plugin-assets/%40defra%2Finteractive-map/plugins/beta/datasets/dist/css/index.css" rel="stylesheet" type="text/css">
11
+ {% endblock %}
12
+
13
+ {% block bodyStart %}
14
+ <script>document.body.classList.add('im-is-loading')</script>
15
+ {% endblock %}
16
+
17
+ {% block beforeContent %}
18
+ {{ govukBackLink({
19
+ text: "Back",
20
+ href: "javascript:window.history.back()"
21
+ }) }}
22
+ {% endblock %}
23
+
24
+ {% block content %}
25
+ <div class="govuk-grid-row">
26
+ <div class="govuk-grid-column-two-thirds">
27
+
28
+ <h1 class="govuk-heading-l">
29
+ Add polygons
30
+ </h1>
31
+
32
+ <div id="map"></div>
33
+
34
+ </div>
35
+ </div>
36
+ {% endblock %}
37
+
38
+ {% block pageScripts %}
39
+ <!-- Defra library scripts -->
40
+ <script src="/plugin-assets/%40defra%2Finteractive-map/dist/umd/index.js"></script>
41
+ <script src="/plugin-assets/%40defra%2Finteractive-map/providers/maplibre/dist/umd/index.js"></script>
42
+ <script src="/plugin-assets/%40defra%2Finteractive-map/plugins/beta/datasets/dist/umd/index.js"></script>
43
+
44
+ <script>
45
+ // GeoJSON can also be loaded from a URL; use the tiles property for vector tile sources
46
+ const geojson = {
47
+ type: 'FeatureCollection',
48
+ features: [{
49
+ type: 'Feature',
50
+ id: 1,
51
+ properties: { name: 'Feature 1', land_use: 'Permanent grassland' },
52
+ geometry: { type: 'Polygon', coordinates: [[[-2.4691585,54.5552164],[-2.4692202,54.5553906],[-2.4690646,54.5554155],[-2.4690002,54.5555088],[-2.4690297,54.5556690],[-2.4690995,54.5557919],[-2.4669269,54.5566971],[-2.4662375,54.5562819],[-2.4637780,54.5574391],[-2.4628580,54.5568169],[-2.4607612,54.5560985],[-2.4608248,54.5560719],[-2.4611789,54.5558914],[-2.4613774,54.5558168],[-2.4615973,54.5557577],[-2.4617475,54.5557297],[-2.4618816,54.5556519],[-2.4620104,54.5556115],[-2.4624771,54.5555275],[-2.4627131,54.5555150],[-2.4628741,54.5554839],[-2.4630082,54.5554404],[-2.4632335,54.5553346],[-2.4633944,54.5552164],[-2.4634749,54.5551106],[-2.4635178,54.5550235],[-2.4635285,54.5548213],[-2.4635768,54.5546346],[-2.4635875,54.5544884],[-2.4636090,54.5544075],[-2.4636465,54.5543515],[-2.4636573,54.5542769],[-2.4636358,54.5541804],[-2.4637377,54.5540155],[-2.4639094,54.5538724],[-2.4643493,54.5535831],[-2.4645370,54.5535084],[-2.4647141,54.5534804],[-2.4648052,54.5534836],[-2.4648213,54.5535116],[-2.4648750,54.5535396],[-2.4650842,54.5535893],[-2.4652451,54.5536516],[-2.4652719,54.5536796],[-2.4653900,54.5537355],[-2.4655455,54.5537853],[-2.4658459,54.5539502],[-2.4663556,54.5542738],[-2.4668008,54.5545164],[-2.4668330,54.5545506],[-2.4668437,54.5546782],[-2.4668598,54.5547031],[-2.4670798,54.5548306],[-2.4671817,54.5549053],[-2.4674177,54.5549364],[-2.4677664,54.5550484],[-2.4681956,54.5551448],[-2.4684101,54.5551759],[-2.4691129,54.5552195],[-2.4691585,54.5552164]]] }
53
+ }, {
54
+ type: 'Feature',
55
+ id: 2,
56
+ properties: { name: 'Feature 2', land_use: 'Arable' },
57
+ geometry: { type: 'Polygon', coordinates: [[[-2.4611682,54.5562375],[-2.4628580,54.5568161],[-2.4636841,54.5573753],[-2.4637793,54.5574398],[-2.4641401,54.5576751],[-2.4642567,54.5577999],[-2.4641307,54.5578823],[-2.4636841,54.5582502],[-2.4624221,54.5592884],[-2.4623376,54.5592534],[-2.4615370,54.5586429],[-2.4611869,54.5582852],[-2.4605258,54.5581071],[-2.4598472,54.5578186],[-2.4611682,54.5562375]]] }
58
+ }, {
59
+ type: 'Feature',
60
+ id: 3,
61
+ properties: { name: 'Feature 3', land_use: 'Arable' },
62
+ geometry: { type: 'Polygon', coordinates: [[[-2.4598472,54.5578186],[-2.4605258,54.5581067],[-2.4611869,54.5582852],[-2.4615376,54.5586433],[-2.4623108,54.5592332],[-2.4623376,54.5592534],[-2.4624221,54.5592884],[-2.4623108,54.5594120],[-2.4616731,54.5601189],[-2.4586053,54.5601189],[-2.4584410,54.5600299],[-2.4580038,54.5596574],[-2.4581815,54.5593953],[-2.4585778,54.5590702],[-2.4587287,54.5589353],[-2.4589198,54.5586736],[-2.4591116,54.5582136],[-2.4598472,54.5578186]]] }
63
+ }, {
64
+ type: 'Feature',
65
+ id: 4,
66
+ properties: { name: 'Feature 4', land_use: 'Permanent grassland' },
67
+ geometry: { type: 'Polygon', coordinates: [[[-2.4633756,54.5612877],[-2.4613908,54.5604315],[-2.4624221,54.5592884],[-2.4641307,54.5578823],[-2.4642567,54.5577999],[-2.4653631,54.5591733],[-2.4659613,54.5597013],[-2.4633756,54.5612877]]] }
68
+ }, {
69
+ type: 'Feature',
70
+ id: 5,
71
+ properties: { name: 'Feature 5', land_use: 'Arable' },
72
+ geometry: { type: 'Polygon', coordinates: [[[-2.4678040,54.5590679],[-2.4661879,54.5595952],[-2.4659613,54.5597013],[-2.4653638,54.5591737],[-2.4642567,54.5577999],[-2.4641401,54.5576751],[-2.4637793,54.5574398],[-2.4662369,54.5562822],[-2.4669282,54.5566975],[-2.4678040,54.5563320],[-2.4678040,54.5590679]]] }
73
+ }, {
74
+ type: 'Feature',
75
+ id: 6,
76
+ properties: { name: 'Feature 6', land_use: 'Permanent grassland' },
77
+ geometry: { type: 'Polygon', coordinates: [[[-2.4669316,54.5603767],[-2.4676430,54.5613102],[-2.4673292,54.5614556],[-2.4671616,54.5617468],[-2.4658446,54.5625528],[-2.4651546,54.5621528],[-2.4639215,54.5633040],[-2.4633146,54.5633040],[-2.4628372,54.5630921],[-2.4631195,54.5628195],[-2.4643741,54.5618374],[-2.4665071,54.5604793],[-2.4667056,54.5604187],[-2.4669316,54.5603767]]] }
78
+ }, {
79
+ type: 'Feature',
80
+ id: 7,
81
+ properties: { name: 'Feature 7', land_use: 'Woodland' },
82
+ geometry: { type: 'Polygon', coordinates: [[[-2.4599129,54.5564203],[-2.4599773,54.5565478],[-2.4599773,54.5565852],[-2.4599344,54.5566256],[-2.4596876,54.5566069],[-2.4594945,54.5566132],[-2.4593657,54.5566505],[-2.4592584,54.5567158],[-2.4592048,54.5567780],[-2.4591780,54.5568496],[-2.4591887,54.5569616],[-2.4591297,54.5570829],[-2.4590009,54.5572726],[-2.4589419,54.5573162],[-2.4588561,54.5574686],[-2.4587435,54.5575588],[-2.4586684,54.5575837],[-2.4585879,54.5575962],[-2.4584001,54.5575837],[-2.4583304,54.5575899],[-2.4580836,54.5576397],[-2.4579817,54.5576895],[-2.4579227,54.5576988],[-2.4578154,54.5576988],[-2.4576384,54.5576739],[-2.4574614,54.5576739],[-2.4573044,54.5577050],[-2.4563093,54.5573092],[-2.4563871,54.5569849],[-2.4564891,54.5560664],[-2.4565601,54.5559039],[-2.4567747,54.5559412],[-2.4571985,54.5559817],[-2.4573219,54.5560097],[-2.4576116,54.5560936],[-2.4582446,54.5562181],[-2.4584913,54.5562959],[-2.4590331,54.5563705],[-2.4599129,54.5564203]]] }
83
+ }]
84
+ }
85
+
86
+ const datasetsPlugin = defra.datasetsPlugin({
87
+ datasets: [{
88
+ id: 'field-geojson',
89
+ label: 'Field geojson',
90
+ geojson: geojson,
91
+ minZoom: 10,
92
+ maxZoom: 24,
93
+ showInKey: true,
94
+ showInMenu: true,
95
+ sublayers: [{
96
+ id: 'arable',
97
+ label: 'Arable',
98
+ filter: ['==', ['get', 'land_use'], 'Arable'],
99
+ style: {
100
+ stroke: '#6D4C41',
101
+ fillPattern: 'horizontal-hatch',
102
+ fillPatternForegroundColor: '#6D4C41',
103
+ fillPatternBackgroundColor: 'transparent'
104
+ }
105
+ }, {
106
+ id: 'permanent-grassland',
107
+ label: 'Permanent grassland',
108
+ filter: ['==', ['get', 'land_use'], 'Permanent grassland'],
109
+ style: {
110
+ stroke: '#00897B',
111
+ fillPattern: 'diagonal-cross-hatch',
112
+ fillPatternForegroundColor: '#00897B',
113
+ fillPatternBackgroundColor: 'transparent'
114
+ }
115
+ }, {
116
+ id: 'woodland',
117
+ label: 'Woodland',
118
+ filter: ['==', ['get', 'land_use'], 'Woodland'],
119
+ style: {
120
+ stroke: '#2E7D32',
121
+ fillPattern: 'dot',
122
+ fillPatternForegroundColor: '#2E7D32',
123
+ fillPatternBackgroundColor: 'transparent'
124
+ }
125
+ }]
126
+ }]
127
+ })
128
+
129
+ new defra.InteractiveMap('map', {
130
+ behaviour: 'inline',
131
+ mapProvider: defra.maplibreProvider(),
132
+ mapStyle: {
133
+ url: 'https://labs.os.uk/tiles/styles/open-zoomstack-outdoor/style.json',
134
+ attribution: `Contains OS data © Crown copyright and database rights ${new Date().getFullYear()}`,
135
+ backgroundColor: '#f5f5f0'
136
+ },
137
+ center: [-2.464, 54.558],
138
+ zoom: 14,
139
+ containerHeight: '516px',
140
+ plugins: [datasetsPlugin]
141
+ })
142
+ </script>
143
+ {% endblock %}
@@ -0,0 +1,119 @@
1
+ {% extends "layouts/main.html" %}
2
+
3
+ {% block pageTitle %}
4
+ Add symbols – GOV.UK Prototype Kit
5
+ {% endblock %}
6
+
7
+ {% block head %}
8
+ <link href="/public/stylesheets/application.css" rel="stylesheet" type="text/css">
9
+ <link href="/plugin-assets/%40defra%2Finteractive-map/dist/css/index.css" rel="stylesheet" type="text/css">
10
+ <link href="/plugin-assets/%40defra%2Finteractive-map/plugins/beta/datasets/dist/css/index.css" rel="stylesheet" type="text/css">
11
+ {% endblock %}
12
+
13
+ {% block bodyStart %}
14
+ <script>document.body.classList.add('im-is-loading')</script>
15
+ {% endblock %}
16
+
17
+ {% block beforeContent %}
18
+ {{ govukBackLink({
19
+ text: "Back",
20
+ href: "javascript:window.history.back()"
21
+ }) }}
22
+ {% endblock %}
23
+
24
+ {% block content %}
25
+ <div class="govuk-grid-row">
26
+ <div class="govuk-grid-column-two-thirds">
27
+
28
+ <h1 class="govuk-heading-l">
29
+ Add symbols
30
+ </h1>
31
+
32
+ <div id="map"></div>
33
+
34
+ </div>
35
+ </div>
36
+ {% endblock %}
37
+
38
+ {% block pageScripts %}
39
+ <!-- Defra library scripts -->
40
+ <script src="/plugin-assets/%40defra%2Finteractive-map/dist/umd/index.js"></script>
41
+ <script src="/plugin-assets/%40defra%2Finteractive-map/providers/maplibre/dist/umd/index.js"></script>
42
+ <script src="/plugin-assets/%40defra%2Finteractive-map/plugins/beta/datasets/dist/umd/index.js"></script>
43
+
44
+ <script>
45
+ const symbolGraphic = 'M3 15H1V1h2v2h2V1h2v5h2V4h2v2h2V4h2v11H6V9H3v6z'
46
+
47
+ // GeoJSON can also be loaded from a URL; use the tiles property for vector tile sources
48
+ const geojson = {
49
+ type: 'FeatureCollection',
50
+ features: [{
51
+ type: 'Feature',
52
+ properties: { category: 'prehistoric', name: 'Prehistoric feature' },
53
+ geometry: { type: 'Point', coordinates: [-2.4615, 54.5616] }
54
+ }, {
55
+ type: 'Feature',
56
+ properties: { category: 'roman', name: 'Roman feature' },
57
+ geometry: { type: 'Point', coordinates: [-2.4628, 54.5541] }
58
+ }, {
59
+ type: 'Feature',
60
+ properties: { category: 'medieval', name: 'Medieval feature' },
61
+ geometry: { type: 'Point', coordinates: [-2.4578, 54.5569] }
62
+ }]
63
+ }
64
+
65
+ const datasetsPlugin = defra.datasetsPlugin({
66
+ datasets: [{
67
+ id: 'historic-monuments',
68
+ label: 'Historic monuments',
69
+ geojson: geojson,
70
+ minZoom: 10,
71
+ maxZoom: 24,
72
+ showInKey: true,
73
+ showInMenu: true,
74
+ sublayers: [{
75
+ id: 'prehistoric',
76
+ label: 'Prehistoric',
77
+ filter: ['in', ['get', 'category'], 'prehistoric'],
78
+ style: {
79
+ symbol: 'square',
80
+ symbolGraphic,
81
+ symbolBackgroundColor: '#00897B'
82
+ }
83
+ }, {
84
+ id: 'roman',
85
+ label: 'Roman',
86
+ filter: ['in', ['get', 'category'], 'roman'],
87
+ style: {
88
+ symbol: 'square',
89
+ symbolGraphic,
90
+ symbolBackgroundColor: '#ca3535'
91
+ }
92
+ }, {
93
+ id: 'medieval',
94
+ label: 'Medieval',
95
+ filter: ['in', ['get', 'category'], 'medieval'],
96
+ style: {
97
+ symbol: 'square',
98
+ symbolGraphic,
99
+ symbolBackgroundColor: '#1565C0'
100
+ }
101
+ }]
102
+ }]
103
+ })
104
+
105
+ new defra.InteractiveMap('map', {
106
+ behaviour: 'inline',
107
+ mapProvider: defra.maplibreProvider(),
108
+ mapStyle: {
109
+ url: 'https://labs.os.uk/tiles/styles/open-zoomstack-outdoor/style.json',
110
+ attribution: `Contains OS data © Crown copyright and database rights ${new Date().getFullYear()}`,
111
+ backgroundColor: '#f5f5f0'
112
+ },
113
+ center: [-2.4608, 54.5574],
114
+ zoom: 14,
115
+ containerHeight: '516px',
116
+ plugins: [datasetsPlugin]
117
+ })
118
+ </script>
119
+ {% endblock %}
@@ -1,13 +1,12 @@
1
1
  {% extends "layouts/main.html" %}
2
2
 
3
3
  {% block pageTitle %}
4
- InteractiveMap page template – GOV.UK Prototype Kit
4
+ Basic map – GOV.UK Prototype Kit
5
5
  {% endblock %}
6
6
 
7
7
  {% block head %}
8
8
  <link href="/public/stylesheets/application.css" rel="stylesheet" type="text/css">
9
9
  <link href="/plugin-assets/%40defra%2Finteractive-map/dist/css/index.css" rel="stylesheet" type="text/css">
10
- <link href="/plugin-assets/%40defra%2Finteractive-map/plugins/beta/scale-bar/dist/css/index.css" rel="stylesheet" type="text/css">
11
10
  {% endblock %}
12
11
 
13
12
  {% block bodyStart %}
@@ -29,7 +28,7 @@
29
28
  Basic map
30
29
  </h1>
31
30
 
32
- <div id="map" data-zoom="12" data-center="[-2.968, 54.425]"></div>
31
+ <div id="map"></div>
33
32
 
34
33
  </div>
35
34
  </div>
@@ -39,26 +38,19 @@
39
38
  <!-- Defra library scripts -->
40
39
  <script src="/plugin-assets/%40defra%2Finteractive-map/dist/umd/index.js"></script>
41
40
  <script src="/plugin-assets/%40defra%2Finteractive-map/providers/maplibre/dist/umd/index.js"></script>
42
- <script src="/plugin-assets/%40defra%2Finteractive-map/plugins/beta/scale-bar/dist/umd/index.js"></script>
43
-
41
+
44
42
  <script>
45
- const interactiveMap = new defra.InteractiveMap('map', {
43
+ new defra.InteractiveMap('map', {
44
+ behaviour: 'inline',
46
45
  mapProvider: defra.maplibreProvider(),
47
- behaviour: 'hybrid',
48
- mapLabel: 'Ambleside',
49
- minZoom: 6,
50
- maxZoom: 18,
51
- containerHeight: '650px',
52
46
  mapStyle: {
53
47
  url: 'https://tiles.openfreemap.org/styles/liberty',
54
48
  attribution: 'OpenFreeMap © OpenMapTiles Data from OpenStreetMap',
55
49
  backgroundColor: '#f5f5f0'
56
50
  },
57
- plugins: [
58
- defra.scaleBarPlugin({
59
- units: 'metric'
60
- })
61
- ]
51
+ center: [-1.6, 53.1],
52
+ zoom: 6,
53
+ containerHeight: '516px'
62
54
  })
63
55
  </script>
64
- {% endblock %}
56
+ {% endblock %}
@@ -0,0 +1,56 @@
1
+ {% extends "layouts/main.html" %}
2
+
3
+ {% block pageTitle %}
4
+ Button-triggered map – GOV.UK Prototype Kit
5
+ {% endblock %}
6
+
7
+ {% block head %}
8
+ <link href="/public/stylesheets/application.css" rel="stylesheet" type="text/css">
9
+ <link href="/plugin-assets/%40defra%2Finteractive-map/dist/css/index.css" rel="stylesheet" type="text/css">
10
+ {% endblock %}
11
+
12
+ {% block bodyStart %}
13
+ <script>document.body.classList.add('im-is-loading')</script>
14
+ {% endblock %}
15
+
16
+ {% block beforeContent %}
17
+ {{ govukBackLink({
18
+ text: "Back",
19
+ href: "javascript:window.history.back()"
20
+ }) }}
21
+ {% endblock %}
22
+
23
+ {% block content %}
24
+ <div class="govuk-grid-row">
25
+ <div class="govuk-grid-column-two-thirds">
26
+
27
+ <h1 class="govuk-heading-l">
28
+ Button-triggered map
29
+ </h1>
30
+
31
+ <div id="map"></div>
32
+
33
+ </div>
34
+ </div>
35
+ {% endblock %}
36
+
37
+ {% block pageScripts %}
38
+ <!-- Defra library scripts -->
39
+ <script src="/plugin-assets/%40defra%2Finteractive-map/dist/umd/index.js"></script>
40
+ <script src="/plugin-assets/%40defra%2Finteractive-map/providers/maplibre/dist/umd/index.js"></script>
41
+
42
+ <script>
43
+ new defra.InteractiveMap('map', {
44
+ behaviour: 'buttonFirst',
45
+ mapProvider: defra.maplibreProvider(),
46
+ mapStyle: {
47
+ url: 'https://tiles.openfreemap.org/styles/liberty',
48
+ attribution: 'OpenFreeMap © OpenMapTiles Data from OpenStreetMap',
49
+ backgroundColor: '#f5f5f0'
50
+ },
51
+ center: [-1.6, 53.1],
52
+ zoom: 6,
53
+ hasExitButton: true
54
+ })
55
+ </script>
56
+ {% endblock %}
@@ -0,0 +1,161 @@
1
+ {% extends "layouts/main.html" %}
2
+
3
+ {% block pageTitle %}
4
+ Draw tools – GOV.UK Prototype Kit
5
+ {% endblock %}
6
+
7
+ {% block head %}
8
+ <link href="/public/stylesheets/application.css" rel="stylesheet" type="text/css">
9
+ <link href="/plugin-assets/%40defra%2Finteractive-map/dist/css/index.css" rel="stylesheet" type="text/css">
10
+ {% endblock %}
11
+
12
+ {% block bodyStart %}
13
+ <script>document.body.classList.add('im-is-loading')</script>
14
+ {% endblock %}
15
+
16
+
17
+ {% block content %}
18
+ <div class="govuk-grid-row">
19
+ <div class="govuk-grid-column-two-thirds">
20
+
21
+ <h1 class="govuk-heading-l">
22
+ Draw tools
23
+ </h1>
24
+
25
+ <div id="map"></div>
26
+
27
+ </div>
28
+ </div>
29
+ {% endblock %}
30
+
31
+ {% block pageScripts %}
32
+ <!-- Defra library scripts -->
33
+ <script src="/plugin-assets/%40defra%2Finteractive-map/dist/umd/index.js"></script>
34
+ <script src="/plugin-assets/%40defra%2Finteractive-map/providers/maplibre/dist/umd/index.js"></script>
35
+ <script src="/plugin-assets/%40defra%2Finteractive-map/plugins/interact/dist/umd/index.js"></script>
36
+ <script src="/plugin-assets/%40defra%2Finteractive-map/plugins/beta/draw-ml/dist/umd/index.js"></script>
37
+
38
+ <script>
39
+ const DRAW_LAYERS = ['fill-inactive.cold', 'stroke-inactive.cold']
40
+
41
+ const interactPlugin = defra.interactPlugin({
42
+ layers: [
43
+ { layerId: 'fill-inactive.cold', idProperty: 'id' },
44
+ { layerId: 'stroke-inactive.cold', idProperty: 'id' }
45
+ ],
46
+ interactionModes: ['selectFeature'],
47
+ multiSelect: true,
48
+ deselectOnClickOutside: true
49
+ })
50
+
51
+ const drawPlugin = defra.drawMLPlugin({
52
+ snapLayers: ['building-3d']
53
+ })
54
+
55
+ const interactiveMap = new defra.InteractiveMap('map', {
56
+ behaviour: 'hybrid',
57
+ mapProvider: defra.maplibreProvider(),
58
+ mapStyle: {
59
+ id: 'default',
60
+ url: 'https://tiles.openfreemap.org/styles/liberty',
61
+ attribution: 'OpenFreeMap © OpenMapTiles Data from OpenStreetMap',
62
+ backgroundColor: '#f5f5f0'
63
+ },
64
+ center: [-0.1276, 51.5074],
65
+ zoom: 12,
66
+ containerHeight: '516px',
67
+ plugins: [interactPlugin, drawPlugin],
68
+ hasExitButton: true
69
+ })
70
+
71
+ let selectedFeatureIds = []
72
+
73
+ interactiveMap.on('map:ready', function () {
74
+ interactPlugin.enable()
75
+
76
+ interactiveMap.addButton('drawTools', {
77
+ label: 'Draw tools',
78
+ mobile: { slot: 'bottom-right' },
79
+ tablet: { slot: 'top-middle' },
80
+ desktop: { slot: 'top-middle' },
81
+ menuItems: [
82
+ {
83
+ id: 'drawPolygon',
84
+ label: 'Draw polygon',
85
+ iconSvgContent: '<path d="M19.5 7v10M4.5 7v10M7 19.5h10M7 4.5h10"/><path d="M22 18v3a1 1 0 0 1-1 1h-3a1 1 0 0 1-1-1v-3a1 1 0 0 1 1-1h3a1 1 0 0 1 1 1zm0-15v3a1 1 0 0 1-1 1h-3a1 1 0 0 1-1-1V3a1 1 0 0 1 1-1h3a1 1 0 0 1 1 1zM7 18v3a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-3a1 1 0 0 1 1-1h3a1 1 0 0 1 1 1zM7 3v3a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V3a1 1 0 0 1 1-1h3a1 1 0 0 1 1 1z"/>',
86
+ onClick: function () {
87
+ interactiveMap.toggleButtonState('drawTools', 'hidden', true)
88
+ drawPlugin.newPolygon(crypto.randomUUID())
89
+ }
90
+ },
91
+ {
92
+ id: 'drawLine',
93
+ label: 'Draw line',
94
+ iconSvgContent: '<path d="M5.706 16.294L16.294 5.706"/><path d="M21 2v3c0 .549-.451 1-1 1h-3c-.549 0-1-.451-1-1V2c0-.549.451-1 1-1h3c.549 0 1 .451 1 1zM6 17v3c0 .549-.451 1-1 1H2c-.549 0-1-.451-1-1v-3c0-.549.451-1 1-1h3c.549 0 1 .451 1 1z"/>',
95
+ onClick: function () {
96
+ interactiveMap.toggleButtonState('drawTools', 'hidden', true)
97
+ drawPlugin.newLine(crypto.randomUUID())
98
+ }
99
+ },
100
+ {
101
+ id: 'editFeature',
102
+ label: 'Edit feature',
103
+ iconSvgContent: '<path d="M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z"/><path d="m15 5 4 4"/>',
104
+ isDisabled: true,
105
+ onClick: function () {
106
+ if (!drawPlugin.editFeature(selectedFeatureIds[0])) return
107
+ interactiveMap.toggleButtonState('drawTools', 'hidden', true)
108
+ interactPlugin.disable()
109
+ }
110
+ },
111
+ {
112
+ id: 'deleteFeature',
113
+ label: 'Delete feature',
114
+ iconSvgContent: '<path d="M10 11v6"/><path d="M14 11v6"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6"/><path d="M3 6h18"/><path d="M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/>',
115
+ isDisabled: true,
116
+ onClick: function () {
117
+ drawPlugin.deleteFeature(selectedFeatureIds)
118
+ interactPlugin.clear()
119
+ interactiveMap.toggleButtonState('drawTools', 'hidden', false)
120
+ interactiveMap.toggleButtonState('drawPolygon', 'disabled', false)
121
+ interactiveMap.toggleButtonState('drawLine', 'disabled', false)
122
+ interactiveMap.toggleButtonState('editFeature', 'disabled', true)
123
+ interactiveMap.toggleButtonState('deleteFeature', 'disabled', true)
124
+ }
125
+ }
126
+ ]
127
+ })
128
+ })
129
+
130
+ interactiveMap.on('draw:started', function () {
131
+ interactPlugin.disable()
132
+ })
133
+
134
+ interactiveMap.on('draw:created', function () {
135
+ interactiveMap.toggleButtonState('drawTools', 'hidden', false)
136
+ interactPlugin.enable()
137
+ })
138
+
139
+ interactiveMap.on('draw:edited', function () {
140
+ interactiveMap.toggleButtonState('drawTools', 'hidden', false)
141
+ interactPlugin.enable()
142
+ })
143
+
144
+ interactiveMap.on('draw:cancelled', function () {
145
+ interactiveMap.toggleButtonState('drawTools', 'hidden', false)
146
+ interactPlugin.enable()
147
+ })
148
+
149
+ interactiveMap.on('interact:selectionchange', function (e) {
150
+ var singleFeature = e.selectedFeatures.length === 1
151
+ var anyFeature = e.selectedFeatures.length > 0
152
+ var isDrawFeature = singleFeature && DRAW_LAYERS.includes(e.selectedFeatures[0].layerId)
153
+ var allDrawFeatures = anyFeature && e.selectedFeatures.every(function (f) { return DRAW_LAYERS.includes(f.layerId) })
154
+ selectedFeatureIds = e.selectedFeatures.map(function (f) { return f.featureId })
155
+ interactiveMap.toggleButtonState('drawPolygon', 'disabled', singleFeature)
156
+ interactiveMap.toggleButtonState('drawLine', 'disabled', singleFeature)
157
+ interactiveMap.toggleButtonState('editFeature', 'disabled', !isDrawFeature)
158
+ interactiveMap.toggleButtonState('deleteFeature', 'disabled', !allDrawFeatures)
159
+ })
160
+ </script>
161
+ {% endblock %}
@@ -0,0 +1,91 @@
1
+ {% extends "layouts/main.html" %}
2
+
3
+ {% block pageTitle %}
4
+ Map with marker and panel – GOV.UK Prototype Kit
5
+ {% endblock %}
6
+
7
+ {% block head %}
8
+ <link href="/public/stylesheets/application.css" rel="stylesheet" type="text/css">
9
+ <link href="/plugin-assets/%40defra%2Finteractive-map/dist/css/index.css" rel="stylesheet" type="text/css">
10
+ {% endblock %}
11
+
12
+ {% block bodyStart %}
13
+ <script>document.body.classList.add('im-is-loading')</script>
14
+ {% endblock %}
15
+
16
+ {% block beforeContent %}
17
+ {{ govukBackLink({
18
+ text: "Back",
19
+ href: "javascript:window.history.back()"
20
+ }) }}
21
+ {% endblock %}
22
+
23
+ {% block content %}
24
+ <div class="govuk-grid-row">
25
+ <div class="govuk-grid-column-two-thirds">
26
+
27
+ <h1 class="govuk-heading-l">
28
+ Map with marker and panel
29
+ </h1>
30
+
31
+ <div id="map" data-zoom="15" data-center="[-2.968, 54.425]"></div>
32
+
33
+ </div>
34
+ </div>
35
+ {% endblock %}
36
+
37
+ {% block pageScripts %}
38
+ <!-- Defra library scripts -->
39
+ <script src="/plugin-assets/%40defra%2Finteractive-map/dist/umd/index.js"></script>
40
+ <script src="/plugin-assets/%40defra%2Finteractive-map/providers/maplibre/dist/umd/index.js"></script>
41
+ <script src="/plugin-assets/%40defra%2Finteractive-map/plugins/interact/dist/umd/index.js"></script>
42
+
43
+ <script>
44
+ const interactPlugin = defra.interactPlugin({
45
+ deselectOnClickOutside: true
46
+ })
47
+
48
+ const map = new defra.InteractiveMap('map', {
49
+ behaviour: 'inline',
50
+ mapProvider: defra.maplibreProvider(),
51
+ mapStyle: {
52
+ url: 'https://tiles.openfreemap.org/styles/liberty',
53
+ attribution: 'OpenFreeMap © OpenMapTiles Data from OpenStreetMap',
54
+ backgroundColor: '#f5f5f0'
55
+ },
56
+ center: [-2.968, 54.425],
57
+ zoom: 15,
58
+ containerHeight: '516px',
59
+ plugins: [interactPlugin]
60
+ })
61
+
62
+ map.on('map:ready', () => {
63
+ map.addMarker('my-marker', [-2.968, 54.425])
64
+ interactPlugin.enable()
65
+ interactPlugin.selectMarker('my-marker')
66
+
67
+ map.addPanel('marker-info', {
68
+ focus: false,
69
+ label: 'Marker',
70
+ html: '<p class="govuk-body">Information about the selected marker</p>',
71
+ mobile: { slot: 'drawer', dismissible: true },
72
+ tablet: { slot: 'left-top', dismissible: true, width: '280px' },
73
+ desktop: { slot: 'left-top', dismissible: true, width: '280px' }
74
+ })
75
+ })
76
+
77
+ map.on('interact:selectionchange', ({ selectedMarkers }) => {
78
+ if (selectedMarkers.length > 0) {
79
+ map.showPanel('marker-info')
80
+ } else {
81
+ map.hidePanel('marker-info')
82
+ }
83
+ })
84
+
85
+ map.on('app:panelclosed', ({ panelId }) => {
86
+ if (panelId === 'marker-info') {
87
+ interactPlugin.unselectMarker('my-marker')
88
+ }
89
+ })
90
+ </script>
91
+ {% endblock %}