Remove private static members from Snap interaction

This commit is contained in:
Tim Schaub
2018-02-12 06:28:21 -07:00
parent 37c446fc4e
commit 1c63234508
2 changed files with 16 additions and 17 deletions
+7 -8
View File
@@ -42,9 +42,9 @@ import RBush from '../structs/RBush.js';
const Snap = function(opt_options) { const Snap = function(opt_options) {
PointerInteraction.call(this, { PointerInteraction.call(this, {
handleEvent: Snap.handleEvent_, handleEvent: handleEvent,
handleDownEvent: TRUE, handleDownEvent: TRUE,
handleUpEvent: Snap.handleUpEvent_ handleUpEvent: handleUpEvent
}); });
const options = opt_options ? opt_options : {}; const options = opt_options ? opt_options : {};
@@ -586,32 +586,30 @@ Snap.prototype.writePolygonGeometry_ = function(feature, geometry) {
* @param {ol.MapBrowserEvent} evt A move event. * @param {ol.MapBrowserEvent} evt A move event.
* @return {boolean} Pass the event to other interactions. * @return {boolean} Pass the event to other interactions.
* @this {ol.interaction.Snap} * @this {ol.interaction.Snap}
* @private
*/ */
Snap.handleEvent_ = function(evt) { export function handleEvent(evt) {
const result = this.snapTo(evt.pixel, evt.coordinate, evt.map); const result = this.snapTo(evt.pixel, evt.coordinate, evt.map);
if (result.snapped) { if (result.snapped) {
evt.coordinate = result.vertex.slice(0, 2); evt.coordinate = result.vertex.slice(0, 2);
evt.pixel = result.vertexPixel; evt.pixel = result.vertexPixel;
} }
return PointerInteraction.handleEvent.call(this, evt); return PointerInteraction.handleEvent.call(this, evt);
}; }
/** /**
* @param {ol.MapBrowserPointerEvent} evt Event. * @param {ol.MapBrowserPointerEvent} evt Event.
* @return {boolean} Stop drag sequence? * @return {boolean} Stop drag sequence?
* @this {ol.interaction.Snap} * @this {ol.interaction.Snap}
* @private
*/ */
Snap.handleUpEvent_ = function(evt) { function handleUpEvent(evt) {
const featuresToUpdate = getValues(this.pendingFeatures_); const featuresToUpdate = getValues(this.pendingFeatures_);
if (featuresToUpdate.length) { if (featuresToUpdate.length) {
featuresToUpdate.forEach(this.updateFeature_.bind(this)); featuresToUpdate.forEach(this.updateFeature_.bind(this));
this.pendingFeatures_ = {}; this.pendingFeatures_ = {};
} }
return false; return false;
}; }
/** /**
@@ -627,4 +625,5 @@ Snap.sortByDistance = function(a, b) {
squaredDistanceToSegment( squaredDistanceToSegment(
this.pixelCoordinate_, b.segment); this.pixelCoordinate_, b.segment);
}; };
export default Snap; export default Snap;
+9 -9
View File
@@ -5,7 +5,7 @@ import View from '../../../../src/ol/View.js';
import Circle from '../../../../src/ol/geom/Circle.js'; import Circle from '../../../../src/ol/geom/Circle.js';
import Point from '../../../../src/ol/geom/Point.js'; import Point from '../../../../src/ol/geom/Point.js';
import LineString from '../../../../src/ol/geom/LineString.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() { describe('ol.interaction.Snap', function() {
@@ -19,7 +19,7 @@ describe('ol.interaction.Snap', function() {
}); });
describe('handleEvent_', function() { describe('handleEvent', function() {
let target, map; let target, map;
const width = 360; const width = 360;
@@ -67,7 +67,7 @@ describe('ol.interaction.Snap', function() {
coordinate: [0, 0], coordinate: [0, 0],
map: map map: map
}; };
Snap.handleEvent_.call(snapInteraction, event); handleEvent.call(snapInteraction, event);
// check that the coordinate is in XY and not XYZ // check that the coordinate is in XY and not XYZ
expect(event.coordinate).to.eql([0, 0]); expect(event.coordinate).to.eql([0, 0]);
}); });
@@ -86,7 +86,7 @@ describe('ol.interaction.Snap', function() {
coordinate: [7, 4], coordinate: [7, 4],
map: map map: map
}; };
Snap.handleEvent_.call(snapInteraction, event); handleEvent.call(snapInteraction, event);
expect(event.coordinate).to.eql([7, 0]); expect(event.coordinate).to.eql([7, 0]);
}); });
@@ -104,7 +104,7 @@ describe('ol.interaction.Snap', function() {
coordinate: [7, 4], coordinate: [7, 4],
map: map map: map
}; };
Snap.handleEvent_.call(snapInteraction, event); handleEvent.call(snapInteraction, event);
expect(event.coordinate).to.eql([10, 0]); expect(event.coordinate).to.eql([10, 0]);
}); });
@@ -121,7 +121,7 @@ describe('ol.interaction.Snap', function() {
coordinate: [5, 5], coordinate: [5, 5],
map: map 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[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); 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], coordinate: [7, 4],
map: map map: map
}; };
Snap.handleEvent_.call(snapInteraction, event); handleEvent.call(snapInteraction, event);
expect(event.coordinate).to.eql([10, 0]); expect(event.coordinate).to.eql([10, 0]);
}); });
@@ -163,7 +163,7 @@ describe('ol.interaction.Snap', function() {
coordinate: [7, 4], coordinate: [7, 4],
map: map map: map
}; };
Snap.handleEvent_.call(snapInteraction, event); handleEvent.call(snapInteraction, event);
expect(event.coordinate).to.eql([10, 0]); expect(event.coordinate).to.eql([10, 0]);
}); });
@@ -186,7 +186,7 @@ describe('ol.interaction.Snap', function() {
coordinate: [7, 4], coordinate: [7, 4],
map: map map: map
}; };
Snap.handleEvent_.call(snapInteraction, event); handleEvent.call(snapInteraction, event);
expect(event.coordinate).to.eql([10, 0]); expect(event.coordinate).to.eql([10, 0]);
}); });