From e0a99c43dc04bd642f54ea2f37120fce96483dfa Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sun, 25 Feb 2018 08:59:48 -0700 Subject: [PATCH] Remove static members from Translate --- src/ol/interaction/Translate.js | 104 +++++++++++++-------- src/ol/interaction/TranslateEventType.js | 27 ------ test/spec/ol/interaction/translate.test.js | 10 +- 3 files changed, 70 insertions(+), 71 deletions(-) delete mode 100644 src/ol/interaction/TranslateEventType.js diff --git a/src/ol/interaction/Translate.js b/src/ol/interaction/Translate.js index b0fc3100ca..4fee69a746 100644 --- a/src/ol/interaction/Translate.js +++ b/src/ol/interaction/Translate.js @@ -10,7 +10,67 @@ import {TRUE} from '../functions.js'; import {includes} from '../array.js'; import PointerInteraction from '../interaction/Pointer.js'; import InteractionProperty from '../interaction/Property.js'; -import TranslateEventType from '../interaction/TranslateEventType.js'; + + +/** + * @enum {string} + */ +const TranslateEventType = { + /** + * Triggered upon feature translation start. + * @event TranslateEvent#translatestart + * @api + */ + TRANSLATESTART: 'translatestart', + /** + * Triggered upon feature translation. + * @event TranslateEvent#translating + * @api + */ + TRANSLATING: 'translating', + /** + * Triggered upon feature translation end. + * @event TranslateEvent#translateend + * @api + */ + TRANSLATEEND: 'translateend' +}; + + +/** + * @classdesc + * Events emitted by {@link ol.interaction.Translate} instances are instances of + * this type. + * + * @constructor + * @extends {ol.events.Event} + * @implements {oli.interaction.TranslateEvent} + * @param {ol.interaction.TranslateEventType} type Type. + * @param {ol.Collection.} features The features translated. + * @param {ol.Coordinate} coordinate The event coordinate. + */ +export const TranslateEvent = function(type, features, coordinate) { + + Event.call(this, type); + + /** + * The features being translated. + * @type {ol.Collection.} + * @api + */ + this.features = features; + + /** + * The coordinate of the drag event. + * @const + * @type {ol.Coordinate} + * @api + */ + this.coordinate = coordinate; +}; + +inherits(TranslateEvent, Event); + /** * @classdesc @@ -18,7 +78,7 @@ import TranslateEventType from '../interaction/TranslateEventType.js'; * * @constructor * @extends {ol.interaction.Pointer} - * @fires ol.interaction.Translate.Event + * @fires ol.interaction.TranslateEvent * @param {olx.interaction.TranslateOptions=} opt_options Options. * @api */ @@ -102,7 +162,7 @@ function handleDownEvent(event) { const features = this.features_ || new Collection([this.lastFeature_]); this.dispatchEvent( - new Translate.Event( + new TranslateEvent( TranslateEventType.TRANSLATESTART, features, event.coordinate)); return true; @@ -124,7 +184,7 @@ function handleUpEvent(event) { const features = this.features_ || new Collection([this.lastFeature_]); this.dispatchEvent( - new Translate.Event( + new TranslateEvent( TranslateEventType.TRANSLATEEND, features, event.coordinate)); return true; @@ -153,7 +213,7 @@ function handleDragEvent(event) { this.lastCoordinate_ = newCoordinate; this.dispatchEvent( - new Translate.Event( + new TranslateEvent( TranslateEventType.TRANSLATING, features, newCoordinate)); } @@ -257,38 +317,4 @@ Translate.prototype.updateState_ = function(oldMap) { }; -/** - * @classdesc - * Events emitted by {@link ol.interaction.Translate} instances are instances of - * this type. - * - * @constructor - * @extends {ol.events.Event} - * @implements {oli.interaction.TranslateEvent} - * @param {ol.interaction.TranslateEventType} type Type. - * @param {ol.Collection.} features The features translated. - * @param {ol.Coordinate} coordinate The event coordinate. - */ -Translate.Event = function(type, features, coordinate) { - - Event.call(this, type); - - /** - * The features being translated. - * @type {ol.Collection.} - * @api - */ - this.features = features; - - /** - * The coordinate of the drag event. - * @const - * @type {ol.Coordinate} - * @api - */ - this.coordinate = coordinate; -}; - -inherits(Translate.Event, Event); - export default Translate; diff --git a/src/ol/interaction/TranslateEventType.js b/src/ol/interaction/TranslateEventType.js deleted file mode 100644 index 8ce3894526..0000000000 --- a/src/ol/interaction/TranslateEventType.js +++ /dev/null @@ -1,27 +0,0 @@ -/** - * @module ol/interaction/TranslateEventType - */ - -/** - * @enum {string} - */ -export default { - /** - * Triggered upon feature translation start. - * @event ol.interaction.Translate.Event#translatestart - * @api - */ - TRANSLATESTART: 'translatestart', - /** - * Triggered upon feature translation. - * @event ol.interaction.Translate.Event#translating - * @api - */ - TRANSLATING: 'translating', - /** - * Triggered upon feature translation end. - * @event ol.interaction.Translate.Event#translateend - * @api - */ - TRANSLATEEND: 'translateend' -}; diff --git a/test/spec/ol/interaction/translate.test.js b/test/spec/ol/interaction/translate.test.js index c274b4c7c1..dfc065d66a 100644 --- a/test/spec/ol/interaction/translate.test.js +++ b/test/spec/ol/interaction/translate.test.js @@ -4,7 +4,7 @@ import Map from '../../../../src/ol/Map.js'; import MapBrowserPointerEvent from '../../../../src/ol/MapBrowserPointerEvent.js'; import View from '../../../../src/ol/View.js'; import Point from '../../../../src/ol/geom/Point.js'; -import Translate from '../../../../src/ol/interaction/Translate.js'; +import Translate, {TranslateEvent} from '../../../../src/ol/interaction/Translate.js'; import Interaction from '../../../../src/ol/interaction/Interaction.js'; import VectorLayer from '../../../../src/ol/layer/Vector.js'; import PointerEvent from '../../../../src/ol/pointer/PointerEvent.js'; @@ -80,7 +80,7 @@ describe('ol.interaction.Translate', function() { * modifications. Helper function to * @param {ol.Feature} feature Translated feature. * @param {ol.interaction.Translate} interaction The interaction. - * @return {Array} events + * @return {Array} events */ function trackEvents(feature, interaction) { const events = []; @@ -100,7 +100,7 @@ describe('ol.interaction.Translate', function() { * Validates the event array to verify proper event sequence. Checks * that first and last event are correct TranslateEvents and that feature * modifications event are in between. - * @param {Array} events The events. + * @param {Array} events The events. * @param {Array} features The features. */ function validateEvents(events, features) { @@ -109,11 +109,11 @@ describe('ol.interaction.Translate', function() { const endevent = events[events.length - 1]; // first event should be translatestart - expect(startevent).to.be.an(Translate.Event); + expect(startevent).to.be.an(TranslateEvent); expect(startevent.type).to.eql('translatestart'); // last event should be translateend - expect(endevent).to.be.an(Translate.Event); + expect(endevent).to.be.an(TranslateEvent); expect(endevent.type).to.eql('translateend'); // make sure we get change events to events array