react-native-map-clustering icon indicating copy to clipboard operation
react-native-map-clustering copied to clipboard

Error when dynamically adding new marker on open cluster

Open Thanasis1101 opened this issue 4 years ago • 2 comments

I am using this package for clustering the markers on a map. The markers are updated dynamically and they can be added or removed at any time. When I see a cluster with X markers, and a marker is added in this cluster, then everything works fine and the cluster label is changed from X to X+1. The problem is when I have already zoomed in the cluster and then the new marker (which belongs in the same cluster) is added, the app crushes and I get the error below:

TypeError: undefined is not an object (evaluating 'clusterChildren[_i + start].properties')

My code looks like this:

import { Marker } from 'react-native-maps';
import MapView from "react-native-map-clustering";

<MapView
    ref={mapRef}
    ...
>
    {this.state.markers.map((marker, index) => {
        return (<Marker ... />)
    })}
</MapView>

Updating the markers looks like this:

this.setState({ markers: updated_markers})

Could this be fixed in a newer version? If you need me to clarify anything feel free to ask.

Thanasis1101 avatar Jun 02 '20 11:06 Thanasis1101

Hey @Thanasis1101 any update on this, please?

SirPhemmiey avatar Feb 11 '21 03:02 SirPhemmiey

@SirPhemmiey I haven't tested it with any newer version, probably it is now fixed. I see that a check has been added at this line. As the error suggested, there was no clusterChildren[i + start], so it couldn't get its properties. But with the new check, this is no longer the case, after this commit.

When did you test it last time? If it was before May 2020 then can you update the package, test it again and report the results? Maybe I will check it too, and if we see it is now fixed I can mark this issue as solved.

Thanasis1101 avatar Feb 11 '21 21:02 Thanasis1101