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

[10.0.0-alpha.5] _cameraRef?.current?.setCamera causing markerpoint get detached from maps-base #409

Open
ngdbao opened this issue Jun 18, 2024 · 10 comments
Labels
bug Something isn't working
Milestone

Comments

@ngdbao
Copy link

ngdbao commented Jun 18, 2024

<MapLibreGL.MapView
    ref={_mapRef}
    style={mapStyle}
    styleURL={mapStyleUrl}
    zoomEnabled={true}
    logoEnabled={false}
    compassEnabled={false}
    attributionEnabled={true}
    attributionPosition={{ bottom: getSize.m(8), left: getSize.m(8) }}
    pitchEnabled
    rotateEnabled
    compassViewPosition={2}
    onDidFinishLoadingMap={handleMapLoaded}>
    <MapLibreGL.Camera
        ref={_cameraRef}
        defaultSettings={{
            bounds: boundingBox,
        }}
        followUserLocation={showMyLocation}
        followUserMode={'normal'}
        followZoomLevel={13}
    />
    <MapLibreGL.UserLocation
        renderMode={Platform.OS === 'ios' ? 'normal' : 'native'}
        showsUserHeadingIndicator={true}
        visible={showMyLocation}
    />

    {renderMarkerPoint}
    {renderUnSelectedMarkerPoint}
    {renderSelectedMarkerPoint}
</MapLibreGL.MapView>

context:

{renderMarkerPoint}
{renderUnSelectedMarkerPoint}
{renderSelectedMarkerPoint}

are using

MapLibreGL.PointAnnotation
MapLibreGL.ShapeSource
MapLibreGL.LineLayer

tap on any of them, would trigger this function to move camera (which triggered by onSelected prop)

    const onChangeViewCamera = React.useCallback(({ lon, lat }) => {
        console.log('Moving camera to: ', lon, lat);
        _cameraRef?.current?.setCamera({
            centerCoordinate: [lon, lat],
            animationDuration: 800,
            animationMode: 'flyTo',
            zoomLevel: 14,
            padding: handlePadding(getSize.m(30)),
        });
    }, []);

Expected Behavior

Everything works well on v8 or v9 as normal, just move camera only when tapping markers

Actual Behavior

On pre-release version v10
all of markers, and camera view get detached from map base, please take a look on this video:

RPReplay_Final1718697445.mp4

Version(s) affected

  • Platform: [Android, iOS]
  • maplibre-react-native Version [10.0.0-alpha.5]
  • React Native Version [0.72.10]
@Adham2023
Copy link

Did you fix the issue? @ngdbao

@ngdbao
Copy link
Author

ngdbao commented Jul 2, 2024

Did you fix the issue? @ngdbao

sadly, not yet :)

@mohanedmoh
Copy link

can you share the code used for adding the markers or the vector layer

@ngdbao
Copy link
Author

ngdbao commented Jul 8, 2024

can you share the code used for adding the markers or the vector layer

it's simply a PointAnnotation with prop draggable false, wrapping a raw react native component children

@caspg
Copy link
Contributor

caspg commented Jul 12, 2024

@ngdbao Could you show more code? Maybe some small example which will help us reproduce error? Especially code related to adding your markers.

@ngdbao
Copy link
Author

ngdbao commented Jul 18, 2024

Hi, I renderred the markerpoint by Pointannotation geo coordinate and anchor like this:

    const renderMarkerPoint = useMemo(
        () =>
            dataCheckpointWithKeyid?.map((mark, index) => {
                return viewMapLoaded ? (
                    <MarkerPoint
                        key={`${(index || -1) + 1}`}
                        index={index}
                        item={mark}
                        onPressChangePoint={onPressChangePoint}
                        // onChangeViewCamera={onChangeViewCamera}
                        isLastItem={index === dataCheckpointWithKeyid.length - 1}
                        isFirstItem={index === 0}
                    />
                ) : null;
            }),
        [dataCheckpointWithKeyid, viewMapLoaded],
    );
