Skip to content

Commit 5819abe

Browse files
feat/AB#80878_limit-zoom-of-map-widgets-for-the-given-geographic-context-in-the-page feat: add regions coordinates feat: add automatic center for region context
1 parent c671f45 commit 5819abe

File tree

2 files changed

+1560
-516
lines changed

2 files changed

+1560
-516
lines changed

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

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,11 +409,49 @@ export class DashboardComponent
409409
this.countryCode.setValue(
410410
this.dashboard.page?.geographicContext?.country
411411
);
412-
} else {
412+
} else if (this.dashboard.page.geographicContext.region) {
413413
this.regionCode.setValue(
414414
this.dashboard.page?.geographicContext?.region
415415
);
416416
}
417+
// Get related geographic context coordinates
418+
const geographicContextCoordinates = this.dashboard.page
419+
.geographicContext.country
420+
? this.geographicContextCountries.find(
421+
(country) =>
422+
country.code ===
423+
this.dashboard?.page?.geographicContext?.country
424+
)
425+
: this.dashboard.page.geographicContext.region
426+
? this.geographicContextRegions.find(
427+
(region) =>
428+
region.code ===
429+
this.dashboard?.page?.geographicContext?.region
430+
)
431+
: null;
432+
if (geographicContextCoordinates) {
433+
// Map all map widgets to have as initial state in their coords the selected geographic context
434+
this.dashboard.structure = this.dashboard.structure.map(
435+
(widget: any) => {
436+
if (widget.id === 'map') {
437+
// Update initial state with the geographic context coordinates if no initial state is set on top of it
438+
if (
439+
!widget.settings.initialState.viewpoint.center.longitude
440+
) {
441+
widget.settings.initialState.viewpoint.center.longitude =
442+
geographicContextCoordinates.centerlongitude;
443+
}
444+
if (
445+
!widget.settings.initialState.viewpoint.center.latitude
446+
) {
447+
widget.settings.initialState.viewpoint.center.latitude =
448+
geographicContextCoordinates.centerlatitude;
449+
}
450+
}
451+
return widget;
452+
}
453+
);
454+
}
417455
}
418456
this.initContext();
419457
this.updateContextOptions();

0 commit comments

Comments
 (0)