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

[question] Caching Issue #115

Open
cbaker opened this issue Jul 20, 2020 · 8 comments
Open

[question] Caching Issue #115

cbaker opened this issue Jul 20, 2020 · 8 comments

Comments

@cbaker
Copy link

cbaker commented Jul 20, 2020

When changing the data in the state that gets rendered to the map our markercluster reference to .getAllChildMarkers() appears to have mixed cache & new data.

When logging the context value, it appears to be 100% correct, however, if I log the value of cluster.getAllChildMarkers() in the iconCreateFunction that I've made, I get a mix between newly added data & stale "cached" data that shouldn't be in there.

I think this is due to updateLeafletElement not being implemented. Our position may not change for some markers, however, the values will, thus resulting in this pseudo caching.

@cbaker
Copy link
Author

cbaker commented Jul 21, 2020

Some of our code that demonstrates usage.

<MarkerClusterGroup
            onclustermouseover={handleClusterMouseover}
            ref={clusterRef}
            iconCreateFunction={markerClusterIcon}
            removeOutsideVisibleBounds
            chunkedLoading
        >
            {/* this visible array has the good values in it, so its not this. */}
            {visible.map(v => (
                <ComposedMarker
                    key={v.UNIQUE_IDENTIFIER}
                    position={v.location}
                    icon={markerIcon(v)}
                    status={v.status}
                    value={v[map.key]}
                    name={v.name}
                    id={v.UNIQUE_IDENTIFIER}
                />
</MarkerClusterGroup>

@filipomar
Copy link

I have faced what I think is a variation of the same issue, from what I understood, from the behaviour and looking at the code, it seems once the function is initially set, the iconCreateFunction will never be updated.

If you change the key on MarkerClusterGroup it will work though, as it will force react to dump the old instance and create the new one.

@cbaker
Copy link
Author

cbaker commented Aug 6, 2020

I have faced what I think is a variation of the same issue, from what I understood, from the behaviour and looking at the code, it seems once the function is initially set, the iconCreateFunction will never be updated.

If you change the key on MarkerClusterGroup it will work though, as it will force react to dump the old instance and create the new one.

I ended up just using natively built leaflet markers & using the cluster ref to append them.

@mauron85
Copy link

mauron85 commented Aug 11, 2020

the iconCreateFunction will never be updated.

since I don't see any specific handler for iconCreateFunction, isn't this react-leaflet problem?

EDIT: I'll answer this myself. No it isn't. This plugin just doesn't implement updateLeafletElement

@mauron85
Copy link

I've came out with following addition. It requires id prop (must be same as key) to be added to the Marker

  updateLeafletElement(fromProps, toProps) {
    const { children: fromChildren } = fromProps;
    const { children: toChildren } = toProps;

    const markers = this.leafletElement.getLayers();
    toChildren.forEach(({ key, props }) => {
      const marker = markers.find(({ options }) => options.id === key);
      if (marker) {
        const { children, ...restProps } = props;
        L.setOptions(marker, restProps);
      }
    });

    this.leafletElement.refreshClusters(markers);
  }

@stale
Copy link

stale bot commented Sep 10, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Sep 10, 2020
@Thiti-Dev
Copy link

Thiti-Dev commented Oct 12, 2020

I've came out with following addition. It requires id prop (must be same as key) to be added to the Marker

  updateLeafletElement(fromProps, toProps) {
    const { children: fromChildren } = fromProps;
    const { children: toChildren } = toProps;

    const markers = this.leafletElement.getLayers();
    toChildren.forEach(({ key, props }) => {
      const marker = markers.find(({ options }) => options.id === key);
      if (marker) {
        const { children, ...restProps } = props;
        L.setOptions(marker, restProps);
      }
    });

    this.leafletElement.refreshClusters(markers);
  }

I need more information on this. For me, the iconCreateFunction is still not updating it still show the same cluster icon color(but the number of the marker in the cluster is showing correctly)

@TimMcCauley
Copy link

Related #149 (comment)

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

No branches or pull requests

6 participants