Skip to content

Commit 6f7f545

Browse files
committed
Geospatial maps: Better "no points" handling
* If no results for browse or search maps are available, zoom to 1 and show a i18n tooltip * Added a missing i18n for point filter * New default centre point added to configuration
1 parent 0bd93ae commit 6f7f545

File tree

6 files changed

+42
-2
lines changed

6 files changed

+42
-2
lines changed

config/config.example.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,3 +578,10 @@ geospatialMapViewer:
578578
# (see https://leaflet-extras.github.io/leaflet-providers/preview/) for a full list
579579
tileProviders:
580580
- 'OpenStreetMap.Mapnik'
581+
# Starting centre point for the map, as lat and lng coordinates. This is useful
582+
# to set the centre of the map when the map is first loaded and if there are no
583+
# points, shapes or markers to display.
584+
# Defaults to the centre of Istanbul
585+
defaultCentrePoint:
586+
lat: 41.015137
587+
lng: 28.979530

src/app/shared/geospatial-map/geospatial-map.component.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

src/assets/i18n/en.json5

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4483,6 +4483,8 @@
44834483

44844484
"search.filters.applied.operator.query": "",
44854485

4486+
"search.filters.applied.f.point": "Coordinates",
4487+
44864488
"search.filters.filter.title.head": "Title",
44874489

44884490
"search.filters.filter.title.placeholder": "Title",
@@ -4731,6 +4733,8 @@
47314733

47324734
"search.results.empty": "Your search returned no results.",
47334735

4736+
"search.results.geospatial-map.empty": "No results on this page with geospatial locations",
4737+
47344738
"search.results.view-result": "View",
47354739

47364740
"search.results.response.500": "An error occurred during query execution, please try again later",

src/config/default-app-config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,5 +619,11 @@ export class DefaultAppConfig implements AppConfig {
619619
tileProviders: [
620620
'OpenStreetMap.Mapnik',
621621
],
622+
// Starting centre point for maps (before drawing and zooming to markers)
623+
// Defaults to Istanbul
624+
defaultCentrePoint: {
625+
lat: 41.015137,
626+
lng: 28.979530,
627+
},
622628
};
623629
}

src/config/geospatial-map-config.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ export class GeospatialMapConfig implements Config {
3838
*/
3939
public tileProviders: string[];
4040

41-
41+
/**
42+
* Starting centre point for maps (before drawing and zooming to markers)
43+
* Takes a lat and lng float value as coordinates
44+
* Defaults to Istanbul
45+
*/
46+
public defaultCentrePoint: { lat: number, lng: number };
4247

4348
}

src/environments/environment.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,5 +448,9 @@ export const environment: BuildConfig = {
448448
tileProviders: [
449449
'OpenStreetMap.Mapnik',
450450
],
451+
defaultCentrePoint: {
452+
lat: 41.015137,
453+
lng: 28.979530,
454+
},
451455
},
452456
};

0 commit comments

Comments
 (0)