react-mapbox-gl icon indicating copy to clipboard operation
react-mapbox-gl copied to clipboard

touchZoomRotate only disable rotation toggle

Open mtthsnc opened this issue 3 years ago • 1 comments

From MapBox documentation it is possible to disable rotation when users zoom on mobile through:

map.touchZoomRotate.disableRotation()

But in react-mapbox-gl there's no option to only disable rotation when zooming on mobile. When touchZoomRotate is set to false it disables both zoom and rotate, which makes the option quite redundant.

This is my current factory parameters:

const ReactMap = Mapbox({
	accessToken: process.env.MAPBOX_ACCESS_TOKEN,
	minZoom: 5.75,
	maxZoom: 16.25,
	dragRotate: false,
	doubleClickZoom: false,
	pitchWithRotate: false,
	touchZoomRotate: false
});

mtthsnc avatar Dec 07 '21 15:12 mtthsnc

bumping this as I'm also looking for a solution to the same problem

pkwanseraitrade avatar Dec 24 '21 05:12 pkwanseraitrade

Me too. I would like to have an option where I can prevent rotation on a mobile device, but still allow zooming.

chinnaxs avatar Dec 25 '22 09:12 chinnaxs

I solved this by directly referring to the map:

import React, { useState, useEffect, useRef, useCallback } from "react";

const mapRef = useRef(null);

const onMapLoad = useCallback(()  => {
      const map = mapRef.current.getMap()
      //turn off option to rotate map with SHIFT+Cursor
      map.keyboard.disableRotation()
      map.touchZoomRotate.disableRotation()
  }, []);

...

            <Map mapboxAccessToken={XXXXXXX}
                ref={mapRef}
                initialViewState={{
                  longitude: 13,
                  latitude: 47,
                  zoom: 9.5,
                }}
                onClick={onClick}
                onMouseEnter={onMouseEnter}
                onMouseLeave={onMouseLeave}
                onLoad={onMapLoad}
                mapStyle="mapbox://styles/mapbox/streets-v12"
                touchZoomRotate={true}
                touchPitch={false}
                dragRotate={false}
            >

gregholst avatar Jan 06 '23 10:01 gregholst

Thanks @gregholst I just recently came back to an issue similar to this and can indeed confirm it works as intended 👍

mtthsnc avatar Nov 28 '23 18:11 mtthsnc

However, a prop integrated with the package would still be appreciated!

mtthsnc avatar Nov 28 '23 18:11 mtthsnc

Hey @omattman @gregholst can we prevent rotation but still allow zoom in and zoom out in map? I tried setting up touchZoomRotate as false but it prevents both rotation and zooming in map. I want to disable the rotation only.

anjaliD-syn avatar Jan 17 '24 12:01 anjaliD-syn

@anjaliD-syn try these properties, they work for me:

touchZoomRotate={true}
touchPitch={false}
dragRotate={false}

gregholst avatar Jan 21 '24 18:01 gregholst

@gregholst Thanks for your reply. I tried your suggestion but no luck :(. With above config it still allows to rotate on mobile screens.

anjaliD-syn avatar Jan 24 '24 05:01 anjaliD-syn

@anjaliD-syn that is strange, for me rotation with fingers is not possible on my mobile phone (Android / Firefox). However, I can't see any other property that seems related. What version of react-map-gl do you use, just trying to find the difference...my package.json says: "react-map-gl": "^7.0.25"

gregholst avatar Jan 24 '24 19:01 gregholst