Skip to content

Commit 51195c7

Browse files
Merge branch 'feat/AB#80878_limit-zoom-of-map-widgets-for-the-given-geographic-context-in-the-page' of github.com-relief:ReliefApplications/ems-frontend into feat/AB#80878_limit-zoom-of-map-widgets-for-the-given-geographic-context-in-the-page
2 parents ca12fcc + 1cae632 commit 51195c7

File tree

2 files changed

+1544
-520
lines changed

2 files changed

+1544
-520
lines changed

apps/back-office/src/app/dashboard/pages/dashboard/dashboard.component.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,38 @@ export class DashboardComponent
406406
};
407407
if (this.dashboard.page?.geographicContext?.enabled) {
408408
if (this.dashboard.page.geographicContext.country) {
409+
const countryCoordinates = this.geographicContextCountries.find(
410+
(country) =>
411+
country.code ===
412+
this.dashboard?.page?.geographicContext?.country
413+
);
414+
if (countryCoordinates) {
415+
// Map all map widgets to have as initial state in their coords the selected country
416+
this.dashboard.structure = this.dashboard.structure.map(
417+
(widget: any) => {
418+
if (widget.id === 'map') {
419+
// Update initial state with the country coordinates if no initial state is set on top of it
420+
// Increase the zoom to have a clear target of the selected country in the map
421+
if (widget.settings.initialState.viewpoint.zoom === 2) {
422+
widget.settings.initialState.viewpoint.zoom = 4;
423+
}
424+
if (
425+
!widget.settings.initialState.viewpoint.center.longitude
426+
) {
427+
widget.settings.initialState.viewpoint.center.longitude =
428+
countryCoordinates.centerlongitude;
429+
}
430+
if (
431+
!widget.settings.initialState.viewpoint.center.latitude
432+
) {
433+
widget.settings.initialState.viewpoint.center.latitude =
434+
countryCoordinates.centerlatitude;
435+
}
436+
}
437+
return widget;
438+
}
439+
);
440+
}
409441
this.countryCode.setValue(
410442
this.dashboard.page?.geographicContext?.country
411443
);

0 commit comments

Comments
 (0)