Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using with react-leaflet #45

Closed
jakehm opened this issue Nov 27, 2016 · 3 comments
Closed

Using with react-leaflet #45

jakehm opened this issue Nov 27, 2016 · 3 comments

Comments

@jakehm
Copy link

jakehm commented Nov 27, 2016

Instead of putting it in my html, I require the plugin like this
require('./AnimatedMarker')
And I add this to the end of AnimatedMarker.js
module.exports = L.animatedMarker

My custom element looks like this:

require('./AnimatedMarker')
import { MapComponent } from 'react-leaflet'
import L from 'leaflet'

export default class AnimatedMarkerElement extends MapComponent {

  componentWillReceiveProps(nextProps) {
    const line = L.polyline([nextProps.route.coordinates]),
      animatedMarker = L.animatedMarker(line.getLatLngs())

    console.log('in componentWillRecieveProps')
    nextProps.map.addLayer(animatedMarker)
  }

  render() {
    return null
  }
}

The error is:
Uncaught TypeError: Cannot read property 'lat' of null
I think that the plugin is looking for a map that it can't find because its burried inside react elements.

@jakehm
Copy link
Author

jakehm commented Nov 28, 2016

Do you need the map object to be a global object for this plugin to work?

@jakehm
Copy link
Author

jakehm commented Nov 28, 2016

const line = L.polyline([nextProps.route.coordinates]), should not be in brackets because it is already an array.

@jakehm jakehm closed this as completed Nov 28, 2016
@goodwinfame
Copy link

@jakehm Hi, jake, how can I get this.refs.map.leafletElement Object

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants