mhasbie / react-leaflet-easyprint

React wrapper of leaflet-easyPrint for react-leaflet. A simple leaflet plugin which adds an icon to print or export a map.
MIT License
9 stars 4 forks source link

Current size not working with programmatically print #4

Open nagolli opened 3 years ago

nagolli commented 3 years ago

Current size is not working with programmatically print.

Call function invokes:

{
  key: 'printMap',
  value: function (t, e) {
      this.leafletElement.printMap(t + ' page', e); //Being t+' page' = n
   },
},

Afterwards, it evals: if ('CurrentSize' === n) return this._printOpertion(n);

If it does not match, which will never do, it invokes:

(i.style.width = e.originalState.mapWidth),
(i.style.height = e.originalState.mapHeight), 

where i.style.width (nor height) is not defined for Current Size.

My workaround from outside of the module, (due to my code: printControl.current is a react reference):

if (!printControl.current.printCurrentMap) {
      printControl.current.printCurrentMap = function printMap(filename: string) {
        this.leafletElement.printMap('CurrentSize', filename);
      };
    }
    printControl.current.printCurrentMap('MyFileName');

My suggestion to solve it within the module: if ('Current page' === n) return this._printOpertion(n);