Named exports from ol/interaction/Pointer

This commit is contained in:
Frederic Junod
2018-02-21 16:52:00 +01:00
parent 190449e816
commit fa1fcc79b6
4 changed files with 11 additions and 12 deletions

View File

@@ -7,7 +7,7 @@ import {scale as scaleCoordinate, rotate as rotateCoordinate, add as addCoordina
import {easeOut} from '../easing.js';
import {noModifierKeys} from '../events/condition.js';
import {FALSE} from '../functions.js';
import PointerInteraction from '../interaction/Pointer.js';
import PointerInteraction, {centroid as centroidFromPointers} from '../interaction/Pointer.js';
/**
* @classdesc
@@ -67,7 +67,7 @@ inherits(DragPan, PointerInteraction);
*/
function handleDragEvent(mapBrowserEvent) {
const targetPointers = this.targetPointers;
const centroid = PointerInteraction.centroid(targetPointers);
const centroid = centroidFromPointers(targetPointers);
if (targetPointers.length == this.lastPointersCount_) {
if (this.kinetic_) {
this.kinetic_.update(centroid[0], centroid[1]);

View File

@@ -5,7 +5,7 @@ import {inherits} from '../index.js';
import ViewHint from '../ViewHint.js';
import {FALSE} from '../functions.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';
/**
@@ -105,7 +105,7 @@ function handleDragEvent(mapBrowserEvent) {
// FIXME: should be the intersection point between the lines:
// touch0,touch1 and previousTouch0,previousTouch1
const viewportPosition = map.getViewport().getBoundingClientRect();
const centroid = PointerInteraction.centroid(this.targetPointers);
const centroid = centroidFromPointers(this.targetPointers);
centroid[0] -= viewportPosition.left;
centroid[1] -= viewportPosition.top;
this.anchor_ = map.getCoordinateFromPixel(centroid);

View File

@@ -5,7 +5,7 @@ import {inherits} from '../index.js';
import ViewHint from '../ViewHint.js';
import {FALSE} from '../functions.js';
import Interaction from '../interaction/Interaction.js';
import PointerInteraction from '../interaction/Pointer.js';
import PointerInteraction, {centroid as centroidFromPointers} from '../interaction/Pointer.js';
/**
* @classdesc
@@ -103,7 +103,7 @@ function handleDragEvent(mapBrowserEvent) {
// scale anchor point.
const viewportPosition = map.getViewport().getBoundingClientRect();
const centroid = PointerInteraction.centroid(this.targetPointers);
const centroid = centroidFromPointers(this.targetPointers);
centroid[0] -= viewportPosition.left;
centroid[1] -= viewportPosition.top;
this.anchor_ = map.getCoordinateFromPixel(centroid);

View File

@@ -86,7 +86,7 @@ inherits(PointerInteraction, Interaction);
* @param {Array.<ol.pointer.PointerEvent>} pointerEvents List of events.
* @return {ol.Pixel} Centroid pixel.
*/
PointerInteraction.centroid = function(pointerEvents) {
export function centroid(pointerEvents) {
const length = pointerEvents.length;
let clientX = 0;
let clientY = 0;
@@ -95,21 +95,20 @@ PointerInteraction.centroid = function(pointerEvents) {
clientY += pointerEvents[i].clientY;
}
return [clientX / length, clientY / length];
};
}
/**
* @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
* @return {boolean} Whether the event is a pointerdown, pointerdrag
* or pointerup event.
* @private
*/
PointerInteraction.prototype.isPointerDraggingEvent_ = function(mapBrowserEvent) {
function isPointerDraggingEvent(mapBrowserEvent) {
const type = mapBrowserEvent.type;
return type === MapBrowserEventType.POINTERDOWN ||
type === MapBrowserEventType.POINTERDRAG ||
type === MapBrowserEventType.POINTERUP;
};
}
/**
@@ -117,7 +116,7 @@ PointerInteraction.prototype.isPointerDraggingEvent_ = function(mapBrowserEvent)
* @private
*/
PointerInteraction.prototype.updateTrackedPointers_ = function(mapBrowserEvent) {
if (this.isPointerDraggingEvent_(mapBrowserEvent)) {
if (isPointerDraggingEvent(mapBrowserEvent)) {
const event = mapBrowserEvent.pointerEvent;
const id = event.pointerId.toString();