@defra/interactive-map 0.0.31-alpha → 0.0.33-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 (131) 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/css/index.css +1 -1
  17. package/dist/esm/im-core.js +1 -1
  18. package/dist/esm/im-shell.js +1 -1
  19. package/dist/umd/im-core.js +1 -1
  20. package/dist/umd/index.js +1 -1
  21. package/docs/api/map-style-config.md +27 -3
  22. package/docs/api.md +55 -0
  23. package/docs/assets/css/docusaurus.scss +22 -6
  24. package/docs/assets/images/add-polygons.jpg +0 -0
  25. package/docs/assets/images/add-symbols.jpg +0 -0
  26. package/docs/assets/images/hero.png +0 -0
  27. package/docs/assets/images/place-marker.jpg +0 -0
  28. package/docs/assets/images/screenshot.jpg +0 -0
  29. package/docs/examples/add-marker-with-panel.mdx +1 -1
  30. package/docs/examples/add-polygons.mdx +225 -0
  31. package/docs/examples/add-symbols.mdx +177 -0
  32. package/docs/examples/{draw.mdx → draw-tools.mdx} +2 -2
  33. package/docs/examples/index.mdx +38 -2
  34. package/docs/examples/place-marker.mdx +151 -0
  35. package/docs/plugins/datasets.md +144 -96
  36. package/docs/plugins/interact.md +1 -4
  37. package/docusaurus.config.cjs +5 -2
  38. package/govuk-prototype-kit.config.json +52 -2
  39. package/package.json +1 -1
  40. package/plugins/beta/datasets/dist/css/index.css +1 -2
  41. package/plugins/beta/datasets/dist/esm/im-datasets-ml-adapter.js +1 -1
  42. package/plugins/beta/datasets/dist/esm/im-datasets-plugin.js +1 -1
  43. package/plugins/beta/datasets/dist/umd/im-datasets-ml-adapter.js +1 -1
  44. package/plugins/beta/datasets/dist/umd/im-datasets-plugin.js +1 -1
  45. package/plugins/beta/datasets/dist/umd/index.js +1 -1
  46. package/plugins/beta/datasets/src/adapters/maplibre/registry/mapLibreDataset.js +27 -9
  47. package/plugins/beta/datasets/src/adapters/maplibre/registry/mapLibreDataset.test.js +46 -4
  48. package/plugins/beta/datasets/src/api/setFeatureVisibility.js +10 -1
  49. package/plugins/beta/datasets/src/api/setFeatureVisibility.test.js +48 -6
  50. package/plugins/beta/datasets/src/components/LayersMenu/Layers.module.scss +12 -12
  51. package/plugins/beta/datasets/src/reducers/datasetsToMenu.js +11 -6
  52. package/plugins/beta/datasets/src/reducers/datasetsToMenu.test.js +49 -0
  53. package/plugins/beta/datasets/src/reducers/mappedDatasetsReducer.js +8 -1
  54. package/plugins/beta/datasets/src/reducers/pluginState.js +1 -1
  55. package/plugins/beta/datasets/src/registry/dataset.js +7 -3
  56. package/plugins/beta/datasets/src/registry/dataset.test.js +14 -0
  57. package/plugins/beta/datasets/src/registry/dynamicGeoJson.js +1 -1
  58. package/plugins/beta/draw-es/dist/esm/im-draw-es-plugin.js +1 -1
  59. package/plugins/beta/draw-es/src/api/addFeature.js +12 -3
  60. package/plugins/beta/draw-es/src/events.js +8 -3
  61. package/plugins/beta/draw-es/src/events.test.js +2 -0
  62. package/plugins/beta/draw-es/src/graphic.js +26 -2
  63. package/plugins/beta/draw-ml/dist/esm/im-draw-ml-plugin.js +1 -1
  64. package/plugins/beta/draw-ml/dist/umd/im-draw-ml-plugin.js +1 -1
  65. package/plugins/beta/draw-ml/src/DrawInit.jsx +19 -0
  66. package/plugins/beta/draw-ml/src/api/newLine.js +1 -0
  67. package/plugins/beta/draw-ml/src/api/newPolygon.js +1 -0
  68. package/plugins/beta/draw-ml/src/modes/createDrawMode.js +52 -37
  69. package/plugins/beta/draw-ml/src/modes/editVertex/touchHandlers.js +1 -1
  70. package/plugins/beta/draw-ml/src/modes/editVertex/vertexOperations.js +5 -4
  71. package/plugins/beta/draw-ml/src/modes/editVertexMode.js +53 -21
  72. package/plugins/beta/draw-ol/dist/esm/DrawMode.js +1 -1
  73. package/plugins/beta/draw-ol/dist/esm/EditMode.js +1 -1
  74. package/plugins/beta/draw-ol/dist/esm/im-draw-ol-plugin.js +1 -1
  75. package/plugins/beta/draw-ol/src/core/OLDrawManager.js +3 -0
  76. package/plugins/beta/draw-ol/src/draw/DrawMode.js +57 -49
  77. package/plugins/beta/draw-ol/src/draw/drawInput.js +76 -32
  78. package/plugins/beta/draw-ol/src/edit/EditMode.js +4 -4
  79. package/plugins/beta/draw-ol/src/edit/keyboardHandler.js +4 -2
  80. package/plugins/beta/draw-ol/src/manifest.js +5 -1
  81. package/plugins/beta/draw-ol/src/reducer.js +1 -1
  82. package/plugins/beta/draw-ol/src/snap/snapEngine.js +75 -31
  83. package/plugins/beta/draw-ol/src/snap/snapGeometry.js +23 -46
  84. package/plugins/beta/draw-ol/src/snap/snapInteraction.js +30 -29
  85. package/plugins/beta/draw-ol/src/snap/snapManager.js +10 -1
  86. package/plugins/beta/draw-ol/src/utils/geometryHelpers.js +9 -3
  87. package/plugins/beta/draw-ol/src/utils/olCoords.js +2 -2
  88. package/plugins/beta/draw-ol/src/utils/spatial.js +4 -8
  89. package/plugins/beta/map-styles/src/mapStyles.scss +41 -41
  90. package/plugins/interact/dist/esm/im-interact-plugin.js +1 -1
  91. package/plugins/interact/dist/umd/im-interact-plugin.js +1 -1
  92. package/plugins/interact/dist/umd/index.js +1 -1
  93. package/plugins/interact/src/InteractInit.jsx +1 -3
  94. package/plugins/interact/src/InteractInit.test.js +0 -2
  95. package/plugins/interact/src/events.test.js +1 -1
  96. package/plugins/interact/src/hooks/useCrossHairVisibility.js +4 -10
  97. package/plugins/interact/src/hooks/useCrossHairVisibility.test.js +5 -10
  98. package/plugins/interact/src/hooks/useHighlightSync.js +1 -10
  99. package/plugins/interact/src/hooks/useHighlightSync.test.js +2 -21
  100. package/plugins/interact/src/hooks/useInteractionHandlers.js +5 -11
  101. package/plugins/interact/src/hooks/useInteractionHandlers.test.js +5 -25
  102. package/plugins/interact/src/reducer.js +4 -22
  103. package/plugins/interact/src/reducer.test.js +11 -39
  104. package/plugins/search/dist/css/index.css +5 -2
  105. package/plugins/search/src/components/Form/Form.module.scss +5 -2
  106. package/plugins/search/src/search.scss +4 -4
  107. package/providers/beta/openlayers/dist/esm/im-openlayers-provider.js +1 -1
  108. package/providers/beta/openlayers/dist/umd/im-openlayers-provider.js +1 -1
  109. package/providers/beta/openlayers/dist/umd/index.js +1 -1
  110. package/providers/beta/openlayers/src/utils/tileLayers.js +29 -2
  111. package/providers/beta/openlayers/src/utils/tileLayers.test.js +53 -1
  112. package/src/App/components/CrossHair/CrossHair.module.scss +8 -8
  113. package/src/App/components/MapButton/MapButton.jsx +14 -10
  114. package/src/App/components/MapButton/MapButton.module.scss +1 -1
  115. package/src/App/components/MapButton/MapButton.test.jsx +1 -1
  116. package/src/App/components/PopupMenu/PopupMenu.test.jsx +79 -0
  117. package/src/App/components/PopupMenu/usePopupMenu.js +61 -12
  118. package/src/App/hooks/useLayoutMeasurements.js +10 -2
  119. package/src/App/hooks/useResizeObserver.js +4 -2
  120. package/src/InteractiveMap/InteractiveMap.js +4 -4
  121. package/src/InteractiveMap/InteractiveMap.test.js +3 -3
  122. package/src/InteractiveMap/behaviourController.js +3 -1
  123. package/src/InteractiveMap/behaviourController.test.js +6 -3
  124. package/src/InteractiveMap/domStateManager.js +2 -0
  125. package/src/config/events.js +21 -3
  126. package/src/types.js +12 -3
  127. package/src/utils/findNextTabStop.js +3 -3
  128. package/src/utils/findNextTabStop.test.js +25 -1
  129. package/webpack.dev.mjs +1 -0
  130. package/docs/assets/images/screens-blue.jpg +0 -0
  131. package/docs/assets/images/screens-white.jpg +0 -0
