1
1
/* global L */
2
2
//= require leaflet
3
- //= require leaflet.markercluster
3
+ //= require views/landing_page/map/data/lookup.js
4
4
//= require views/landing_page/map/data/cdc.geojson.js
5
5
//= require views/landing_page/map/data/hub.geojson.js
6
6
//= require views/landing_page/map/data/icb.geojson.js
@@ -26,7 +26,6 @@ window.addEventListener('DOMContentLoaded', function () {
26
26
const mapOptions = {
27
27
minZoom : 7 ,
28
28
maxZoom : 16 ,
29
- center : [ 52.562 , - 1.465 ] ,
30
29
zoom : 7 ,
31
30
maxBounds : [
32
31
[ 49.5 , - 10.5 ] ,
@@ -63,14 +62,15 @@ window.addEventListener('DOMContentLoaded', function () {
63
62
const basemap = L . tileLayer ( `https://api.os.uk/maps/raster/v1/zxy/Light_3857/{z}/{x}/{y}.png?key=${ apiKey } ` )
64
63
basemap . addTo ( map )
65
64
65
+ const iconSize = [ 24 , 24 ]
66
66
const icons = {
67
67
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 ] } )
70
70
} ,
71
71
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 ] } )
74
74
}
75
75
}
76
76
@@ -88,8 +88,7 @@ window.addEventListener('DOMContentLoaded', function () {
88
88
pane : 'cdc'
89
89
} )
90
90
}
91
- } )
92
-
91
+ } ) . addTo ( map )
93
92
const cdcOverlay = customOverlays . cdc
94
93
95
94
// Add the Surgical Hub locations.
@@ -104,8 +103,7 @@ window.addEventListener('DOMContentLoaded', function () {
104
103
pane : 'hub'
105
104
} )
106
105
}
107
- } )
108
-
106
+ } ) . addTo ( map )
109
107
const hubOverlay = customOverlays . hub
110
108
111
109
// Generate CDC and Surgical Hub counts per ICS boundary.
@@ -142,14 +140,8 @@ window.addEventListener('DOMContentLoaded', function () {
142
140
} )
143
141
icsOverlay . addTo ( map )
144
142
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 ( ) )
153
145
154
146
const layers = [ cdcOverlay , hubOverlay ]
155
147
for ( let i = 0 ; i < layers . length ; i ++ ) {
@@ -158,7 +150,7 @@ window.addEventListener('DOMContentLoaded', function () {
158
150
159
151
checkbox . addEventListener ( 'click' , function ( ) {
160
152
map . closePopup ( )
161
- checkbox . checked ? MarkerClusterGroup . addLayer ( mapLayer ) : MarkerClusterGroup . removeLayer ( mapLayer )
153
+ checkbox . checked ? map . addLayer ( mapLayer ) : map . removeLayer ( mapLayer )
162
154
163
155
// track the filter click
164
156
mapElement . setAttribute ( 'data-ga4-auto' , JSON . stringify ( {
@@ -183,20 +175,27 @@ window.addEventListener('DOMContentLoaded', function () {
183
175
let propLookup
184
176
185
177
const popupContainer = document . createElement ( 'div' )
186
- const popupHeading = document . createElement ( 'h1' )
178
+
179
+ const popupHeading = document . createElement ( 'h3' )
187
180
popupHeading . classList . add ( 'govuk-heading-m' )
188
181
const popupBody = document . createElement ( 'div' )
189
182
190
183
if ( ftGeomType === 'Point' ) {
191
184
popupHeading . innerText = ftProps . name
192
185
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
+ }
197
196
}
198
197
} else {
199
- popupHeading . innerText = ftProps . ICB23NM
198
+ popupHeading . innerText = window . GOVUK . lookup . ics [ ftProps . ICB23CD ]
200
199
201
200
propLookup = {
202
201
cdcCount : 'Community Diagnostic Centres' ,
@@ -206,21 +205,23 @@ window.addEventListener('DOMContentLoaded', function () {
206
205
207
206
for ( const [ key , value ] of Object . entries ( propLookup ) ) {
208
207
if ( Object . prototype . hasOwnProperty . call ( ftProps , key ) ) {
209
- const popupBodyHeading = document . createElement ( 'h2 ' )
208
+ const popupBodyHeading = document . createElement ( 'h4 ' )
210
209
popupBodyHeading . classList . add ( 'govuk-heading-s' )
210
+ popupBodyHeading . classList . add ( 'govuk-!-margin-0' )
211
211
popupBodyHeading . innerText = value
212
212
popupBody . appendChild ( popupBodyHeading )
213
213
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 )
217
218
}
218
219
}
219
220
220
221
popupContainer . appendChild ( popupHeading )
221
222
popupContainer . appendChild ( popupBody )
222
- const popup = layer . bindPopup ( popupContainer )
223
223
224
+ const popup = layer . bindPopup ( popupContainer )
224
225
popup . on ( 'popupopen' , ( e ) => {
225
226
if ( ftGeomType === 'Point' ) e . target . setIcon ( icons [ lyrPane ] . active )
226
227
else e . target . setStyle ( { fillOpacity : 0.3 } )
@@ -236,7 +237,6 @@ window.addEventListener('DOMContentLoaded', function () {
236
237
tracker . sendEvent ( )
237
238
mapElement . removeAttribute ( 'data-ga4-auto' )
238
239
} )
239
-
240
240
popup . on ( 'popupclose' , ( e ) => {
241
241
if ( ftGeomType === 'Point' ) e . target . setIcon ( icons [ lyrPane ] . default )
242
242
else e . target . setStyle ( { fillOpacity : 0.0 } )
0 commit comments