-
-
Notifications
You must be signed in to change notification settings - Fork 101
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
TypeError: Cannot read property 'lat' of undefined #31
Comments
@whyvez I'll try to test react-leaflet markers update during this week. You could be right because there is really simple logic for rendering |
Perfect. Could use the marker id. What version of node should I use to build? |
I'm seeing this issue as well and would love to help push a fix forward. @whyvez @yuzhva did either of you make any progress on a resolution? I'm going to pull this project locally to |
@whyvez I was able to clone and build though I did have to make a few tweaks. I'm on Node v6.9.4 and NPM v3.10.10. Let me know if you're still interested in this as I could share a fork. @yuzhva there are probably a few things that could be simplified in relation to config and deployment:
Anyway, just thought I'd mention the things I noticed while going through this as some clean up might make the package easier to maintain/contribute to. |
@skipjack your advises is really nice. It's been a while since I create that wrapper, so I learned new things, but I didn't have enough time to improve them( |
Happy you found it helpful!
Yeah I totally get that, it's just the nature of open source work, right? 😜 So after digging into this for a few hours yesterday, here's a summary of what I found... Actual Error@whyvez I'm not sure what the stack trace was for you, however the core of it for me was:
So, after digging into various fixes within this library for a while with no luck, I decided to come back to the highlighted lines. Here's what I found: if (toProps.center !== fromProps.center) {
this.leafletElement.setLatLng(toProps.center)
} These lines within if ( latLng(toProps.center).equals(fromProps.center) ) { The Thoughts on this PackageSo, while the bug may not be related to this package, and aside from what I mentioned above re CSS and build process, there were some other things I noticed about the base component. First, I don't think you should support <MarkerClusterGroup ...>
{ points.map(point => <Marker position={ point } />) }
</MarkerClusterGroup> This would be a breaking change obviously, but I think it's a worthwhile one. Which leads me to my second point. With import React from 'react';
import PropTypes from 'prop-types';
import L from 'leaflet'
import 'leaflet.markercluster';
import { MapLayer } from 'react-leaflet';
import './style.css';
export default class MarkerClusterGroup extends MapLayer {
static propTypes = {
children: PropTypes.node,
options: PropTypes.object,
wrapperOptions: PropTypes.object
}
static defaultProps = {
wrapperOptions: {}
}
static childContextTypes = {
layerContainer: PropTypes.object
}
getChildContext() {
return {
layerContainer: this.leafletElement
}
}
componentWillMount() {
super.componentWillMount()
let { enableDefaultStyle, disableDefaultAnimation } = this.props.wrapperOptions
if ( enableDefaultStyle ) this.context.map._container.className += ' marker-cluster-styled'
if ( !disableDefaultAnimation ) this.context.map._container.className += ' marker-cluster-animated'
}
createLeafletElement(props) {
return new L.markerClusterGroup(props.options)
}
} This offsets most of the work on child elements calling Anyway, I just figured I'd share what I'd found. I'm still fairly new to For now, I'm just going to create a custom |
@skipjack Your solution is awesome. So, I decided to implement it and publish to npm with test coverage... (you know, all those cool labels at repository) But there were issues... |
@yuzhva great! Feel free to ping me if you need anything clarified or want someone to test the update. |
Getting the same issues with the cluster children, "Uncaught TypeError: Cannot read property '0' of undefined", after updating a cluster. |
@yuzhva loving how simple this codebase has become. I'm about to try v2 (i.e. |
I'm still getting this issue, specifically with CircleMarkers as well. If I change the CircleMarker to a regular Marker, I don't get this issue. Using |
@jwmann see my comment above. I modified the equality check in |
@skipjack so you have to make the change inside the node_modules? |
@skipjack Thanks for your work, i edited this comment 5 times until i made it work, revoked all my snippets.
And can we fix this @PaulLeCam? for now i made a npm patch that fixes that issue in my repo & for all branches, and also within my CI install. i can recommend. Everyone waiting for this fix you can support my merge request |
Unfortunately my PR has not been accepted. I don't know why exactly the !== method makes more sense than the equals method with is catching any non usable values and proceed with the computation. I would love to resolve this, asap. |
@Falkyouall did you try to upgrade your dependencies to that latest v2.x? yarn add react-leaflet-markercluster@next |
I confirm that this was happening to me when using CircleMarker inside MarkerClusterGroup and passing not only |
@yuzhva Hey, sorry for late answer, i should subscribe this thread. And Yes i'm using the latest react-leaflet version
I still have a working npm-patch script that fixes the issue by npm postinstall with the above solution. |
Hi, maybe you should to review the dependency tree, I had the same problem, from a library loads leaflet from its node_modules folder, also, my app was loading leaflet from its node_modules folder, Leaflet did a instanceOf comparison. Some as: https://github.com/Leaflet/Leaflet/blob/master/src/geo/LatLngBounds.js#L246 export function toLatLngBounds(a, b) {
if (a instanceof LatLngBounds) {
return a;
}
return new LatLngBounds(a, b);
} For some reason, I was finally able to fix the error, setting the leaflet load on config-overrides.js
|
@elesdoar can you describe your solution in more detail? I'm using plain leaflet without react. How can i setup this override in a simple TypeScript with Webpack Application? My Problem in more detail: |
@elesdoar : thanks, you save my day 🎉 |
I'm using
react-leaflet-markercluster
with with children markers and gettingTypeError: Cannot read property 'lat' of undefined
when I update the markers. From thereadme
it looks like this is not fully supported yet. Could you expand on this?I think the cause might be how keys are applied to the cloned marker element.
From my understanding React uses the key to determine on update if the item is new or an updated earlier one and the react docs advise against using index as a key.
https://facebook.github.io/react/docs/lists-and-keys.html
I'm trying to debug this but having issues building the project. At first glance I thought it was the node version. I went from v8 to v4 but still not building. Could you let me know which node version the project targets. Might also be worth adding the
engines
property in thepackage.json
with the targeted node. I can also create a seperate issue for this specifically if you think it might be best.The text was updated successfully, but these errors were encountered: