Rename _ol_interaction_Translate_ to Translate

This commit is contained in:
Frederic Junod
2018-01-15 09:39:20 +01:00
parent 20587b524c
commit fc256ed77e
3 changed files with 35 additions and 35 deletions

View File

@@ -3,7 +3,7 @@ import View from '../src/ol/View.js';
import GeoJSON from '../src/ol/format/GeoJSON.js'; import GeoJSON from '../src/ol/format/GeoJSON.js';
import {defaults as defaultInteractions} from '../src/ol/interaction.js'; import {defaults as defaultInteractions} from '../src/ol/interaction.js';
import Select from '../src/ol/interaction/Select.js'; import Select from '../src/ol/interaction/Select.js';
import _ol_interaction_Translate_ from '../src/ol/interaction/Translate.js'; import Translate from '../src/ol/interaction/Translate.js';
import TileLayer from '../src/ol/layer/Tile.js'; import TileLayer from '../src/ol/layer/Tile.js';
import VectorLayer from '../src/ol/layer/Vector.js'; import VectorLayer from '../src/ol/layer/Vector.js';
import OSM from '../src/ol/source/OSM.js'; import OSM from '../src/ol/source/OSM.js';
@@ -23,7 +23,7 @@ const vector = new VectorLayer({
const select = new Select(); const select = new Select();
const translate = new _ol_interaction_Translate_({ const translate = new Translate({
features: select.getFeatures() features: select.getFeatures()
}); });

View File

@@ -22,12 +22,12 @@ import TranslateEventType from '../interaction/TranslateEventType.js';
* @param {olx.interaction.TranslateOptions=} opt_options Options. * @param {olx.interaction.TranslateOptions=} opt_options Options.
* @api * @api
*/ */
const _ol_interaction_Translate_ = function(opt_options) { const Translate = function(opt_options) {
PointerInteraction.call(this, { PointerInteraction.call(this, {
handleDownEvent: _ol_interaction_Translate_.handleDownEvent_, handleDownEvent: Translate.handleDownEvent_,
handleDragEvent: _ol_interaction_Translate_.handleDragEvent_, handleDragEvent: Translate.handleDragEvent_,
handleMoveEvent: _ol_interaction_Translate_.handleMoveEvent_, handleMoveEvent: Translate.handleMoveEvent_,
handleUpEvent: _ol_interaction_Translate_.handleUpEvent_ handleUpEvent: Translate.handleUpEvent_
}); });
const options = opt_options ? opt_options : {}; const options = opt_options ? opt_options : {};
@@ -85,7 +85,7 @@ const _ol_interaction_Translate_ = function(opt_options) {
}; };
inherits(_ol_interaction_Translate_, PointerInteraction); inherits(Translate, PointerInteraction);
/** /**
@@ -94,16 +94,16 @@ inherits(_ol_interaction_Translate_, PointerInteraction);
* @this {ol.interaction.Translate} * @this {ol.interaction.Translate}
* @private * @private
*/ */
_ol_interaction_Translate_.handleDownEvent_ = function(event) { Translate.handleDownEvent_ = function(event) {
this.lastFeature_ = this.featuresAtPixel_(event.pixel, event.map); this.lastFeature_ = this.featuresAtPixel_(event.pixel, event.map);
if (!this.lastCoordinate_ && this.lastFeature_) { if (!this.lastCoordinate_ && this.lastFeature_) {
this.lastCoordinate_ = event.coordinate; this.lastCoordinate_ = event.coordinate;
_ol_interaction_Translate_.handleMoveEvent_.call(this, event); Translate.handleMoveEvent_.call(this, event);
const features = this.features_ || new Collection([this.lastFeature_]); const features = this.features_ || new Collection([this.lastFeature_]);
this.dispatchEvent( this.dispatchEvent(
new _ol_interaction_Translate_.Event( new Translate.Event(
TranslateEventType.TRANSLATESTART, features, TranslateEventType.TRANSLATESTART, features,
event.coordinate)); event.coordinate));
return true; return true;
@@ -118,15 +118,15 @@ _ol_interaction_Translate_.handleDownEvent_ = function(event) {
* @this {ol.interaction.Translate} * @this {ol.interaction.Translate}
* @private * @private
*/ */
_ol_interaction_Translate_.handleUpEvent_ = function(event) { Translate.handleUpEvent_ = function(event) {
if (this.lastCoordinate_) { if (this.lastCoordinate_) {
this.lastCoordinate_ = null; this.lastCoordinate_ = null;
_ol_interaction_Translate_.handleMoveEvent_.call(this, event); Translate.handleMoveEvent_.call(this, event);
const features = this.features_ || new Collection([this.lastFeature_]); const features = this.features_ || new Collection([this.lastFeature_]);
this.dispatchEvent( this.dispatchEvent(
new _ol_interaction_Translate_.Event( new Translate.Event(
TranslateEventType.TRANSLATEEND, features, TranslateEventType.TRANSLATEEND, features,
event.coordinate)); event.coordinate));
return true; return true;
@@ -140,7 +140,7 @@ _ol_interaction_Translate_.handleUpEvent_ = function(event) {
* @this {ol.interaction.Translate} * @this {ol.interaction.Translate}
* @private * @private
*/ */
_ol_interaction_Translate_.handleDragEvent_ = function(event) { Translate.handleDragEvent_ = function(event) {
if (this.lastCoordinate_) { if (this.lastCoordinate_) {
const newCoordinate = event.coordinate; const newCoordinate = event.coordinate;
const deltaX = newCoordinate[0] - this.lastCoordinate_[0]; const deltaX = newCoordinate[0] - this.lastCoordinate_[0];
@@ -156,7 +156,7 @@ _ol_interaction_Translate_.handleDragEvent_ = function(event) {
this.lastCoordinate_ = newCoordinate; this.lastCoordinate_ = newCoordinate;
this.dispatchEvent( this.dispatchEvent(
new _ol_interaction_Translate_.Event( new Translate.Event(
TranslateEventType.TRANSLATING, features, TranslateEventType.TRANSLATING, features,
newCoordinate)); newCoordinate));
} }
@@ -168,7 +168,7 @@ _ol_interaction_Translate_.handleDragEvent_ = function(event) {
* @this {ol.interaction.Translate} * @this {ol.interaction.Translate}
* @private * @private
*/ */
_ol_interaction_Translate_.handleMoveEvent_ = function(event) { Translate.handleMoveEvent_ = function(event) {
const elem = event.map.getViewport(); const elem = event.map.getViewport();
// Change the cursor to grab/grabbing if hovering any of the features managed // Change the cursor to grab/grabbing if hovering any of the features managed
@@ -191,7 +191,7 @@ _ol_interaction_Translate_.handleMoveEvent_ = function(event) {
* coordinates. * coordinates.
* @private * @private
*/ */
_ol_interaction_Translate_.prototype.featuresAtPixel_ = function(pixel, map) { Translate.prototype.featuresAtPixel_ = function(pixel, map) {
return map.forEachFeatureAtPixel(pixel, return map.forEachFeatureAtPixel(pixel,
function(feature) { function(feature) {
if (!this.features_ || includes(this.features_.getArray(), feature)) { if (!this.features_ || includes(this.features_.getArray(), feature)) {
@@ -209,7 +209,7 @@ _ol_interaction_Translate_.prototype.featuresAtPixel_ = function(pixel, map) {
* @returns {number} Hit tolerance in pixels. * @returns {number} Hit tolerance in pixels.
* @api * @api
*/ */
_ol_interaction_Translate_.prototype.getHitTolerance = function() { Translate.prototype.getHitTolerance = function() {
return this.hitTolerance_; return this.hitTolerance_;
}; };
@@ -221,7 +221,7 @@ _ol_interaction_Translate_.prototype.getHitTolerance = function() {
* @param {number} hitTolerance Hit tolerance in pixels. * @param {number} hitTolerance Hit tolerance in pixels.
* @api * @api
*/ */
_ol_interaction_Translate_.prototype.setHitTolerance = function(hitTolerance) { Translate.prototype.setHitTolerance = function(hitTolerance) {
this.hitTolerance_ = hitTolerance; this.hitTolerance_ = hitTolerance;
}; };
@@ -229,7 +229,7 @@ _ol_interaction_Translate_.prototype.setHitTolerance = function(hitTolerance) {
/** /**
* @inheritDoc * @inheritDoc
*/ */
_ol_interaction_Translate_.prototype.setMap = function(map) { Translate.prototype.setMap = function(map) {
const oldMap = this.getMap(); const oldMap = this.getMap();
PointerInteraction.prototype.setMap.call(this, map); PointerInteraction.prototype.setMap.call(this, map);
this.updateState_(oldMap); this.updateState_(oldMap);
@@ -239,7 +239,7 @@ _ol_interaction_Translate_.prototype.setMap = function(map) {
/** /**
* @private * @private
*/ */
_ol_interaction_Translate_.prototype.handleActiveChanged_ = function() { Translate.prototype.handleActiveChanged_ = function() {
this.updateState_(null); this.updateState_(null);
}; };
@@ -248,7 +248,7 @@ _ol_interaction_Translate_.prototype.handleActiveChanged_ = function() {
* @param {ol.PluggableMap} oldMap Old map. * @param {ol.PluggableMap} oldMap Old map.
* @private * @private
*/ */
_ol_interaction_Translate_.prototype.updateState_ = function(oldMap) { Translate.prototype.updateState_ = function(oldMap) {
let map = this.getMap(); let map = this.getMap();
const active = this.getActive(); const active = this.getActive();
if (!map || !active) { if (!map || !active) {
@@ -273,7 +273,7 @@ _ol_interaction_Translate_.prototype.updateState_ = function(oldMap) {
* @param {ol.Collection.<ol.Feature>} features The features translated. * @param {ol.Collection.<ol.Feature>} features The features translated.
* @param {ol.Coordinate} coordinate The event coordinate. * @param {ol.Coordinate} coordinate The event coordinate.
*/ */
_ol_interaction_Translate_.Event = function(type, features, coordinate) { Translate.Event = function(type, features, coordinate) {
Event.call(this, type); Event.call(this, type);
@@ -292,5 +292,5 @@ _ol_interaction_Translate_.Event = function(type, features, coordinate) {
*/ */
this.coordinate = coordinate; this.coordinate = coordinate;
}; };
inherits(_ol_interaction_Translate_.Event, Event); inherits(Translate.Event, Event);
export default _ol_interaction_Translate_; export default Translate;

View File

@@ -4,7 +4,7 @@ import Map from '../../../../src/ol/Map.js';
import MapBrowserPointerEvent from '../../../../src/ol/MapBrowserPointerEvent.js'; import MapBrowserPointerEvent from '../../../../src/ol/MapBrowserPointerEvent.js';
import View from '../../../../src/ol/View.js'; import View from '../../../../src/ol/View.js';
import Point from '../../../../src/ol/geom/Point.js'; import Point from '../../../../src/ol/geom/Point.js';
import _ol_interaction_Translate_ from '../../../../src/ol/interaction/Translate.js'; import Translate from '../../../../src/ol/interaction/Translate.js';
import Interaction from '../../../../src/ol/interaction/Interaction.js'; import Interaction from '../../../../src/ol/interaction/Interaction.js';
import VectorLayer from '../../../../src/ol/layer/Vector.js'; import VectorLayer from '../../../../src/ol/layer/Vector.js';
import PointerEvent from '../../../../src/ol/pointer/PointerEvent.js'; import PointerEvent from '../../../../src/ol/pointer/PointerEvent.js';
@@ -109,11 +109,11 @@ describe('ol.interaction.Translate', function() {
const endevent = events[events.length - 1]; const endevent = events[events.length - 1];
// first event should be translatestart // first event should be translatestart
expect(startevent).to.be.an(_ol_interaction_Translate_.Event); expect(startevent).to.be.an(Translate.Event);
expect(startevent.type).to.eql('translatestart'); expect(startevent.type).to.eql('translatestart');
// last event should be translateend // last event should be translateend
expect(endevent).to.be.an(_ol_interaction_Translate_.Event); expect(endevent).to.be.an(Translate.Event);
expect(endevent.type).to.eql('translateend'); expect(endevent.type).to.eql('translateend');
// make sure we get change events to events array // make sure we get change events to events array
@@ -132,10 +132,10 @@ describe('ol.interaction.Translate', function() {
describe('constructor', function() { describe('constructor', function() {
it('creates a new interaction', function() { it('creates a new interaction', function() {
const translate = new _ol_interaction_Translate_({ const translate = new Translate({
features: features features: features
}); });
expect(translate).to.be.a(_ol_interaction_Translate_); expect(translate).to.be.a(Translate);
expect(translate).to.be.a(Interaction); expect(translate).to.be.a(Interaction);
}); });
@@ -144,7 +144,7 @@ describe('ol.interaction.Translate', function() {
describe('setActive', function() { describe('setActive', function() {
it('works when the map is not set', function() { it('works when the map is not set', function() {
const translate = new _ol_interaction_Translate_({ const translate = new Translate({
features: features features: features
}); });
expect(translate.getActive()).to.be(true); expect(translate.getActive()).to.be(true);
@@ -158,7 +158,7 @@ describe('ol.interaction.Translate', function() {
let translate; let translate;
beforeEach(function() { beforeEach(function() {
translate = new _ol_interaction_Translate_({ translate = new Translate({
features: new Collection([features[0]]) features: new Collection([features[0]])
}); });
map.addInteraction(translate); map.addInteraction(translate);
@@ -197,7 +197,7 @@ describe('ol.interaction.Translate', function() {
let translate; let translate;
beforeEach(function() { beforeEach(function() {
translate = new _ol_interaction_Translate_(); translate = new Translate();
map.addInteraction(translate); map.addInteraction(translate);
}); });
@@ -219,7 +219,7 @@ describe('ol.interaction.Translate', function() {
let element, translate; let element, translate;
beforeEach(function() { beforeEach(function() {
translate = new _ol_interaction_Translate_(); translate = new Translate();
map.addInteraction(translate); map.addInteraction(translate);
element = map.getViewport(); element = map.getViewport();
}); });