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

Forward className and style to div.mapboxgl-marker element in Marker component #335

Open
kaitlynbrown opened this issue Jul 15, 2021 · 0 comments

Comments

@kaitlynbrown
Copy link

Is your feature request related to a problem? Please describe.
I would like to add a z-index to certain markers on my map to ensure they show up in front of other markers that might be overlapping. The normal way to do this would be to add either a css class or inline style on the div containers for those markers. However, because neither className nor style is forwarded to the div that contains the marker contents, this isn't currently possible to do.

Describe the solution you'd like
Forward className and style to div.mapboxgl-marker

Describe alternatives you've considered
I'm using the following (very hacky) code to add a className to the marker containers after the map has loaded, but this isn't reliable, because there are many things that can happen to cause the class to be removed:

  useEffect(() => {
    // HACK: There doesn't seem to be any react-friendly way to add css classes or styles to Marker elements
    if (!unclusteredClinics?.length) {
      return;
    }
    const interval = setInterval(() => {
      const unclusteredElements = document.querySelectorAll(
        '.clinic-marker-unclustered'
      );
      if (!unclusteredElements.length) {
        return;
      }
      unclusteredElements.forEach(el =>
        el.parentElement.classList.add('clinic-marker-unclustered-container')
      );
      clearInterval(interval);
    }, 50);
  }, [clinics]);
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

No branches or pull requests

1 participant