Remove private static members from Snap interaction
This commit is contained in:
@@ -42,9 +42,9 @@ import RBush from '../structs/RBush.js';
|
||||
const Snap = function(opt_options) {
|
||||
|
||||
PointerInteraction.call(this, {
|
||||
handleEvent: Snap.handleEvent_,
|
||||
handleEvent: handleEvent,
|
||||
handleDownEvent: TRUE,
|
||||
handleUpEvent: Snap.handleUpEvent_
|
||||
handleUpEvent: handleUpEvent
|
||||
});
|
||||
|
||||
const options = opt_options ? opt_options : {};
|
||||
@@ -586,32 +586,30 @@ Snap.prototype.writePolygonGeometry_ = function(feature, geometry) {
|
||||
* @param {ol.MapBrowserEvent} evt A move event.
|
||||
* @return {boolean} Pass the event to other interactions.
|
||||
* @this {ol.interaction.Snap}
|
||||
* @private
|
||||
*/
|
||||
Snap.handleEvent_ = function(evt) {
|
||||
export function handleEvent(evt) {
|
||||
const result = this.snapTo(evt.pixel, evt.coordinate, evt.map);
|
||||
if (result.snapped) {
|
||||
evt.coordinate = result.vertex.slice(0, 2);
|
||||
evt.pixel = result.vertexPixel;
|
||||
}
|
||||
return PointerInteraction.handleEvent.call(this, evt);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.MapBrowserPointerEvent} evt Event.
|
||||
* @return {boolean} Stop drag sequence?
|
||||
* @this {ol.interaction.Snap}
|
||||
* @private
|
||||
*/
|
||||
Snap.handleUpEvent_ = function(evt) {
|
||||
function handleUpEvent(evt) {
|
||||
const featuresToUpdate = getValues(this.pendingFeatures_);
|
||||
if (featuresToUpdate.length) {
|
||||
featuresToUpdate.forEach(this.updateFeature_.bind(this));
|
||||
this.pendingFeatures_ = {};
|
||||
}
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -627,4 +625,5 @@ Snap.sortByDistance = function(a, b) {
|
||||
squaredDistanceToSegment(
|
||||
this.pixelCoordinate_, b.segment);
|
||||
};
|
||||
|
||||
export default Snap;
|
||||
|
||||
@@ -5,7 +5,7 @@ import View from '../../../../src/ol/View.js';
|
||||
import Circle from '../../../../src/ol/geom/Circle.js';
|
||||
import Point from '../../../../src/ol/geom/Point.js';
|
||||
import LineString from '../../../../src/ol/geom/LineString.js';
|
||||
import Snap from '../../../../src/ol/interaction/Snap.js';
|
||||
import Snap, {handleEvent} from '../../../../src/ol/interaction/Snap.js';
|
||||
|
||||
|
||||
describe('ol.interaction.Snap', function() {
|
||||
@@ -19,7 +19,7 @@ describe('ol.interaction.Snap', function() {
|
||||
|
||||
});
|
||||
|
||||
describe('handleEvent_', function() {
|
||||
describe('handleEvent', function() {
|
||||
let target, map;
|
||||
|
||||
const width = 360;
|
||||
@@ -67,7 +67,7 @@ describe('ol.interaction.Snap', function() {
|
||||
coordinate: [0, 0],
|
||||
map: map
|
||||
};
|
||||
Snap.handleEvent_.call(snapInteraction, event);
|
||||
handleEvent.call(snapInteraction, event);
|
||||
// check that the coordinate is in XY and not XYZ
|
||||
expect(event.coordinate).to.eql([0, 0]);
|
||||
});
|
||||
@@ -86,7 +86,7 @@ describe('ol.interaction.Snap', function() {
|
||||
coordinate: [7, 4],
|
||||
map: map
|
||||
};
|
||||
Snap.handleEvent_.call(snapInteraction, event);
|
||||
handleEvent.call(snapInteraction, event);
|
||||
expect(event.coordinate).to.eql([7, 0]);
|
||||
});
|
||||
|
||||
@@ -104,7 +104,7 @@ describe('ol.interaction.Snap', function() {
|
||||
coordinate: [7, 4],
|
||||
map: map
|
||||
};
|
||||
Snap.handleEvent_.call(snapInteraction, event);
|
||||
handleEvent.call(snapInteraction, event);
|
||||
expect(event.coordinate).to.eql([10, 0]);
|
||||
});
|
||||
|
||||
@@ -121,7 +121,7 @@ describe('ol.interaction.Snap', function() {
|
||||
coordinate: [5, 5],
|
||||
map: map
|
||||
};
|
||||
Snap.handleEvent_.call(snapInteraction, event);
|
||||
handleEvent.call(snapInteraction, event);
|
||||
|
||||
expect(event.coordinate[0]).to.roughlyEqual(Math.sin(Math.PI / 4) * 10, 1e-10);
|
||||
expect(event.coordinate[1]).to.roughlyEqual(Math.sin(Math.PI / 4) * 10, 1e-10);
|
||||
@@ -143,7 +143,7 @@ describe('ol.interaction.Snap', function() {
|
||||
coordinate: [7, 4],
|
||||
map: map
|
||||
};
|
||||
Snap.handleEvent_.call(snapInteraction, event);
|
||||
handleEvent.call(snapInteraction, event);
|
||||
expect(event.coordinate).to.eql([10, 0]);
|
||||
});
|
||||
|
||||
@@ -163,7 +163,7 @@ describe('ol.interaction.Snap', function() {
|
||||
coordinate: [7, 4],
|
||||
map: map
|
||||
};
|
||||
Snap.handleEvent_.call(snapInteraction, event);
|
||||
handleEvent.call(snapInteraction, event);
|
||||
expect(event.coordinate).to.eql([10, 0]);
|
||||
});
|
||||
|
||||
@@ -186,7 +186,7 @@ describe('ol.interaction.Snap', function() {
|
||||
coordinate: [7, 4],
|
||||
map: map
|
||||
};
|
||||
Snap.handleEvent_.call(snapInteraction, event);
|
||||
handleEvent.call(snapInteraction, event);
|
||||
expect(event.coordinate).to.eql([10, 0]);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user