Skip to content

Commit ce34b3b

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 51195c7 commit ce34b3b

File tree

2 files changed

+60
-40
lines changed

2 files changed

+60
-40
lines changed

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

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -406,46 +406,52 @@ 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-
}
441409
this.countryCode.setValue(
442410
this.dashboard.page?.geographicContext?.country
443411
);
444-
} else {
412+
} else if (this.dashboard.page.geographicContext.region) {
445413
this.regionCode.setValue(
446414
this.dashboard.page?.geographicContext?.region
447415
);
448416
}
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+
}
449455
}
450456
this.initContext();
451457
this.updateContextOptions();

assets/geographic-context-data.json

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,45 @@
22
"regions": [
33
{
44
"code": "AF",
5-
"name": "AFRO"
5+
"name": "AFRO",
6+
"centerlatitude": "10.833305983642491",
7+
"centerlongitude": "17.226562500000004"
68
},
79
{
810
"code": "AM",
9-
"name": "AMRO"
11+
"name": "AMRO",
12+
"centerlatitude": "3.162455530237848",
13+
"centerlongitude": "-68.20312500000001"
1014
},
1115
{
1216
"code": "EM",
13-
"name": "EMRO"
17+
"name": "EMRO",
18+
"centerlatitude": "22.268764039073968",
19+
"centerlongitude": "38.3203125"
1420
},
1521
{
1622
"code": "EU",
17-
"name": "EURO"
23+
"name": "EURO",
24+
"centerlatitude": "58.81374171570782",
25+
"centerlongitude": "67.500000000000011"
1826
},
1927
{
2028
"code": "SE",
21-
"name": "SEARO"
29+
"name": "SEARO",
30+
"centerlatitude": "31.653381399664",
31+
"centerlongitude": "68.55468750000001"
2232
},
2333
{
2434
"code": "WP",
25-
"name": "WPRO"
35+
"name": "WPRO",
36+
"centerlatitude": "11.178401873711785",
37+
"centerlongitude": "68.90625000000001"
2638
},
2739
{
2840
"code": "HQ",
29-
"name": "HQ"
41+
"name": "HQ",
42+
"centerlatitude": "44.08758502824518",
43+
"centerlongitude": "4.570312500000001"
3044
}
3145
],
3246
"countries": [

0 commit comments

Comments
 (0)