• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

terrestris / react-geo / 14379560298

10 Apr 2025 11:42AM UTC coverage: 58.59% (-0.05%) from 58.642%
14379560298

push

github

web-flow
Merge pull request #4205 from ahennr/fix/print-util

feat(printbutton): use typings defined in react-util including extent and extentPadding

508 of 975 branches covered (52.1%)

Branch coverage included in aggregate %.

7 of 11 new or added lines in 3 files covered. (63.64%)

1 existing line in 1 file now uncovered.

1013 of 1621 relevant lines covered (62.49%)

11.27 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

61.54
/src/Button/PrintButton/PrintButton.tsx
1
import React, {
2
  useState
3
} from 'react';
4

5
import useMap from '@terrestris/react-util/dist/Hooks/useMap/useMap';
6
import { PdfPrintSpec, PngPrintSpec, PrintSpec, PrintUtil } from '@terrestris/react-util/dist/Util/PrintUtil';
7

8
import SimpleButton, {
9
  SimpleButtonProps
10
} from '../SimpleButton/SimpleButton';
11

12
export type PrintButtonProps = Omit<PrintSpec, 'map'> & {
13
  format?: 'png' | 'pdf';
14
} & Partial<PdfPrintSpec> & Partial<PngPrintSpec> & SimpleButtonProps;
15

16
export const PrintButton: React.FC<PrintButtonProps> = ({
1✔
17
  attributions = 'bottom-right',
7✔
18
  dpi = 120,
7✔
19
  extent,
20
  extentPadding,
21
  format = 'png',
7✔
22
  legendTitle = 'Legend',
7✔
23
  mapSize,
24
  northArrow = 'top-right',
7✔
25
  onProgressChange,
26
  outputFileName = 'react-geo-image',
7✔
27
  pdfPrintFunc,
28
  scaleBar = {
7✔
29
    position: 'bottom-left',
30
    units: 'metric'
31
  },
32
  title = 'Print',
7✔
33
  ...passThroughProps
34
}) => {
35

36
  const [loading, setLoading] = useState<boolean>(false);
7✔
37
  const map = useMap();
7✔
38

39
  const onPrintClick = async () => {
7✔
40
    if (!map) {
2!
41
      return;
×
42
    }
43
    if (format === 'png') {
2!
44
      setLoading(true);
2✔
45
      const pngPrintSpec: PngPrintSpec = {
2✔
46
        attributions,
47
        dpi,
48
        extent,
49
        extentPadding,
50
        format,
51
        map,
52
        mapSize,
53
        onProgressChange,
54
        outputFileName,
55
        scaleBar
56
      };
57
      await PrintUtil.printPng(pngPrintSpec);
2✔
58
      setLoading(false);
2✔
59
      return;
2✔
60
    }
NEW
61
    if (pdfPrintFunc && format === 'pdf') {
×
62
      setLoading(true);
×
NEW
63
      const pdfPrintSpec: PdfPrintSpec = {
×
64
        dpi,
65
        extent,
66
        extentPadding,
67
        format,
68
        legendTitle,
69
        map,
70
        mapSize,
71
        northArrow,
72
        onProgressChange,
73
        outputFileName,
74
        pdfPrintFunc,
75
        scaleBar,
76
        title
77
      };
NEW
78
      await PrintUtil.printPdf(pdfPrintSpec);
×
UNCOV
79
      setLoading(false);
×
NEW
80
      return;
×
81
    }
82
  };
83

84
  if (!map) {
7!
85
    return null;
×
86
  }
87

88
  return (
7✔
89
    <SimpleButton
90
      loading={loading}
91
      onClick={onPrintClick}
92
      {...passThroughProps}
93
    />
94
  );
95

96
};
97

98
export default PrintButton;
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc