-
-
Notifications
You must be signed in to change notification settings - Fork 819
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
[Bug]: Sibling MarkerViews not observing zIndex style property #3456
Comments
We're observing the same behavior. We have map markers that are loaded in batches, and we want the markers from later batches to show below the markers from earlier batches. We are both sorting the markers array each time a new batch comes in and also adding a |
@jgregory-apogee marker views are based on Mapbox view annotation. There order is based on selected is top on non selected, otherwise views added later are top of views added earlier. RN zIndex will not have affect on this. |
Thanks for the quick response, @mfazekas! I was hoping that pushing markers to the end of the list of I will keep trying things, and I appreciate the help! |
If anyone else is hitting this issue, I was able to work around it by briefly foiling the const MapMarkers = ({ data }) => {
const markers = useMemo(() => {
return data.map((d) => ({
id: d.id,
coords: d.coords,
zIndex: getZIndex(d),
})
.sort((a, b) => a.zIndex - b.zIndex);
}, [data]);
const [shouldBustMarkerMemos, setShouldBustMarkerMemos] = useState(false);
useEffect(() => {
setShouldBustMarkerMemos(true);
setTimeout(() => setShouldBustMarkerMemos(false), 0);
}, [data]);
return sortedMarkers.map((marker) => {
return (
<MarkerView
key={shouldBustMarkerMemos ? `${Math.random()}` : marker.id}
id={marker.id}
coordinate={marker.coords}
>
...
</MarkerView>
);
});
} |
Mapbox Implementation
Mapbox
Mapbox Version
10.7.0
React Native Version
0.73.7
Platform
Android
@rnmapbox/maps
version10.1.19
Standalone component to reproduce
Observed behavior and steps to reproduce
MarkerViews are not affected by the
zIndex
property passed in as a style prop. Therefore it does not seem possible to set a desired order to sibling MarkerView components. As a result the MarkerView that appears on top is the Marker that is closest to the closing</MapView>
.Expected behavior
I would expect
<MarkerBlue />
to appear on top if it'szIndex
is set higher than thezIndex
of<MarkerRed />
Notes / preliminary analysis
Because of this behaviour it does not appear to be possible to programmatically set the order of sibling MarkerViews.
For example the coordinate value for one of the markers may depend on an value becoming available which creates a race condition and may result in it getting put on top regardless of its position within a MapView.
E.g. the blue marker here may not have userLocation available immediately. So when it becomes available it will appear on top of the red marker.
This makes it hard to maintain the desired order of overlapping MarkerViews.
Additional links and references
N/a
The text was updated successfully, but these errors were encountered: