@@ -43,7 +43,7 @@ export class WidgetMapbox extends LitElement {
4343
4444 disconnectedCallback ( ) {
4545 super . disconnectedCallback ( )
46- if ( this . resizeObserver ) {
46+ if ( this . resizeObserver ) {
4747 this . resizeObserver . disconnect ( )
4848 }
4949 }
@@ -67,16 +67,33 @@ export class WidgetMapbox extends LitElement {
6767
6868 this . customDebounce = setTimeout ( ( ) => {
6969 this . map ?. resize ( )
70- this . fitBounds ( )
70+ this . fitBounds ( )
7171 } , 300 )
7272 }
7373
74+ isArrayOfTwoNumbers ( v : any ) {
75+ return (
76+ Array . isArray ( v ) && // Check if it's an array
77+ v . length <= 3 && // Check if the array has exactly two elements
78+ typeof v [ 0 ] === 'number' && // Check if the first element is a number
79+ typeof v [ 1 ] === 'number' // Check if the second element is a number
80+ )
81+ }
82+
7483 fitBounds ( ) {
7584 const bounds = new mapboxgl . LngLatBounds ( )
7685 this . dataSources . forEach ( ( col : GeoJSON . FeatureCollection ) => {
7786 col . features . forEach ( ( f ) => {
7887 // @ts -ignore
79- if ( f . geometry . coordinates ?. length ) bounds . extend ( f . geometry . coordinates )
88+ if ( this . isArrayOfTwoNumbers ( f . geometry ?. coordinates ) ) {
89+ // @ts -ignore
90+ bounds . extend ( f . geometry . coordinates )
91+ } else {
92+ // @ts -ignore
93+ for ( const lnglat of f . geometry . coordinates ) {
94+ if ( this . isArrayOfTwoNumbers ( lnglat ) ) bounds . extend ( lnglat )
95+ }
96+ }
8097 } )
8198 } )
8299 if ( bounds . isEmpty ( ) ) {
@@ -129,7 +146,7 @@ export class WidgetMapbox extends LitElement {
129146 // Filter for latest Values
130147 this . dataSets . forEach ( ( ds ) => {
131148 if ( ds ?. latestValues && ds ?. latestValues > 0 ) {
132- ds . data = ds ?. data ?. slice ( 0 , ds . latestValues ?? 1 ) ?? [ ]
149+ ds . data = ds ?. data ?. slice ( - ds . latestValues || - 1 ) ?? [ ]
133150 }
134151 } )
135152
@@ -586,6 +603,17 @@ export class WidgetMapbox extends LitElement {
586603 a.mapboxgl-ctrl-logo {
587604 display: none;
588605 }
606+
607+ .no-data {
608+ font-size: 20px;
609+ color: var(--re-text-color, #000);
610+ display: flex;
611+ height: 100%;
612+ width: 100%;
613+ text-align: center;
614+ align-items: center;
615+ justify-content: center;
616+ }
589617 `
590618
591619 render ( ) {
@@ -595,17 +623,10 @@ export class WidgetMapbox extends LitElement {
595623 rel ="stylesheet "
596624 />
597625 < div class ="wrapper ">
598- < header
599- class ="paging "
600- ?active =${ this . inputData ?. title || this . inputData ?. subTitle }
601- >
626+ < header class ="paging " ?active =${ this . inputData ?. title || this . inputData ?. subTitle } >
602627 < div class ="title ">
603- < h3 class ="paging " ?active =${ this . inputData ?. title } >
604- ${ this . inputData ?. title }
605- </ h3 >
606- < p class ="paging " ?active =${ this . inputData ?. subTitle } >
607- ${ this . inputData ?. subTitle }
608- </ p >
628+ < h3 class ="paging " ?active =${ this . inputData ?. title } > ${ this . inputData ?. title } </ h3 >
629+ < p class ="paging " ?active =${ this . inputData ?. subTitle } > ${ this . inputData ?. subTitle } </ p >
609630 </ div >
610631 < div class ="legend paging " ?active =${ this ?. inputData ?. showLegend } >
611632 ${ repeat (
@@ -624,7 +645,8 @@ export class WidgetMapbox extends LitElement {
624645 ) }
625646 </ div >
626647 </ header >
627- < div id ="map "> </ div >
648+ < div class ="paging no-data " ?active =${ ! this . dataSets . length } > No Data</ div >
649+ < div id ="map " class ="paging " ?active =${ this . dataSets . length } > </ div >
628650 </ div >
629651 `
630652 }
0 commit comments