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

[Feat] Custom map.querySourceFeatues Renderer #2348

Open
JaeSeoKim opened this issue Jan 24, 2024 · 2 comments
Open

[Feat] Custom map.querySourceFeatues Renderer #2348

JaeSeoKim opened this issue Jan 24, 2024 · 2 comments
Labels

Comments

@JaeSeoKim
Copy link

JaeSeoKim commented Jan 24, 2024

Target Use Case

This feature is allows you to render content received via the querySourceFeatues function without worrying about React's lifecycle.

Example

Display HTML clusters with custom properties

Proposal

The QuerySourceFeatures (temporary name) component receives the arguments of the querySourceFeatures function, and additionally the target component that should be rendered via render.

Internally, the component references events for data, move, and moveend, and renders through the passed in render if any data has changed.

Here's example code to use

<QuerySourceFeatures
  source="earthquakes"
  filter={["==", "cluster", true]}
  render={({ data }) => {
    <Marker
      longitude={data.geometry.coordinates[0]}
      latitude={data.geometry.coordinates[1]}
    >
      <DonutChart properties={data.properties!} />
    </Marker>
  }}
/>

I've written POC code in the following repo.

If you think it's a good idea to add these features, please review them for further improvements and I'll write a PR.

Otherwise I'll PR that POC code as an example.

@JaeSeoKim JaeSeoKim changed the title [Feat] Custom map.querySourceFeatues data Renderer [Feat] Custom map.querySourceFeatues Renderer Jan 24, 2024
@Jdyn
Copy link

Jdyn commented Feb 10, 2024

+1 Since I recently implemented this exact use case and your implementation looks pretty sound.

I am curious if you noticed any tangible benefits using flushSync and useLayoutEffect since I implemented this originally with just setState and useEffect and it works identically from what my eyes can see, although I was using a small set of features.

@JaeSeoKim
Copy link
Author

@Jdyn In fact, in the case of useLayoutEffect, it is said to work before browser paint, but I am not sure if it will work in this case as well. 😅
However, with flushSync, React's State update doesn't work synchronously, so if you don't use that logic, you can quickly move the screen and zoom in and out, you'll see the component partially delayed and rendered.

It will help you understand if you refer to the official document

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

No branches or pull requests

2 participants