Added cursor for different tools, allowed panning to work on touch while drawing
Stopped double tap to reset zoom while not on pan tool
This commit is contained in:
parent
04e4bf3f29
commit
e366d88f7e
@ -92,18 +92,18 @@ function Map({
|
|||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
function handleMove(event) {
|
function handleMove(event, isGesture) {
|
||||||
const scale = mapScaleRef.current;
|
const scale = mapScaleRef.current;
|
||||||
const translate = mapTranslateRef.current;
|
const translate = mapTranslateRef.current;
|
||||||
|
|
||||||
let newScale = scale;
|
let newScale = scale;
|
||||||
let newTranslate = translate;
|
let newTranslate = translate;
|
||||||
|
|
||||||
if (event.ds) {
|
if (isGesture) {
|
||||||
newScale = Math.max(Math.min(scale + event.ds, maxZoom), minZoom);
|
newScale = Math.max(Math.min(scale + event.ds, maxZoom), minZoom);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selectedTool === "pan") {
|
if (selectedTool === "pan" || isGesture) {
|
||||||
newTranslate = {
|
newTranslate = {
|
||||||
x: translate.x + event.dx,
|
x: translate.x + event.dx,
|
||||||
y: translate.y + event.dy,
|
y: translate.y + event.dy,
|
||||||
@ -114,20 +114,25 @@ function Map({
|
|||||||
interact(".map")
|
interact(".map")
|
||||||
.gesturable({
|
.gesturable({
|
||||||
listeners: {
|
listeners: {
|
||||||
move: handleMove,
|
move: (e) => handleMove(e, true),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.draggable({
|
.draggable({
|
||||||
inertia: true,
|
inertia: true,
|
||||||
listeners: {
|
listeners: {
|
||||||
move: handleMove,
|
move: (e) => handleMove(e, false),
|
||||||
|
},
|
||||||
|
cursorChecker: () => {
|
||||||
|
return selectedTool === "pan" && mapData ? "move" : "default";
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
interact(".map").on("doubletap", (event) => {
|
interact(".map").on("doubletap", (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
setTranslateAndScale({ x: 0, y: 0 }, 1);
|
if (selectedTool === "pan") {
|
||||||
|
setTranslateAndScale({ x: 0, y: 0 }, 1);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}, [selectedTool]);
|
}, [selectedTool, mapData]);
|
||||||
|
|
||||||
// Reset map transform when map changes
|
// Reset map transform when map changes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
Loading…
Reference in New Issue
Block a user