-
-
Notifications
You must be signed in to change notification settings - Fork 846
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
Can't press ShapeSource on top of UserLocation #241
Comments
@mfazekas can you experience the same behaviour ? I can see on ShapeSource.md that
And I can see that UserLocation is an Annotation, and Annotation is a ShapeSource, so does it mean that we should give a low z-index to |
Having the same issue, was this fixed? |
No fix for now |
Workaround can be to put a transparent layer on top of the layer in the shape source with a higher index than user location. We could accept a PR with a prop on UserLocation that disables the on press listener, but I honestly feel like this is a very narrow usecase with a functional workaround. |
Hi @kristfal So I don't see how to proceed ! If you have one more clue it would be really nice... |
@kristfal I don't think this is a narrow usecase... If anyone has custom markers rendered (think of the earthquake example) which are clickable, none can be clicked if they are within a 1inch by 1inch square of UserLocation... |
@kristfal I need to move forward on the subject now, this is becoming critical to me... a help would be great if possible !
Thanks ! |
Alright, with a proper utilisation of import React from 'react';
import MapboxGL from '@react-native-mapbox-gl/maps';
import { withTheme } from 'styled-components';
const layerStyles = (circleColor) => ({
pluse: {
circleRadius: 15,
circleColor,
circleOpacity: 0.2,
circlePitchAlignment: 'map',
},
background: {
circleRadius: 9,
circleColor: '#fff',
circlePitchAlignment: 'map',
},
foreground: {
circleRadius: 6,
circleColor,
circlePitchAlignment: 'map',
},
});
const MyUserLocation = ({ theme: { color: { primary } } }) =>
<MapboxGL.UserLocation
visible
animated
>
<MapboxGL.CircleLayer
key="mapboxUserLocationPluseCircle"
id="mapboxUserLocationPluseCircle"
belowLayerID='markersSymbol'
style={layerStyles(primary).pluse}
/>
<MapboxGL.CircleLayer
key="mapboxUserLocationWhiteCircle"
id="mapboxUserLocationWhiteCircle"
belowLayerID='markersSymbol'
style={layerStyles(primary).background}
/>
<MapboxGL.CircleLayer
key="mapboxUserLocationBlueCicle"
id="mapboxUserLocationBlueCicle"
belowLayerID='markersSymbol'
aboveLayerID="mapboxUserLocationWhiteCircle"
style={layerStyles(primary).foreground}
/>
</MapboxGL.UserLocation>
export default withTheme(MyUserLocation) |
@arnaudambro I'm not entirely following your solution - how would you apply that to my code below?
|
Can you provide the whole code, markers + user-location so that I can test myself ? |
@arnaudambro Thank you very much for your help! I'm getting a step closer to what i'm looking for. With your solution, user is hidden below the symbol so it can not be seen. What I'm trying to do is to have user on the top of the symbol but the user layer not capturing onPress event that way the layer of the symbol could catch the onPress event. For know I did set a pulse circleRadius larger than my symbol that way the user can still guess where he is located on the map by seeing a part of the pulse circle. Bad UX but better than seeing nothing 😄 |
@arnaudambro see #534 (comment) ;) |
Hey guys! |
There's a known issue with rnmapbox where the blue userlocation circle prevents taps on nearby location markers. The recommended workaround is to override the default userlocation component and define a relevant belowLayerID (in our case, sitesLayer). rnmapbox/maps#241
There's a known issue with rnmapbox where the blue userlocation circle prevents taps on nearby location markers. The recommended workaround is to override the default userlocation component and define a relevant belowLayerID (in our case, sitesLayer). rnmapbox/maps#241
* feat: clear search input #436 * feat: override mapbox userlocation with custom userlocation There's a known issue with rnmapbox where the blue userlocation circle prevents taps on nearby location markers. The recommended workaround is to override the default userlocation component and define a relevant belowLayerID (in our case, sitesLayer). rnmapbox/maps#241 * fix: file cleanup * feat: don't open a second popover when tapping out * fix: allow taps through mapsearch component * feat: allow site creation by tapping on user location Mapbox's default UserLocation onPress handler doesn't have a defined return type, but it does return properties we can conditionally pass through to the existing SiteMap onPress handler. This allows users to open a location popover by tapping on their location if no sites already exist.
That would be really cool to have a prop for this. I don't think I have the skills to implement it - but I wish. |
Actually, using renderMode={'native'} seems to resolve this issue in iOS. However, it appears that @mfazekas is going to deprecate that soon. |
As a workaround I've used something like this to handle my use case: async function handleLocationPress() {
const currentLocation = []; // you current location position (GeoJSON.Position)
const screenCoordinates = await mapRef.current?.getPointInView(currentLocation);
const screenPointFeature = feature(
{
type: 'Point',
coordinates: currentLocation
},
{
screenPointX: screenCoordinates?.[0] || 0,
screenPointY: screenCoordinates?.[1] || 0
}
);
handlePress(screenPointFeature);
}
async function handlePress(feature) {
const { screenPointX, screenPointY } = feature.properties;
// Note this only works for the following layers: SymbolLayer, CircleLayer, LineLayer, and FillLayer
const featureCollection = await mapRef.current?.queryRenderedFeaturesAtPoint(
[screenPointX, screenPointY],
null,
[
...layerIdsToQueryOn // string[]
]
);
return featureCollection;
}
// Use
<Mapbox.MapView
ref={mapRef}
style={{ flex: 1 }}
onPress={handlePress}
>
<UserLocation
ref={userLocationRef}
onUpdate={handleUserLocationUpdate}
minDisplacement={1}
animated
visible={locationVisible}
onPress={handleLocationPress}
/>
{/* Whatever else ShapeSources and content below */}
</Mapbox.MapView> |
Hello,
I have a
SymbolLayer
located underneath theUserLocation
, and I wish theSymbolLayer
to be pressable.But it seems it can't be done: when I press the icon, it is actually the
UserLocation
which is pressed, and theUserLocation
onPress
event doesn't have any argument and doesn't have apointerEvents
prop or equivalent.Is there a way to get to the
SymbolLayer
?Again, great repo, and greater to become, thanks all for the work done !
The text was updated successfully, but these errors were encountered: