Fix proxy token drop being off on different zoom factors
This commit is contained in:
parent
3c27f65d0f
commit
9bc69a18e8
@ -221,7 +221,6 @@ function Map({
|
|||||||
draggingTokenOptions.tokenState.id === b.id
|
draggingTokenOptions.tokenState.id === b.id
|
||||||
) {
|
) {
|
||||||
// If dragging token b move above
|
// If dragging token b move above
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
// Else sort so last modified is on top
|
// Else sort so last modified is on top
|
||||||
|
@ -7,6 +7,8 @@ import usePortal from "../../helpers/usePortal";
|
|||||||
|
|
||||||
import MapStageContext from "../../contexts/MapStageContext";
|
import MapStageContext from "../../contexts/MapStageContext";
|
||||||
|
|
||||||
|
import { getRelativePointerPositionNormalized } from "../../helpers/konva";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @callback onProxyDragEnd
|
* @callback onProxyDragEnd
|
||||||
* @param {boolean} isOnMap whether the token was dropped on the map
|
* @param {boolean} isOnMap whether the token was dropped on the map
|
||||||
@ -95,29 +97,10 @@ function ProxyToken({ tokenClassName, onProxyDragEnd, tokens }) {
|
|||||||
if (proxy) {
|
if (proxy) {
|
||||||
const mapStage = mapStageRef.current;
|
const mapStage = mapStageRef.current;
|
||||||
if (onProxyDragEnd && mapStage) {
|
if (onProxyDragEnd && mapStage) {
|
||||||
const mapImageRect = mapStage
|
const mapImage = mapStage.findOne("#mapImage");
|
||||||
.findOne("#mapImage")
|
const { x, y } = getRelativePointerPositionNormalized(mapImage);
|
||||||
.getClientRect();
|
|
||||||
|
|
||||||
const map = document.querySelector(".map");
|
|
||||||
const mapRect = map.getBoundingClientRect();
|
|
||||||
|
|
||||||
let x = parseFloat(proxy.getAttribute("data-x")) || 0;
|
|
||||||
let y = parseFloat(proxy.getAttribute("data-y")) || 0;
|
|
||||||
|
|
||||||
// TODO: This seems to be wrong when map is zoomed
|
|
||||||
|
|
||||||
// Convert coordiantes to be relative to the map
|
|
||||||
x = x - mapRect.left - mapImageRect.x;
|
|
||||||
y = y - mapRect.top - mapImageRect.y;
|
|
||||||
|
|
||||||
// Normalize to map width
|
|
||||||
x = x / mapImageRect.width;
|
|
||||||
y = y / mapImageRect.height;
|
|
||||||
|
|
||||||
// Get the token from the supplied tokens if it exists
|
// Get the token from the supplied tokens if it exists
|
||||||
const token = tokensRef.current[id] || {};
|
const token = tokensRef.current[id] || {};
|
||||||
|
|
||||||
onProxyDragEnd(proxyOnMap.current, {
|
onProxyDragEnd(proxyOnMap.current, {
|
||||||
...token,
|
...token,
|
||||||
x,
|
x,
|
||||||
@ -153,6 +136,7 @@ function ProxyToken({ tokenClassName, onProxyDragEnd, tokens }) {
|
|||||||
left: 0,
|
left: 0,
|
||||||
bottom: 0,
|
bottom: 0,
|
||||||
right: 0,
|
right: 0,
|
||||||
|
pointerEvents: "none",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Box
|
<Box
|
||||||
|
Loading…
Reference in New Issue
Block a user