-
-
Notifications
You must be signed in to change notification settings - Fork 857
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
setCamera doesn't take effect if followUserLocation set to true #1079
Comments
inspecting the code i've found following
wouldn't it make sense to at least provide possibility to pass |
hey @nasmuris, sounds reasonable to me - would you be willing to open a PR for this? |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
I'd say this is a particularly important feature right now because in order for UserLocation renderMode to be native on android, Camera followUserLocation must be true, but if followUserLocation is true, setCamera can't be used! Can we reopen? |
Right, I believe that is the current status on setCamera. I'm wondering if we can get it consistent with how the iOS version works? |
I'll reopen this - and yes, would be great if someone could take a jab at this. |
as a workaround for not being able to use
|
Same issue here, as a workaround could you please give an example how to use these attributes ?, I have navigation mode map which use followUserLocation, if user moved the map and clicked on center button I want to get back to current location. @ferdicus |
Not sure if this would help in your case, but I currently set import React, {useState, useEffect, useRef} from 'react';
import {Platform, View} from 'react-native';
import MapboxGL from '@react-native-mapbox-gl/maps';
...
export default function MapScreen(props) {
const cameraRef = useRef();
const [followUser, setFollowUser] = useState(Platform.OS === 'android');
useEffect(() => {
if (!followUser && cameraRef?.current) {
cameraRef.current.moveTo([-3.0886, 54.539627], 300);
}
}, [followUser]);
return (
<View style={styles.container}>
<MapboxGL.MapView
style={styles.map}
styleURL={STYLE_URL}
onDidFinishLoadingStyle={() => {
if (followUser) {
// Required for Android heading indicator,
// triggers effect to focus camera on init values
setFollowUser(false);
}
}}>
<MapboxGL.Camera
ref={cameraRef}
// native for Android, only works if followUserLocation set to true
followUserLocation={followUser}
zoomLevel={11}
centerCoordinate={[-3.0886, 54.539627]}
animationMode={'flyTo'}
animationDuration={1900}
/>
<MapboxGL.UserLocation
visible={true}
renderMode={'native'}
// Android indicator set via androidRenderMode
showsUserHeadingIndicator={Platform.OS === 'ios'}
// native/android only render mode (compass: triangle with heading)
androidRenderMode={'compass'}
/>
</MapboxGL.MapView>
</View>
);
} |
This is not an issue - please refer to the gitter chat/ stackoverflow or Discussions for usage advise |
@ferdicus Sorry for being unable to reply for such a long time, but this bug/feature had low prio for my project and I haven't had enought time to dig into this in my free time... |
Same problem here. I'm trying to change the pitch based on the navigation mode but the problem is that when the user location updates at the same time the camera's animation stops. |
This also seem to affect camera.flyTo as well as changing the centerCoordinate dynamically using a state. When followUserLocation is set to true, both dont work, but if false, it works fine. |
@gokugen - did you try |
@ferdicus yes even with |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Hi stale bot, so in your mind, things without activity are fixed? Robots... |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Activity is happening. |
is there a workaround for this yet? I can't have followUser but also flyTo? |
Also experiencing this and a solution in the api would be much appreciated (something like the const [coordinates, setCoordinates] = useState<Coordinates>(null)
const [followUserLocation, setFollowUserLocation] = useState<boolean>(true)
const flyTo = (coordinates: Coordinates) => {
setFollowUserLocation(false)
setCoordinates(coordinates)
}
useEffect(() => {
if (!followUserLocation && coordinates) {
cameraRef.current.flyTo(coordinates)
}
}, [followUserLocation, coordinates])
... |
Has anybody been able to find a solution to this issue? I’m having it on Android (only when targeting Android 12 for some reason). Same code working on iOS without issues even if followUserLocation is set to true. My environment: |
Activity is happening |
I understand that you people might think that it doesn't make sense to allow a setCamera, moveTo or flyTo operation to be performed when the user wants the map to follow location, but there are a bunch of cases where you wanna change some camera properties without the need to turn off followUserLocation, just to turn it back on once the camera change has been performed. Plus, on iOS, this is not happening, and PLEASE don't change that 😅. I mean, I might want to change the zoom, the pinch and other properties, and I cannot do anything like that without this on/off, which sucks because I need to trigger a rerender uselessly... Are you sure it makes sense to keep it that way? |
@whiteHatCip But it's not clear how Zoom, pitch etc can be changed with changing |
The problem is that I start my application with the followUserLocation set to true, then the new coordinates for the current location arrive, but the camera doesn't move on it's own to the current location, and specifically with the desired zoom level, to say one example. This thing is not a problem on iOS, why should it be on Android? |
Agreeing with @whiteHatCip here. In order to achieve a moveTo if followUserLocation is set to true we have to use this workaround: #1079 (comment) |
@steffenkleinle If I may add another consideration about the workaround, you have to always make sure that the condition to perform the move/fly to coordinates is always correct, meaning that if you don't want to flit, you have to make sure that in the #1079 (comment) workaround the |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Describe the bug
setCamera doesn't take effect if followUserLocation set to true
To Reproduce
set Camera's component
followUserLocation
prop to true and try to callsetCamera
on it's refExample:
Expected behavior
it should be possible to setCamera or at least some of it's props in case followUserLocation===true
while i see there can be some conflict updating the coords (which one should be prioritized?) at least zoomLevel, pitch and rotation should be just fine
Screenshots
Versions (please complete the following information):
The text was updated successfully, but these errors were encountered: