UNPKG

s2maps-gpu

Version:

S2 Maps GPU - An open source, high-performance, and GPU-accelerated map engine for rendering large-scale, interactive maps.

80 lines (79 loc) 2.36 kB
/** An interface that models the user touch event items we are interested in */ export interface UserTouchEvent { length: number; [key: number]: { clientX: number; clientY: number; x: number; y: number; }; } /** An interface that models the click event items we are interested in */ export interface ClickEvent { detail: { posX: number; posY: number; }; } /** * # DragPan * * ## Description * DragPan is a class that handles mouse and touch events for panning and zooming * * ## Example * ```ts * const dragPan = new DragPan() * dragPan.addEventListener('move', () => { * console.info(dragPan.movementX, dragPan.movementY) * }) * ``` */ export default class DragPan extends EventTarget { #private; zoomActive: boolean; mouseActive: boolean; minMovementX: number; minMovementY: number; movementX: number; movementY: number; totalMovementX: number; totalMovementY: number; touchDeltaX: number; touchDeltaY: number; touchDeltaZ: number; clickEvent: null | ReturnType<typeof setTimeout>; zoom: number; /** Clears all previous movement and zoom changes */ clear(): void; /** * Beginning of a touch event, user has just touched the screen * @param touches - collection of touch events */ onTouchStart(touches: UserTouchEvent): void; /** * User has let go, we don't know if it was a swipe, a click, or a double click * @param touches - collection of touch events */ onTouchEnd(touches: UserTouchEvent): void; /** User is using a mouse and just clicked */ onMouseDown(): void; /** * User has let go of the left mouse button * @param posX - x position of the click * @param posY - y position of the click */ onMouseUp(posX?: number, posY?: number): void; /** * tracks movement if the left click actively pressed * or it tracks what features are currently active * @param movementX - the change in x position * @param movementY - the change in y position */ onMouseMove(movementX: number, movementY: number): void; /** * User is using a touch screen and is actively moving their finger(s) * @param touches - collection of touch events */ onTouchMove(touches: UserTouchEvent): void; }