Skip to content

Commit d2fa466

Browse files
committed
Update to latest code
- updates the JS for the map to the latest code, including a few adjustments - corresponds to v5 of the map - removes cluster feature plugin in favour of a manual solution - update bindpopup function significantly
1 parent 5b7ba5c commit d2fa466

File tree

6 files changed

+35
-49
lines changed

6 files changed

+35
-49
lines changed

app/assets/config/manifest.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//= link views/travel-advice.js
77
//= link views/landing_page/map/main.js
88
//= link views/landing_page/map/os-api-branding.js
9+
//= link views/landing_page/map/data/lookup.js
910
//= link views/landing_page/map/data/cdc.geojson.js
1011
//= link views/landing_page/map/data/hub.geojson.js
1112
//= link views/landing_page/map/data/icb.geojson.js

app/assets/javascripts/views/landing_page/map/main.js

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* global L */
22
//= require leaflet
3-
//= require leaflet.markercluster
3+
//= require views/landing_page/map/data/lookup.js
44
//= require views/landing_page/map/data/cdc.geojson.js
55
//= require views/landing_page/map/data/hub.geojson.js
66
//= require views/landing_page/map/data/icb.geojson.js
@@ -26,7 +26,6 @@ window.addEventListener('DOMContentLoaded', function () {
2626
const mapOptions = {
2727
minZoom: 7,
2828
maxZoom: 16,
29-
center: [52.562, -1.465],
3029
zoom: 7,
3130
maxBounds: [
3231
[49.5, -10.5],
@@ -63,14 +62,15 @@ window.addEventListener('DOMContentLoaded', function () {
6362
const basemap = L.tileLayer(`https://api.os.uk/maps/raster/v1/zxy/Light_3857/{z}/{x}/{y}.png?key=${apiKey}`)
6463
basemap.addTo(map)
6564

65+
const iconSize = [24, 24]
6666
const icons = {
6767
cdc: {
68-
default: L.icon({ iconUrl: mapElement.getAttribute('data-icon-cdc-default'), iconSize: [24, 24] }),
69-
active: L.icon({ iconUrl: mapElement.getAttribute('data-icon-cdc-active'), iconSize: [24, 24] })
68+
default: L.icon({ iconUrl: mapElement.getAttribute('data-icon-cdc-default'), iconSize: iconSize, iconAnchor: [24, 12], popupAnchor: [-12, 0] }),
69+
active: L.icon({ iconUrl: mapElement.getAttribute('data-icon-cdc-active'), iconSize: iconSize, iconAnchor: [24, 12], popupAnchor: [-12, 0] })
7070
},
7171
hub: {
72-
default: L.icon({ iconUrl: mapElement.getAttribute('data-icon-sh-default'), iconSize: [24, 24] }),
73-
active: L.icon({ iconUrl: mapElement.getAttribute('data-icon-sh-default'), iconSize: [24, 24] })
72+
default: L.icon({ iconUrl: mapElement.getAttribute('data-icon-sh-default'), iconSize: iconSize, iconAnchor: [0, 12], popupAnchor: [12, 0] }),
73+
active: L.icon({ iconUrl: mapElement.getAttribute('data-icon-sh-default'), iconSize: iconSize, iconAnchor: [0, 12], popupAnchor: [12, 0] })
7474
}
7575
}
7676

@@ -88,8 +88,7 @@ window.addEventListener('DOMContentLoaded', function () {
8888
pane: 'cdc'
8989
})
9090
}
91-
})
92-
91+
}).addTo(map)
9392
const cdcOverlay = customOverlays.cdc
9493

9594
// Add the Surgical Hub locations.
@@ -104,8 +103,7 @@ window.addEventListener('DOMContentLoaded', function () {
104103
pane: 'hub'
105104
})
106105
}
107-
})
108-
106+
}).addTo(map)
109107
const hubOverlay = customOverlays.hub
110108

111109
// Generate CDC and Surgical Hub counts per ICS boundary.
@@ -142,14 +140,8 @@ window.addEventListener('DOMContentLoaded', function () {
142140
})
143141
icsOverlay.addTo(map)
144142

145-
// Add marker cluster group to the map.
146-
const MarkerClusterGroup = new L.MarkerClusterGroup({
147-
showCoverageOnHover: false,
148-
maxClusterRadius: 0
149-
}).addTo(map)
150-
151-
MarkerClusterGroup.addLayer(customOverlays.cdc)
152-
MarkerClusterGroup.addLayer(customOverlays.hub)
143+
// Fit the map bounds to the extent of the Integrated Care System (ICS) boundaries
144+
map.fitBounds(icsOverlay.getBounds())
153145

