Fix map interaction

This commit is contained in:
Mitchell McCaffrey 2020-10-02 13:44:15 +10:00
parent f783a9bb70
commit 54a60d6c76
2 changed files with 12 additions and 8 deletions

View File

@ -89,6 +89,7 @@ function MapInteraction({
stageScale, stageScale,
setStageScale, setStageScale,
stageTranslateRef, stageTranslateRef,
selectedToolId,
preventMapInteraction, preventMapInteraction,
{ {
onPinchStart: () => { onPinchStart: () => {

View File

@ -12,6 +12,7 @@ function useStageInteraction(
stageScale, stageScale,
onStageScaleChange, onStageScaleChange,
stageTranslateRef, stageTranslateRef,
tool = "pan",
preventInteraction = false, preventInteraction = false,
gesture = {} gesture = {}
) { ) {
@ -89,14 +90,16 @@ function useStageInteraction(
const [dx, dy] = delta; const [dx, dy] = delta;
const stageTranslate = stageTranslateRef.current; const stageTranslate = stageTranslateRef.current;
const newTranslate = { if (tool === "pan") {
x: stageTranslate.x + dx / stageScale, const newTranslate = {
y: stageTranslate.y + dy / stageScale, x: stageTranslate.x + dx / stageScale,
}; y: stageTranslate.y + dy / stageScale,
layer.x(newTranslate.x); };
layer.y(newTranslate.y); layer.x(newTranslate.x);
layer.draw(); layer.y(newTranslate.y);
stageTranslateRef.current = newTranslate; layer.draw();
stageTranslateRef.current = newTranslate;
}
gesture.onDrag && gesture.onDrag(props); gesture.onDrag && gesture.onDrag(props);
}, },
}); });