Skip to content

Commit

Permalink
Фикс перетаскивания точек (#21)
Browse files Browse the repository at this point in the history
* drag event fix
  • Loading branch information
itanka9 authored Nov 1, 2022
1 parent 7d2fcbe commit 143b1f7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/joint.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { GeoPoint, TargetedEvent } from './types';
import { createHtmlMarker, getJointDistanceText, getLabelHtml, getMarkerPopupHtml } from './utils';
import {
createHtmlMarker,
getJointDistanceText,
getLabelHtml,
getMarkerPopupHtml,
getMousePosition,
} from './utils';
import { Evented } from './evented';
import { style } from './style';

Expand Down Expand Up @@ -205,7 +211,9 @@ export class Joint extends Evented<EventTable> {

this.emit('move', { targetData: this });

this.coordinates = this.map.unproject([ev.clientX, ev.clientY]);
const container = this.map.getContainer();

this.coordinates = this.map.unproject(getMousePosition(container, ev.clientX, ev.clientY));
this.marker?.setCoordinates(this.coordinates);
};

Expand Down
9 changes: 9 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,12 @@ export function getSnapPoint(map: mapgl.Map, joints: Joint[], point: ScreenPoint

return { point: geoPoint, distance, segment: bestSegmentIndex };
}

export function getMousePosition(
container: HTMLElement,
clientX: number,
clientY: number,
): number[] {
const rect = container.getBoundingClientRect();
return [clientX - rect.left - container.clientLeft, clientY - rect.top - container.clientTop];
}

0 comments on commit 143b1f7

Please sign in to comment.