const MarkerPoint = ({
    item,
    index,
    onPressChangePoint,
    isLastItem,
    isFirstItem,
}) => {
    const [imageLoaded, setImageLoaded] = useState(false);
    const markerRef = useRef<any>(null);

    const id = String(index);
    const handleOnLoad = useCallback(() => {
        Platform.OS === 'android' ? setImageLoaded(true) : null;
    }, []);

    useEffect(() => {
        if (imageLoaded) {
            markerRef?.current?.refresh();
            console.log(`====Image ${index} refresh====`);
        }
    }, [imageLoaded]);

    const handleSelected = useCallback(() => {
        onPressChangePoint?.(index);
    }, [index, onPressChangePoint]);

    const anchor = useMemo(() => {
        return isLastItem ? { x: 0.5, y: 0.4 } : isFirstItem ? { x: 0.5, y: 1 } : { x: 0.46, y: 0.21 };
    }, [isFirstItem, isLastItem]);

    const MapCheckPoint = (
        <MapLibreGL.PointAnnotation
            key={id}
            ref={markerRef}
            id={id}
            anchor={anchor}
            coordinate={[item?.geo?.lon || 0, item?.geo?.lat || 0]}
            draggable={false}
            onSelected={handleSelected}>
            <View style={stylesCallout.checkpointContainer}>
                <View style={stylesCallout.container}>
                    <View style={stylesCallout.content}>
                        <AppImage
                            disabled={true}
                            url={item?.images}
                            defaultSource={CHECKPOINT_ICON}
                            style={stylesCallout.startImage}
                            onLoad={handleOnLoad}
                            shouldLoading
                            resizeMode="cover"
                        />
                        <AppText style={stylesCallout.textStart}>{MapDefaultText.START || ''}</AppText>
                        <AppText numberOfLines={1} style={stylesCallout.locationStart}>
                            {truncateText(item?.location, 25) || ''}
                        </AppText>
                    </View>
                </View>
            </View>
        </MapLibreGL.PointAnnotation>
    );

    return MapCheckPoint;
};

MarkerPoint.propTypes = {
    item: PropTypes.any,
    index: PropTypes.number,
    onPressChangePoint: PropTypes.func,
    isLastItem: PropTypes.bool,
    isFirstItem: PropTypes.bool,
    onChangeViewCamera: PropTypes.func,
    viewMapLoaded: PropTypes.bool,
};

export default React.memo(MarkerPoint);

only PointAnnotation, but ShapeSource or LineLayer works fine

@brentforder
Copy link

I'm having a similar issue with PointAnnotation being detached from the basemap coordinates, but only on iOS. On Android, my PointAnnotations work wonderfully. On iOS, they are all stuck at the top-left (0,0) view coordinates of the MapView.

I've determined that the coordinate properties of the PointAnnotations are correctly being set with valid geographic coordinates.
I'm exploring the idea of migrating from PointAnnotation to ShapeSource and SymbolLayer... But this is quite painful. As far as I can tell, PointAnnotation simply does not work on iOS.

I'm on the bleeding edge, with 10.0.0-alpha.10 and I've customized the iOS Podfile to work with the latest MapLibre Native 6.5.4.
If anyone can point me to maplibre-react-native versions where PointAnnotation is definitely working on iOS, I would appreciate it.

@KiwiKilian
Copy link
Collaborator

KiwiKilian commented Nov 14, 2024

Is anyone still seeing such problems with 10.0.0-alpha.25? I'm using MapLibreGL.PointAnnotation successfully, even with drag and drop. When setCamera is called, it stays put where it should be.

@brentforder
Copy link

Is anyone still seeing such problems with 10.0.0-alpha.25? I'm using MapLibreGL.PointAnnotation successfully, even with drag and drop. When setCamera is called, it stays put where it should be.

In my testing with 10.0.0-alpha.25, PointAnnotation is now actually being positioned properly at geographic coordinates on iOS! That's progress!
Unfortunately, dragging is only working for me with PointAnnotation on Android.
On iOS:

  • PointAnnotation.draggable property doesn't work to enable dragging.
  • PointAnnotation.onDrag(), onDragStart() etc. do not fire.

@KiwiKilian
Copy link
Collaborator

Will need a reproduction. It's working in our app:

ScreenRecording_11-14-2024.19-21-58_1.mp4

@KiwiKilian KiwiKilian added this to the 10.0.0 milestone Nov 15, 2024
@KiwiKilian KiwiKilian added the bug Something isn't working label Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants