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

terrestris / react-geo / 18554106033

16 Oct 2025 07:45AM UTC coverage: 67.411% (+0.2%) from 67.169%
18554106033

push

github

web-flow
Merge pull request #4419 from marcjansen/tackle-more-sq-issues

Tackle issues found by SonarQube

652 of 1060 branches covered (61.51%)

Branch coverage included in aggregate %.

18 of 31 new or added lines in 8 files covered. (58.06%)

1 existing line in 1 file now uncovered.

1220 of 1717 relevant lines covered (71.05%)

12.84 hits per line

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

62.16
/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✔
NEW
59
    } else if (pdfPrintFunc && format === 'pdf') {
×
UNCOV
60
      setLoading(true);
×
61
      const pdfPrintSpec: PdfPrintSpec = {
×
62
        dpi,
63
        extent,
64
        extentPadding,
65
        format,
66
        legendTitle,
67
        map,
68
        mapSize,
69
        northArrow,
70
        onProgressChange,
71
        outputFileName,
72
        pdfPrintFunc,
73
        scaleBar,
74
        title
75
      };
76
      await PrintUtil.printPdf(pdfPrintSpec);
×
77
      setLoading(false);
×
78
    }
79
  };
80

81
  if (!map) {
7!
82
    return null;
×
83
  }
84

85
  return (
7✔
86
    <SimpleButton
87
      loading={loading}
88
      onClick={onPrintClick}
89
      {...passThroughProps}
90
    />
91
  );
92

93
};
94

95
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