@@ -35,33 +35,39 @@ const zip = (a, b) => a.map((k, i) => [k, b[i]]);
3535
3636export class RequestApi extends Http {
3737 downloadScreenshot ( href : string , filename : string ) {
38- return this . instance
39- . get < any > ( BACKEND_API_URL + '/maps/map-screenshot' , {
40- params : {
41- url : href + '&op=screenshot' ,
42- } ,
43- responseType : 'blob' ,
44- } )
45- . then ( response => {
46- const url = window . URL . createObjectURL ( new Blob ( [ response . data ] ) ) ;
47- console . log ( url ) ;
48- // create file link in browser's memory
49- const href = URL . createObjectURL ( response . data ) ;
50-
51- // create "a" HTML element with href to file & click
52- const link = document . createElement ( 'a' ) ;
53- link . href = href ;
54- link . setAttribute ( 'download' , filename ) ; //or any other extension
55- document . body . appendChild ( link ) ;
56- link . click ( ) ;
57-
58- // clean up "a" element & remove ObjectURL
59- document . body . removeChild ( link ) ;
60- URL . revokeObjectURL ( href ) ;
61- } )
62- . catch ( err => {
63- console . log ( err ) ;
64- } ) ;
38+ href = href . replaceAll (
39+ 'http://localhost:3000' ,
40+ 'https://arpav.geobeyond.dev' ,
41+ ) ;
42+ return (
43+ this . instance
44+ . get < any > ( BACKEND_API_URL + '/maps/map-screenshot' , {
45+ params : {
46+ url : href + '&op=screenshot' ,
47+ } ,
48+ responseType : 'blob' ,
49+ } )
50+ //@ts -ignore
51+ . then ( ( response : Blob ) => {
52+ const url = window . URL . createObjectURL ( response ) ;
53+ console . log ( url ) ;
54+ // create file link in browser's memory
55+
56+ // create "a" HTML element with href to file & click
57+ const link = document . createElement ( 'a' ) ;
58+ link . href = url ;
59+ link . setAttribute ( 'download' , filename ) ; //or any other extension
60+ document . body . appendChild ( link ) ;
61+ link . click ( ) ;
62+
63+ // clean up "a" element & remove ObjectURL
64+ document . body . removeChild ( link ) ;
65+ URL . revokeObjectURL ( href ) ;
66+ } )
67+ . catch ( err => {
68+ console . log ( err ) ;
69+ } )
70+ ) ;
6571 }
6672 getCapabilities ( wms ) {
6773 const fullUrl =
@@ -170,7 +176,25 @@ export class RequestApi extends Http {
170176 public getCities = ( ) => {
171177 if ( localStorage . getItem ( 'municipality-centroids' ) ) {
172178 // @ts -ignore
173- return JSON . parse ( localStorage . getItem ( 'municipality-centroids' ) ) ;
179+ let cities = JSON . parse ( localStorage . getItem ( 'municipality-centroids' ) ) ;
180+ let lastCities = [ ] ;
181+ if ( localStorage . getItem ( 'lastCities' ) ) {
182+ // @ts -ignore
183+ lastCities = JSON . parse ( localStorage . getItem ( 'lastCities' ) ) ;
184+ }
185+ console . log ( cities , lastCities ) ;
186+ let fcities = cities . filter ( city => {
187+ let found = false ;
188+ for ( let c of lastCities ) {
189+ if ( c ) {
190+ console . log ( c ) ;
191+ //@ts -ignore
192+ if ( c . label === city . label ) found = true ;
193+ }
194+ }
195+ return ! found ;
196+ } ) ;
197+ return [ ...lastCities , ...fcities ] ;
174198 } else {
175199 this . instance
176200 . get < any > ( BACKEND_API_URL + '/municipalities/municipality-centroids' )
@@ -634,12 +658,17 @@ export class RequestApi extends Http {
634658 if ( mode !== 'forecast' ) {
635659 }
636660
637- return this . instance . get < any > ( url ) . then ( ( x : any ) => {
638- x . series . map ( a => {
639- console . log ( 'timeseries: ' , a . name ) ;
661+ return this . instance
662+ . get < any > ( url )
663+ . then ( ( x : any ) => {
664+ x . series . map ( a => {
665+ console . log ( 'timeseries: ' , a . name ) ;
666+ } ) ;
667+ return x ;
668+ } )
669+ . catch ( error => {
670+ return { series : [ ] } ;
640671 } ) ;
641- return x ;
642- } ) ;
643672 } ;
644673
645674 public getTimeSeriesDataPoint = (
0 commit comments