154146
const layers = [cdcOverlay, hubOverlay]
155147
for (let i = 0; i < layers.length; i++) {
@@ -158,7 +150,7 @@ window.addEventListener('DOMContentLoaded', function () {
158150

159151
checkbox.addEventListener('click', function () {
160152
map.closePopup()
161-
checkbox.checked ? MarkerClusterGroup.addLayer(mapLayer) : MarkerClusterGroup.removeLayer(mapLayer)
153+
checkbox.checked ? map.addLayer(mapLayer) : map.removeLayer(mapLayer)
162154

163155
// track the filter click
164156
mapElement.setAttribute('data-ga4-auto', JSON.stringify({
@@ -183,20 +175,27 @@ window.addEventListener('DOMContentLoaded', function () {
183175
let propLookup
184176

185177
const popupContainer = document.createElement('div')
186-
const popupHeading = document.createElement('h1')
178+
179+
const popupHeading = document.createElement('h3')
187180
popupHeading.classList.add('govuk-heading-m')
188181
const popupBody = document.createElement('div')
189182

190183
if (ftGeomType === 'Point') {
191184
popupHeading.innerText = ftProps.name
192185

193-
propLookup = {
194-
services: 'Services offered',
195-
isOpen12_7: 'Open 12 hours a day, 7 days a week?',
196-
address: 'Address'
186+
if (lyrPane === 'cdc') {
187+
propLookup = {
188+
services: 'Services offered',
189+
isOpen12_7: 'Open 12 hours a day, 7 days a week?',
190+
address: 'Address'
191+
}
192+
} else if (lyrPane === 'hub') {
193+
propLookup = {
194+
address: 'Address'
195+
}
197196
}
198197
} else {
199-
popupHeading.innerText = ftProps.ICB23NM
198+
popupHeading.innerText = window.GOVUK.lookup.ics[ftProps.ICB23CD]
200199

201200
propLookup = {
202201
cdcCount: 'Community Diagnostic Centres',
@@ -206,21 +205,23 @@ window.addEventListener('DOMContentLoaded', function () {
206205

207206
for (const [key, value] of Object.entries(propLookup)) {
208207
if (Object.prototype.hasOwnProperty.call(ftProps, key)) {
209-
const popupBodyHeading = document.createElement('h2')
208+
const popupBodyHeading = document.createElement('h4')
210209
popupBodyHeading.classList.add('govuk-heading-s')
210+
popupBodyHeading.classList.add('govuk-!-margin-0')
211211
popupBodyHeading.innerText = value
212212
popupBody.appendChild(popupBodyHeading)
213213

214-
const popupBodyDiv = document.createElement('div')
215-
popupBodyDiv.innerText = key === 'address' ? `${ftProps.address}, ${ftProps.postcode}` : ftProps[key]
216-
popupBody.appendChild(popupBodyDiv)
214+
const popupBodyContent = document.createElement('p')
215+
popupBodyContent.classList.add('govuk-body')
216+
popupBodyContent.innerText = ftProps[key]
217+
popupBody.appendChild(popupBodyContent)
217218
}
218219
}
219220

220221
popupContainer.appendChild(popupHeading)
221222
popupContainer.appendChild(popupBody)
222-
const popup = layer.bindPopup(popupContainer)
223223

224+
const popup = layer.bindPopup(popupContainer)
224225
popup.on('popupopen', (e) => {
225226
if (ftGeomType === 'Point') e.target.setIcon(icons[lyrPane].active)
226227
else e.target.setStyle({ fillOpacity: 0.3 })
@@ -236,7 +237,6 @@ window.addEventListener('DOMContentLoaded', function () {
236237
tracker.sendEvent()
237238
mapElement.removeAttribute('data-ga4-auto')
238239
})
239-
240240
popup.on('popupclose', (e) => {
241241
if (ftGeomType === 'Point') e.target.setIcon(icons[lyrPane].default)
242242
else e.target.setStyle({ fillOpacity: 0.0 })

app/assets/stylesheets/views/_landing_page/map.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
}
1212

1313
.map__canvas {
14-
height: 500px;
14+
height: 800px;
1515
margin-bottom: govuk-spacing(1);
16+
border: solid 1px $govuk-border-colour;
1617
}
1718

1819
.map__key {

app/assets/stylesheets/views/_landing_page/map/leaflet.scss

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -563,11 +563,6 @@ svg.leaflet-image-layer.leaflet-interactive path {
563563
min-height: 1px;
564564
}
565565

566-
.leaflet-popup-content p {
567-
margin: 17px 0;
568-
margin: 1.3em 0;
569-
}
570-
571566
.leaflet-popup-tip-container {
572567
width: 40px;
573568
height: 20px;

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
},
5454
"packageManager": "[email protected]",
5555
"dependencies": {
56-
"leaflet": "^1.9.4",
57-
"leaflet.markercluster": "^1.5.3"
56+
"leaflet": "^1.9.4"
5857
}
5958
}

yarn.lock

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1853,7 +1853,6 @@ __metadata:
18531853
jasmine-browser-runner: ^3.0.0
18541854
jasmine-core: ^5.7.1
18551855
leaflet: ^1.9.4
1856-
leaflet.markercluster: ^1.5.3
18571856
nyc: ^17.1.0
18581857
standardx: ^7.0.0
18591858
stylelint: ^16.19.1
@@ -2892,15 +2891,6 @@ __metadata:
28922891
languageName: node
28932892
linkType: hard
28942893

2895-
"leaflet.markercluster@npm:^1.5.3":
2896-
version: 1.5.3
2897-
resolution: "leaflet.markercluster@npm:1.5.3"
2898-
peerDependencies:
2899-
leaflet: ^1.3.1
2900-
checksum: abf0d0befbc78b7f178a330791554f0e4fd7170dbe2e6d59f387b627d914f4633b0541a9028fe5d11cf842c09c8dbb56ae6bd9d1d08c5ce35e32541c8f1eacd1
2901-
languageName: node
2902-
linkType: hard
2903-
29042894
"leaflet@npm:^1.9.4":
29052895
version: 1.9.4
29062896
resolution: "leaflet@npm:1.9.4"

0 commit comments

Comments
 (0)