Igor-Vladyka / leaflet.browser.print

A leaflet plugin which allows users to print the map directly from the browser
https://igor-vladyka.github.io/leaflet.browser.print/
MIT License
154 stars 76 forks source link

Map Moves After Print Action #131

Open outputtxt opened 4 months ago

outputtxt commented 4 months ago

Hi, I am using this plugin with "react-leaflet": "^4.2.1", and I am experiencing 2 unwanted behavior in my project.

1) Custom Selection acquires wrong coordinates. The printed area is always bottom right corner of selected area. 2) After print action, printed or cancelled, map always moves to bottom right corner.

by bottom right corner, I mean, map div moves down by current height, and moves right by current width. I am using Edge, Version 120.0.2210.133 (Official build) (64-bit)

My code is :

L.control.browserPrint({
      position: "topleft",
      title: "Print",
      printModes: [
        L.BrowserPrint.Mode.Landscape("A4", {
          margin: 2,
          title: "Horizontal",
          // invalidateBounds: false,
          header: {
            enabled: true,
            text: " ",
            size: "0mm",
          },
          footer: {
            enabled: true,
            text: " ",
            size: "0mm",
          },
        }),

        L.BrowserPrint.Mode.Custom("B1", {
          orientation: "Landscape",
          title: "Select Area",
          margin: 2,
        }),
      ],
      documentTitle: "MyProject",
    }).addTo(map);

Any help is appreciated, best regards.

Jackidu54 commented 4 months ago

Same problem here using Chrome,

Logs say :

leaflet.browser.print.js:92 Uncaught TypeError: Cannot set properties of undefined (setting 'start') at NewClass._startAutoPolygon (leaflet.browser.print.js:92:29) at NewClass.fire (leaflet.js?v=7dea7d77:387:20) at NewClass._fireDOMEvent (leaflet.js?v=7dea7d77:2959:24) at NewClass._handleDOMEvent (leaflet.js?v=7dea7d77:2923:16) at HTMLDivElement.handler (leaflet.js?v=7dea7d77:1733:21)

Downgrading the plugin to 1.0 does not change anything

outputtxt commented 4 months ago

if I comment the line below inside leaflet.browser.print.js, the map movement stops:

this._map.invalidateSize({reset: true, animate: false, pan: false});

And I tried some possible alternatives on custom select, after changing the page size to A3 and adding header true but 0mm, the wrong area selection error is also gone.

Bu meanwhile I found out that, paper header/footer props are not working well on different browsers. In my case, even with false, it still continues to draw header/footer on edge.

Falke-Design commented 2 months ago

I can't reproduce this error. @outputtxt can you please create a demo: https://plnkr.co/edit/CX484lkQSfC0mr4m