@@ -0,0 +1,104 @@
1
+ {% extends "layouts/main.html" %}
2
+
3
+ {% block pageTitle %}
4
+ Place a marker to continue – 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
+ Place a marker to continue
29
+ </h1>
30
+
31
+ <div id="map"></div>
32
+
33
+ <div id="external-buttons" hidden>
34
+ <button class="govuk-button govuk-!-margin-top-4" id="continue-btn" disabled>Continue</button>
35
+ </div>
36
+
37
+ </div>
38
+ </div>
39
+ {% endblock %}
40
+
41
+ {% block pageScripts %}
42
+ <!-- Defra library scripts -->
43
+ <script src="/plugin-assets/%40defra%2Finteractive-map/dist/umd/index.js"></script>
44
+ <script src="/plugin-assets/%40defra%2Finteractive-map/providers/maplibre/dist/umd/index.js"></script>
45
+ <script src="/plugin-assets/%40defra%2Finteractive-map/plugins/interact/dist/umd/index.js"></script>
46
+
47
+ <script>
48
+ var interactPlugin = defra.interactPlugin({
49
+ interactionModes: ['placeMarker']
50
+ })
51
+
52
+ var map = new defra.InteractiveMap('map', {
53
+ behaviour: 'hybrid',
54
+ mapProvider: defra.maplibreProvider(),
55
+ mapStyle: {
56
+ url: 'https://tiles.openfreemap.org/styles/liberty',
57
+ attribution: 'OpenFreeMap © OpenMapTiles Data from OpenStreetMap',
58
+ backgroundColor: '#f5f5f0'
59
+ },
60
+ center: [-0.1276, 51.5074],
61
+ zoom: 12,
62
+ containerHeight: '516px',
63
+ plugins: [interactPlugin],
64
+ backAndContinue: {
65
+ backLabel: 'Back',
66
+ continueLabel: 'Continue',
67
+ continueEnabledWhen: function (context) {
68
+ return context.mapState.markers.items.some(function (m) { return m.id === 'location' })
69
+ }
70
+ }
71
+ })
72
+
73
+ map.on('map:ready', function () {
74
+ interactPlugin.enable()
75
+ })
76
+
77
+ map.on('app:continue', function (context) {
78
+ var marker = context.mapState.markers.items.find(function (m) { return m.id === 'location' })
79
+ // navigate to next step with marker.coords
80
+ if (marker) {
81
+ console.log('Continuing with marker at:', marker.coords)
82
+ }
83
+ })
84
+
85
+ var continueBtn = document.getElementById('continue-btn')
86
+ var externalButtons = document.getElementById('external-buttons')
87
+
88
+ function setInline(isFullscreen) {
89
+ externalButtons.hidden = isFullscreen
90
+ }
91
+
92
+ map.on('app:opened', function (e) { setInline(e.isFullscreen) })
93
+ map.on('app:closed', function () { externalButtons.hidden = true })
94
+ map.on('app:fullscreenchange', function (e) { setInline(e.isFullscreen) })
95
+
96
+ map.on('interact:markerchange', function () {
97
+ continueBtn.disabled = false
98
+ })
99
+
100
+ continueBtn.addEventListener('click', function () {
101
+ // navigate to next step
102
+ })
103
+ </script>
104
+ {% endblock %}
@@ -0,0 +1,98 @@
1
+ {% extends "layouts/main.html" %}
2
+
3
+ {% block pageTitle %}
4
+ Add a search control – 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/search/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 a search control
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/search/dist/umd/index.js"></script>
43
+
44
+ <script>
45
+ const SETTLEMENT_TYPES = new Set(['city', 'town', 'village', 'hamlet', 'suburb', 'quarter', 'neighbourhood', 'municipality', 'borough', 'district', 'county'])
46
+
47
+ const nominatimDataset = {
48
+ name: 'nominatim',
49
+ buildRequest: function (query) {
50
+ const params = new URLSearchParams({
51
+ q: query,
52
+ format: 'json',
53
+ limit: '8',
54
+ countrycodes: 'gb'
55
+ })
56
+ return new Request('https://nominatim.openstreetmap.org/search?' + params, {
57
+ headers: { 'Accept-Language': 'en' }
58
+ })
59
+ },
60
+ parseResults: function (json, query) {
61
+ if (!Array.isArray(json)) return []
62
+ const escaped = query.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
63
+ const results = json
64
+ .filter(function (item) { return SETTLEMENT_TYPES.has(item.addresstype) })
65
+ .map(function (item) {
66
+ const bb = item.boundingbox.map(Number)
67
+ return {
68
+ id: String(item.place_id),
69
+ text: item.display_name,
70
+ marked: item.display_name.replace(new RegExp('(' + escaped + ')', 'i'), '<mark>$1</mark>'),
71
+ point: [Number(item.lon), Number(item.lat)],
72
+ bounds: [bb[2], bb[0], bb[3], bb[1]]
73
+ }
74
+ })
75
+ return Array.from(new Map(results.map(function (r) { return [r.text, r] })).values())
76
+ }
77
+ }
78
+
79
+ const searchPlugin = defra.searchPlugin({
80
+ customDatasets: [nominatimDataset],
81
+ width: '300px'
82
+ })
83
+
84
+ new defra.InteractiveMap('map', {
85
+ behaviour: 'inline',
86
+ mapProvider: defra.maplibreProvider(),
87
+ mapStyle: {
88
+ url: 'https://tiles.openfreemap.org/styles/liberty',
89
+ attribution: 'OpenFreeMap © OpenMapTiles Data from OpenStreetMap',
90
+ backgroundColor: '#f5f5f0'
91
+ },
92
+ center: [-1.6, 53.1],
93
+ zoom: 6,
94
+ containerHeight: '516px',
95
+ plugins: [searchPlugin]
96
+ })
97
+ </script>
98
+ {% endblock %}
@@ -0,0 +1,101 @@
1
+ {% extends "layouts/main.html" %}
2
+
3
+ {% block pageTitle %}
4
+ Select a feature – 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
+ Select a feature
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
+ <script src="/plugin-assets/%40defra%2Finteractive-map/plugins/interact/dist/umd/index.js"></script>
42
+
43
+ <script>
44
+ const PANEL_ID = 'building-info'
45
+
46
+ const interactPlugin = defra.interactPlugin({
47
+ interactionModes: ['selectFeature'],
48
+ deselectOnClickOutside: true,
49
+ layers: [
50
+ { layerId: 'buildings 3D', idProperty: 'uuid' }
51
+ ]
52
+ })
53
+
54
+ const map = new defra.InteractiveMap('map', {
55
+ behaviour: 'inline',
56
+ mapProvider: defra.maplibreProvider(),
57
+ mapStyle: {
58
+ url: 'https://labs.os.uk/tiles/styles/open-zoomstack-outdoor/style.json',
59
+ attribution: `Contains OS data © Crown copyright and database rights ${new Date().getFullYear()}`,
60
+ backgroundColor: '#f5f5f0'
61
+ },
62
+ center: [-1.5491, 53.8008],
63
+ zoom: 14.5,
64
+ maxZoom: 14.5,
65
+ containerHeight: '516px',
66
+ plugins: [interactPlugin]
67
+ })
68
+
69
+ map.on('map:ready', () => {
70
+ interactPlugin.enable()
71
+
72
+ map.addPanel(PANEL_ID, {
73
+ focus: false,
74
+ label: 'Selected building',
75
+ html: '<div id="building-info-content"></div>',
76
+ mobile: { slot: 'drawer', dismissible: true, open: false },
77
+ tablet: { slot: 'left-top', dismissible: true, width: '300px', open: false },
78
+ desktop: { slot: 'left-top', dismissible: true, width: '300px', open: false }
79
+ })
80
+ })
81
+
82
+ map.on('interact:selectionchange', ({ selectedFeatures }) => {
83
+ if (selectedFeatures.length > 0) {
84
+ let html = ''
85
+ for (const [k, v] of Object.entries(selectedFeatures[0].properties)) {
86
+ html += '<p class="govuk-body govuk-!-margin-bottom-1"><strong>' + k + ':</strong> ' + v + '</p>'
87
+ }
88
+ document.getElementById('building-info-content').innerHTML = html
89
+ map.showPanel(PANEL_ID)
90
+ } else {
91
+ map.hidePanel(PANEL_ID)
92
+ }
93
+ })
94
+
95
+ map.on('app:panelclosed', ({ panelId }) => {
96
+ if (panelId === PANEL_ID) {
97
+ interactPlugin.clear()
98
+ }
99
+ })
100
+ </script>
101
+ {% endblock %}
@@ -0,0 +1,87 @@
1
+ {% extends "layouts/main.html" %}
2
+
3
+ {% block pageTitle %}
4
+ Change map style – 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/map-styles/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
+ Change map style
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/map-styles/dist/umd/index.js"></script>
43
+
44
+ <script>
45
+ const attribution = 'OpenFreeMap © OpenMapTiles Data from OpenStreetMap'
46
+
47
+ const mapStyles = [
48
+ {
49
+ id: 'road',
50
+ label: 'Road',
51
+ url: 'https://tiles.openfreemap.org/styles/liberty',
52
+ thumbnail: '/plugin-assets/%40defra%2Finteractive-map/assets/images/road-ofm-thumb.jpg',
53
+ attribution,
54
+ backgroundColor: '#f5f5f0'
55
+ },
56
+ {
57
+ id: 'bright',
58
+ label: 'Bright',
59
+ url: 'https://tiles.openfreemap.org/styles/bright',
60
+ thumbnail: '/plugin-assets/%40defra%2Finteractive-map/assets/images/bright-ofm-thumb.jpg',
61
+ attribution,
62
+ backgroundColor: '#f5f5f0'
63
+ },
64
+ {
65
+ id: 'dark',
66
+ label: 'Dark',
67
+ url: 'https://tiles.openfreemap.org/styles/fiord',
68
+ thumbnail: '/plugin-assets/%40defra%2Finteractive-map/assets/images/dark-ofm-thumb.jpg',
69
+ attribution,
70
+ mapColorScheme: 'dark',
71
+ appColorScheme: 'dark'
72
+ }
73
+ ]
74
+
75
+ const mapStylesPlugin = defra.mapStylesPlugin({ mapStyles })
76
+
77
+ new defra.InteractiveMap('map', {
78
+ behaviour: 'inline',
79
+ mapProvider: defra.maplibreProvider(),
80
+ mapStyle: mapStyles[0],
81
+ center: [-0.1276, 51.5074],
82
+ zoom: 12,
83
+ containerHeight: '516px',
84
+ plugins: [mapStylesPlugin]
85
+ })
86
+ </script>
87
+ {% endblock %}
@@ -0,0 +1,74 @@
1
+ {% extends "layouts/main.html" %}
2
+
3
+ {% block pageTitle %}
4
+ Toggle marker label – 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
+ Toggle marker label
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
+ <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.96, 54.43],
57
+ zoom: 15,
58
+ containerHeight: '516px',
59
+ plugins: [interactPlugin]
60
+ })
61
+
62
+ map.on('map:ready', () => {
63
+ map.addMarker('my-marker', [-2.96, 54.43], {
64
+ label: 'My location',
65
+ showLabel: false
66
+ })
67
+ interactPlugin.enable()
68
+ })
69
+
70
+ map.on('interact:selectionchange', ({ selectedMarkers }) => {
71
+ map.updateMarker('my-marker', { showLabel: selectedMarkers.includes('my-marker') })
72
+ })
73
+ </script>
74
+ {% endblock %}