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

fix: on React, load marker images before adding layers #966

Merged
merged 1 commit into from
Oct 7, 2023

Conversation

rudokemper
Copy link
Member

Resolves #965.

In the Map component, this PR refactors the this.map.on("load") event to prioritize loading the marker images before adding the Terrastories point data and layers. This approach addresses a race condition where the layers might sometimes be added to the map before the marker images had fully loaded.

To improve code clarity, I've also extracted the layer addition logic into its own function, addPlaceMarkerLayers().

Before:

image

After:
image

In so doing, the following warnings in the console have also gone away:

mapbox-gl.js:31 Image "ts-marker" could not be loaded. Please make sure you have added the image with map.addImage() or a "sprite" property in your style. You can provide missing images by listening for the "styleimagemissing" map event.
mapbox-gl.js:31 Image "ts-marker-cluster" could not be loaded. Please make sure you have added the image with map.addImage() or a "sprite" property in your style. You can provide missing images by listening for the "styleimagemissing" map event.

@rudokemper
Copy link
Member Author

@lauramosher I know our goal is to eventually switch over to the Explore UI which does not have this issue, but hoping this could work as a temporary resolution. This race condition issue shows up every time for some of our online users and it's not great when they're doing a demo.

@lauramosher lauramosher merged commit 949df8a into master Oct 7, 2023
@rudokemper rudokemper deleted the load-marker-images-before-layers-react branch November 7, 2023 02:01
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

Successfully merging this pull request may close these issues.

[Bug][React] Race condition issue: map marker layers added to map before image is loaded
2 participants