Skip to content

Commit 4818616

Browse files
committed
updates
1 parent 5fdb0b0 commit 4818616

File tree

2 files changed

+84
-44
lines changed

2 files changed

+84
-44
lines changed

src/app/Services/API/Requests/index.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,35 @@ export interface iNetcdfDownload {
3434
const zip = (a, b) => a.map((k, i) => [k, b[i]]);
3535

3636
export class RequestApi extends Http {
37+
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+
});
65+
}
3766
getCapabilities(wms) {
3867
const fullUrl =
3968
BACKEND_WMS_BASE_URL +

src/app/pages/MapPage/index.tsx

Lines changed: 55 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,7 @@ export function MapPage(props: MapPageProps) {
531531
}
532532

533533
setInProgress(true);
534+
534535
const caption = `${isMobile
535536
? currentMap.climatological_variable
536537
: labelFor(currentMap.climatological_variable)
@@ -571,23 +572,27 @@ export function MapPage(props: MapPageProps) {
571572
//@ts-ignore
572573
navigator?.userAgentData?.platform.toLowerCase().indexOf('linux') >= 0
573574
? 'jpg'
574-
: 'png'
575+
: 'jpg'
575576
}`;
576577
filename = filename.replaceAll('_', '');
577-
mapScreen
578-
.takeScreen(format, {
579-
captionFontSize: isMobile ? 10 : 12,
580-
screenName: `${currentMap.climatological_variable}`,
581-
caption: caption,
582-
})
583-
.then(blob => {
584-
setInProgress(false);
585-
saveAs(blob as Blob, filename);
586-
})
587-
.catch(e => {
588-
setInProgress(false);
589-
console.error(e);
590-
});
578+
579+
api.downloadScreenshot(window.location.href, filename).then(() => {
580+
setInProgress(false);
581+
});
582+
//mapScreen
583+
// .takeScreen(format, {
584+
// captionFontSize: isMobile ? 10 : 12,
585+
// screenName: `${currentMap.climatological_variable}`,
586+
// caption: caption,
587+
// })
588+
// .then(blob => {
589+
// setInProgress(false);
590+
// saveAs(blob as Blob, filename);
591+
// })
592+
// .catch(e => {
593+
// setInProgress(false);
594+
// console.error(e);
595+
// });
591596
};
592597

593598
const openCharts = (latLng: LatLng) => {
@@ -611,36 +616,42 @@ export function MapPage(props: MapPageProps) {
611616

612617
return (
613618
<Box sx={mapStyle}>
614-
<Modal
615-
open={error.length > 0}
616-
onClose={closeError}
617-
aria-labelledby="modal-modal-title"
618-
aria-describedby="modal-modal-description"
619-
>
620-
<Box sx={modalStyle}>
621-
<Typography id="modal-modal-title" variant="h6" component="h2">
622-
{t(error + '.title')}
623-
</Typography>
624-
<Typography id="modal-modal-description" sx={{ mt: 2 }}>
625-
{t(error + '.message')}
626-
</Typography>
627-
<Button onClick={closeError}>Ok</Button>
619+
{currentMap.op !== 'screenshot' ? (
620+
<Box>
621+
<Modal
622+
open={error.length > 0}
623+
onClose={closeError}
624+
aria-labelledby="modal-modal-title"
625+
aria-describedby="modal-modal-description"
626+
>
627+
<Box sx={modalStyle}>
628+
<Typography id="modal-modal-title" variant="h6" component="h2">
629+
{t(error + '.title')}
630+
</Typography>
631+
<Typography id="modal-modal-description" sx={{ mt: 2 }}>
632+
{t(error + '.message')}
633+
</Typography>
634+
<Button onClick={closeError}>Ok</Button>
635+
</Box>
636+
</Modal>
637+
<HeaderBar />
638+
<MapMenuBar
639+
onDownloadMapImg={handleDownloadMapImg}
640+
mode={map_mode}
641+
data={map_data}
642+
menus={menus}
643+
combinations={combinations}
644+
onMenuChange={updateCurrentMap}
645+
current_map={currentMap}
646+
foundLayers={foundLayers}
647+
setCurrentMap={setCurrentMap}
648+
openError={openError}
649+
inProgress={inProgress}
650+
/>
628651
</Box>
629-
</Modal>
630-
<HeaderBar />
631-
<MapMenuBar
632-
onDownloadMapImg={handleDownloadMapImg}
633-
mode={map_mode}
634-
data={map_data}
635-
menus={menus}
636-
combinations={combinations}
637-
onMenuChange={updateCurrentMap}
638-
current_map={currentMap}
639-
foundLayers={foundLayers}
640-
setCurrentMap={setCurrentMap}
641-
openError={openError}
642-
inProgress={inProgress}
643-
/>
652+
) : (
653+
<></>
654+
)}
644655

645656
<Map
646657
onReady={handleMapReady}

0 commit comments

Comments
 (0)