@@ -92,6 +92,8 @@ export class GeospatialMapComponent implements AfterViewInit, OnInit, OnDestroy
9292 */
9393 @Input ( ) layout = 'item' ;
9494
95+ DEFAULT_CENTRE_POINT = [ environment . geospatialMapViewer . defaultCentrePoint . lat , environment . geospatialMapViewer . defaultCentrePoint . lng ] ;
96+
9597 private subs : Subscription [ ] = [ ] ;
9698
9799 constructor ( private elRef : ElementRef ,
@@ -146,7 +148,7 @@ export class GeospatialMapComponent implements AfterViewInit, OnInit, OnDestroy
146148 const el = this . elRef . nativeElement . querySelector ( 'div.geospatial-map' ) ;
147149 // Defaults are London - we update this after drawing markers to zoom and fit based on data
148150 this . map = L . map ( el , {
149- center : [ 51.505 , - 0.09 ] ,
151+ center : this . DEFAULT_CENTRE_POINT ,
150152 zoom : 11 ,
151153 } ) ;
152154 const tileProviders = environment . geospatialMapViewer . tileProviders ;
@@ -247,9 +249,15 @@ export class GeospatialMapComponent implements AfterViewInit, OnInit, OnDestroy
247249 point . url = '/search' ;
248250 return point ;
249251 } ) . filter ( ( point ) => hasValue ( point ) && hasValue ( point . coordinates ) && point . coordinates . length === 2 ) ;
252+ // If there are no points to draw, instead zoom out and show a tooltip and return early
250253 if ( isEmpty ( points ) ) {
254+ this . map . setZoom ( 1 ) ;
255+ const marker = new L . marker ( this . DEFAULT_CENTRE_POINT , { opacity : 0 } ) ;
256+ marker . bindTooltip ( '<span class="fs-4 no-results-tooltip">' + this . translateService . instant ( 'search.results.geospatial-map.empty' ) + '</span>' , { permanent : true , offset : [ 0 , 0 ] , direction : 'top' } ) ;
257+ this . map . addLayer ( marker ) ;
251258 return ;
252259 }
260+ // We have >0 markers, so construct links and tooltips for each
253261 const markers = L . markerClusterGroup ( ) ;
254262 for ( let i = 0 ; i < points . length ; i ++ ) {
255263 // GeoJSON coordinates are [x, y] or [longitude, latitude] or [eastings, northings]
@@ -305,6 +313,12 @@ export class GeospatialMapComponent implements AfterViewInit, OnInit, OnDestroy
305313 this . map . addLayer ( markers ) ;
306314 const bounds = L . latLngBounds ( points . map ( point => [ point . latitude , point . longitude ] ) ) ;
307315 this . map . fitBounds ( bounds ) ;
316+ } else {
317+ // If there are no points to draw, instead zoom out and show a tooltip
318+ this . map . setZoom ( 1 ) ;
319+ const marker = new L . marker ( this . DEFAULT_CENTRE_POINT , { opacity : 0 } ) ;
320+ marker . bindTooltip ( '<span class="fs-4 no-results-tooltip">' + this . translateService . instant ( 'search.results.geospatial-map.empty' ) + '</span>' , { permanent : true , offset : [ 0 , 0 ] , direction : 'top' } ) ;
321+ this . map . addLayer ( marker ) ;
308322 }
309323 }
310324
0 commit comments