Named exports from ol/interaction/Pointer
This commit is contained in:
@@ -7,7 +7,7 @@ import {scale as scaleCoordinate, rotate as rotateCoordinate, add as addCoordina
|
|||||||
import {easeOut} from '../easing.js';
|
import {easeOut} from '../easing.js';
|
||||||
import {noModifierKeys} from '../events/condition.js';
|
import {noModifierKeys} from '../events/condition.js';
|
||||||
import {FALSE} from '../functions.js';
|
import {FALSE} from '../functions.js';
|
||||||
import PointerInteraction from '../interaction/Pointer.js';
|
import PointerInteraction, {centroid as centroidFromPointers} from '../interaction/Pointer.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @classdesc
|
* @classdesc
|
||||||
@@ -67,7 +67,7 @@ inherits(DragPan, PointerInteraction);
|
|||||||
*/
|
*/
|
||||||
function handleDragEvent(mapBrowserEvent) {
|
function handleDragEvent(mapBrowserEvent) {
|
||||||
const targetPointers = this.targetPointers;
|
const targetPointers = this.targetPointers;
|
||||||
const centroid = PointerInteraction.centroid(targetPointers);
|
const centroid = centroidFromPointers(targetPointers);
|
||||||
if (targetPointers.length == this.lastPointersCount_) {
|
if (targetPointers.length == this.lastPointersCount_) {
|
||||||
if (this.kinetic_) {
|
if (this.kinetic_) {
|
||||||
this.kinetic_.update(centroid[0], centroid[1]);
|
this.kinetic_.update(centroid[0], centroid[1]);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import {inherits} from '../index.js';
|
|||||||
import ViewHint from '../ViewHint.js';
|
import ViewHint from '../ViewHint.js';
|
||||||
import {FALSE} from '../functions.js';
|
import {FALSE} from '../functions.js';
|
||||||
import Interaction from '../interaction/Interaction.js';
|
import Interaction from '../interaction/Interaction.js';
|
||||||
import PointerInteraction from '../interaction/Pointer.js';
|
import PointerInteraction, {centroid as centroidFromPointers} from '../interaction/Pointer.js';
|
||||||
import {disable} from '../rotationconstraint.js';
|
import {disable} from '../rotationconstraint.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -105,7 +105,7 @@ function handleDragEvent(mapBrowserEvent) {
|
|||||||
// FIXME: should be the intersection point between the lines:
|
// FIXME: should be the intersection point between the lines:
|
||||||
// touch0,touch1 and previousTouch0,previousTouch1
|
// touch0,touch1 and previousTouch0,previousTouch1
|
||||||
const viewportPosition = map.getViewport().getBoundingClientRect();
|
const viewportPosition = map.getViewport().getBoundingClientRect();
|
||||||
const centroid = PointerInteraction.centroid(this.targetPointers);
|
const centroid = centroidFromPointers(this.targetPointers);
|
||||||
centroid[0] -= viewportPosition.left;
|
centroid[0] -= viewportPosition.left;
|
||||||
centroid[1] -= viewportPosition.top;
|
centroid[1] -= viewportPosition.top;
|
||||||
this.anchor_ = map.getCoordinateFromPixel(centroid);
|
this.anchor_ = map.getCoordinateFromPixel(centroid);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import {inherits} from '../index.js';
|
|||||||
import ViewHint from '../ViewHint.js';
|
import ViewHint from '../ViewHint.js';
|
||||||
import {FALSE} from '../functions.js';
|
import {FALSE} from '../functions.js';
|
||||||
import Interaction from '../interaction/Interaction.js';
|
import Interaction from '../interaction/Interaction.js';
|
||||||
import PointerInteraction from '../interaction/Pointer.js';
|
import PointerInteraction, {centroid as centroidFromPointers} from '../interaction/Pointer.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @classdesc
|
* @classdesc
|
||||||
@@ -103,7 +103,7 @@ function handleDragEvent(mapBrowserEvent) {
|
|||||||
|
|
||||||
// scale anchor point.
|
// scale anchor point.
|
||||||
const viewportPosition = map.getViewport().getBoundingClientRect();
|
const viewportPosition = map.getViewport().getBoundingClientRect();
|
||||||
const centroid = PointerInteraction.centroid(this.targetPointers);
|
const centroid = centroidFromPointers(this.targetPointers);
|
||||||
centroid[0] -= viewportPosition.left;
|
centroid[0] -= viewportPosition.left;
|
||||||
centroid[1] -= viewportPosition.top;
|
centroid[1] -= viewportPosition.top;
|
||||||
this.anchor_ = map.getCoordinateFromPixel(centroid);
|
this.anchor_ = map.getCoordinateFromPixel(centroid);
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ inherits(PointerInteraction, Interaction);
|
|||||||
* @param {Array.<ol.pointer.PointerEvent>} pointerEvents List of events.
|
* @param {Array.<ol.pointer.PointerEvent>} pointerEvents List of events.
|
||||||
* @return {ol.Pixel} Centroid pixel.
|
* @return {ol.Pixel} Centroid pixel.
|
||||||
*/
|
*/
|
||||||
PointerInteraction.centroid = function(pointerEvents) {
|
export function centroid(pointerEvents) {
|
||||||
const length = pointerEvents.length;
|
const length = pointerEvents.length;
|
||||||
let clientX = 0;
|
let clientX = 0;
|
||||||
let clientY = 0;
|
let clientY = 0;
|
||||||
@@ -95,21 +95,20 @@ PointerInteraction.centroid = function(pointerEvents) {
|
|||||||
clientY += pointerEvents[i].clientY;
|
clientY += pointerEvents[i].clientY;
|
||||||
}
|
}
|
||||||
return [clientX / length, clientY / length];
|
return [clientX / length, clientY / length];
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
|
* @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
|
||||||
* @return {boolean} Whether the event is a pointerdown, pointerdrag
|
* @return {boolean} Whether the event is a pointerdown, pointerdrag
|
||||||
* or pointerup event.
|
* or pointerup event.
|
||||||
* @private
|
|
||||||
*/
|
*/
|
||||||
PointerInteraction.prototype.isPointerDraggingEvent_ = function(mapBrowserEvent) {
|
function isPointerDraggingEvent(mapBrowserEvent) {
|
||||||
const type = mapBrowserEvent.type;
|
const type = mapBrowserEvent.type;
|
||||||
return type === MapBrowserEventType.POINTERDOWN ||
|
return type === MapBrowserEventType.POINTERDOWN ||
|
||||||
type === MapBrowserEventType.POINTERDRAG ||
|
type === MapBrowserEventType.POINTERDRAG ||
|
||||||
type === MapBrowserEventType.POINTERUP;
|
type === MapBrowserEventType.POINTERUP;
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -117,7 +116,7 @@ PointerInteraction.prototype.isPointerDraggingEvent_ = function(mapBrowserEvent)
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
PointerInteraction.prototype.updateTrackedPointers_ = function(mapBrowserEvent) {
|
PointerInteraction.prototype.updateTrackedPointers_ = function(mapBrowserEvent) {
|
||||||
if (this.isPointerDraggingEvent_(mapBrowserEvent)) {
|
if (isPointerDraggingEvent(mapBrowserEvent)) {
|
||||||
const event = mapBrowserEvent.pointerEvent;
|
const event = mapBrowserEvent.pointerEvent;
|
||||||
|
|
||||||
const id = event.pointerId.toString();
|
const id = event.pointerId.toString();
|
||||||
|
|||||||
Reference in New Issue
Block a user