rowanwins / leaflet-easyPrint

A leaflet plugin which adds an icon to print the map - Demo @ http://rowanwins.github.io/leaflet-easyPrint/
MIT License
248 stars 137 forks source link

Issue when issue programatic command #53

Open maka-io opened 6 years ago

maka-io commented 6 years ago

This works ok when using the buttons on the map, but when calling the printMap method elsewhere has this error:

modules.js?hash=065275937aca1cbee55ce09c264f23ee80b21989:440455 oops, something went wrong! TypeError: Cannot read property 'width' of undefined
    at NewClass._resizeAndPrintMap (modules.js?hash=065275937aca1cbee55ce09c264f23ee80b21989:440455)
    at modules.js?hash=065275937aca1cbee55ce09c264f23ee80b21989:440455
    at meteor.js?hash=6d285d84547b3dad9717a7c89c664b61b45ea3d8:1117
    at <anonymous>
(anonymous) @ modules.js?hash=065275937aca1cbee55ce09c264f23ee80b21989:440455
(anonymous) @ meteor.js?hash=6d285d84547b3dad9717a7c89c664b61b45ea3d8:1117
Promise rejected (async)
Promise.then @ promise.js?hash=c98d83815206ae5685c0ad4b836235e77666d747:97
_createImagePlaceholder @ modules.js?hash=065275937aca1cbee55ce09c264f23ee80b21989:440455
printMap @ modules.js?hash=065275937aca1cbee55ce09c264f23ee80b21989:440455
StepFinalComponent._this.handleSubmitOrder @ step-final.jsx:228
submit @ step-final.jsx:116
StepperControlComponent._this.handleNext @ stepper-control.jsx:122
EnhancedButton._this.handleTouchTap @ modules.js?hash=065275937aca1cbee55ce09c264f23ee80b21989:41172
ReactErrorUtils.js.ReactErrorUtils.invokeGuardedCallback @ modules.js?hash=065275937aca1cbee55ce09c264f23ee80b21989:9171
executeDispatch @ modules.js?hash=065275937aca1cbee55ce09c264f23ee80b21989:8952
executeDispatchesInOrder @ modules.js?hash=065275937aca1cbee55ce09c264f23ee80b21989:8975
executeDispatchesAndRelease @ modules.js?hash=065275937aca1cbee55ce09c264f23ee80b21989:8365
executeDispatchesAndReleaseTopLevel @ modules.js?hash=065275937aca1cbee55ce09c264f23ee80b21989:8376
forEachAccumulated @ modules.js?hash=065275937aca1cbee55ce09c264f23ee80b21989:9278
processEventQueue @ modules.js?hash=065275937aca1cbee55ce09c264f23ee80b21989:8576
runEventQueueInBatch @ modules.js?hash=065275937aca1cbee55ce09c264f23ee80b21989:15719
handleTopLevel @ modules.js?hash=065275937aca1cbee55ce09c264f23ee80b21989:15729
handleTopLevelImpl @ modules.js?hash=065275937aca1cbee55ce09c264f23ee80b21989:20770
perform @ modules.js?hash=065275937aca1cbee55ce09c264f23ee80b21989:11677
batchedUpdates @ modules.js?hash=065275937aca1cbee55ce09c264f23ee80b21989:20683
batchedUpdates @ modules.js?hash=065275937aca1cbee55ce09c264f23ee80b21989:10345
dispatchEvent @ modules.js?hash=065275937aca1cbee55ce09c264f23ee80b21989:20845
rowanwins commented 6 years ago

Hi @maka-io

Hmmm can you confirm what version of the plugin you are using? And from what I can tell this might be being bundled into a react app or something like that?

Are you using custom sizing or anything like that? A snippet of the plugin config and how you're calling it would be handy.

ShawnUrbach commented 6 years ago

I am having the same issue. I get the following error:

index.js:141 oops, something went wrong! TypeError: Cannot read property 'width' of undefined
    at e._resizeAndPrintMap (index.js:151)
    at index.js:138
    at <anonymous>

Plugin config:

var printPlugin = L.easyPrint({
        title: 'Print',
    position: 'bottomleft',
    hideControlContainer: false,
    sizeModes: ['A4Landscape'],
    hidden: false,
}).addTo(map);

Function call:

$('#saveImage').click(function(){
    printPlugin.printMap('A4Landscape', 'MyFileName');
});

I am using the latest version of the default branch. Not bundling with React. Thanks.

rowanwins commented 6 years ago

Thanks for the extended report @ShawnUrbach I'll try and take a look in the next few days

sblaauw commented 6 years ago

I received the same error as @ShawnUrbach.

The problem: When _resizeAndPrintMap() was called internally via the control it would make a call with sizeMode being the full className "A4Landscape page" whereas calling it programmatically would only be A4Landscape which wouldn't match the preset.

I've added a pull request to resolve the issue.

Hatteron commented 5 years ago

When this problem will solved ?

neerajlk commented 5 years ago

This problem still does persist. any fix?

Amber711 commented 4 years ago

any updates...

mtan11 commented 4 years ago

Any help? i still had this problem