question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

width undefined when using "printMap(size, filename)"

See original GitHub issue

The output in the console is:

    proxyConsole.js:56 oops, something went wrong! TypeError: Cannot read property 'width' of undefined
        at NewClass._resizeAndPrintMap (bundle.js:1)
        at bundle.js:1
        at <anonymous>
    __stack_frame_overlay_proxy_console__ @ proxyConsole.js:56
    (anonymous) @ bundle.js:1
    Promise rejected (async)
    _createImagePlaceholder @ bundle.js:1
    printMap @ bundle.js:1
    (anonymous) @ PrintControl.js:42
    (anonymous) @ withHandlers.js:92
    ./node_modules/react-dom/lib/ReactErrorUtils.js.ReactErrorUtils.invokeGuardedCallback @ ReactErrorUtils.js:69
    executeDispatch @ EventPluginUtils.js:85
    executeDispatchesInOrder @ EventPluginUtils.js:108
    executeDispatchesAndRelease @ EventPluginHub.js:43
    executeDispatchesAndReleaseTopLevel @ EventPluginHub.js:54
    forEachAccumulated @ forEachAccumulated.js:24
    processEventQueue @ EventPluginHub.js:254
    runEventQueueInBatch @ ReactEventEmitterMixin.js:17
    handleTopLevel @ ReactEventEmitterMixin.js:27
    handleTopLevelImpl @ ReactEventListener.js:72
    perform @ Transaction.js:143
    batchedUpdates @ ReactDefaultBatchingStrategy.js:62
    batchedUpdates @ ReactUpdates.js:97
    dispatchEvent @ ReactEventListener.js:147

My component is:

    import React, { Component } from 'react'
    import PropTypes from 'prop-types'
    import 'leaflet'
    import 'leaflet-easyprint'
    import Control from 'react-leaflet-control'
    import FontIcon from 'material-ui/FontIcon'
    import styled from 'styled-components'
    import compose from 'recompose/compose'
    import withState from 'recompose/withState'
    import withHandlers from 'recompose/withHandlers'
    import getContext from 'recompose/getContext'
    import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider'
    import darkBaseTheme from 'material-ui/styles/baseThemes/darkBaseTheme'
    import getMuiTheme from 'material-ui/styles/getMuiTheme'

    const StyledButton = styled.button`
      background-color: white;
      width: 47px;
      height: 47px;
      border-radius: 5px;
      border: 2px solid rgba(0, 0, 0, 0.2);
      background-clip: padding-box;
      span {
        color: rgba(0, 0, 0, 0.54) !important;
      }
    `

    const theme = Object.assign({}, darkBaseTheme, {
      appBar: {
        height: 51,
      },
    })

    const enhance = compose(
      getContext({ map: PropTypes.object.isRequired }),
      withState('printPlugin', 'changePrintPlugin', {}),
      withHandlers({
        savePng: props => () => {
          const { printPlugin } = props
          printPlugin.printMap('Current', 'apfloraKarte')
        },
      })
    )

    class PrintControl extends Component {
      props: {
        savePng: () => void,
        printPlugin: object,
        changePrintPlugin: () => void,
      }

      componentDidMount() {
        const { map, changePrintPlugin } = this.props
        const options = {
          hidden: true,
          position: 'topright',
          // sizeModes may not be needed?
          sizeModes: ['Current'],
          exportOnly: true,
          filename: 'apfloraKarte',
        }
        const pp = window.L.easyPrint(options).addTo(map)
        changePrintPlugin(pp)
      }

      render() {
        const { savePng } = this.props

        return (
          <Control position="topright">
            <StyledButton onClick={savePng} title="Karte als png speichern">
              <MuiThemeProvider muiTheme={getMuiTheme(theme)}>
                <FontIcon id="karteAlsPngSpeichern" className="material-icons">
                  file_download
                </FontIcon>
              </MuiThemeProvider>
            </StyledButton>
          </Control>
        )
      }
    }

    export default enhance(PrintControl)

Seems like the same problem as https://github.com/rowanwins/leaflet-easyPrint/issues/32

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
hankerspacecommented, Nov 11, 2020

Found a solution, simply use these values:

  • “A4Portrait page”
  • “A4Landscape page”
  • “CurrentSize”

Example: printPlugin.printMap(‘A4Landscape page’, ‘MyFileName’);

Best 😉

1reaction
jstiecommented, Jan 10, 2018

I have the same issues replicating the simple example from the github-page.

This ‘works’ (with Leaflet-controls disappearing and reappearing):

`var printPlugin = L.easyPrint({ title: ‘My awesome print button’, hidden: true, exportOnly: true, }).addTo(map);

$(‘#map’).click(function() { printPlugin.printMap(‘CurrentSize’, ‘MyFileName’); }) `

But using ‘Current’, ‘A4Landscape’, ‘A4Portrait’ and self-defined sizes i get:

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot read property 'length' of undefined (print map with ...
Well it means this.printProvider.layout is null. Please check that your input parameters are all according to the documentation. – Chris. May 17 ...
Read more >
Python Tutorial - Getting Started with Python and Python Basics
This example reads a filename from command-line and prints the line, word and character counts (similar to wc utility in Unix). It illustrates...
Read more >
Jmol/JSmol Interactive Script Documentation
Use of undefined variables in Jmol is not an error; undefined variables ... position along the horizontal and vertical screen dimensions.
Read more >
GCC Command Line Options — EmbSys 2012 documentation
Stop on following floating point exceptions -ffree-form Assume that the source file is free form -ffree-line-length-<n> Use n as character line width in ......
Read more >
nm (GNU Binary Utilities) - sourceware.org
When a weak undefined symbol is linked and the symbol is not defined, the value of the weak symbol becomes zero with no...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found