@@ -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 ( ) ;
0 commit comments