Rename _ol_interaction_Translate_ to Translate
This commit is contained in:
@@ -3,7 +3,7 @@ import View from '../src/ol/View.js';
|
||||
import GeoJSON from '../src/ol/format/GeoJSON.js';
|
||||
import {defaults as defaultInteractions} from '../src/ol/interaction.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 VectorLayer from '../src/ol/layer/Vector.js';
|
||||
import OSM from '../src/ol/source/OSM.js';
|
||||
@@ -23,7 +23,7 @@ const vector = new VectorLayer({
|
||||
|
||||
const select = new Select();
|
||||
|
||||
const translate = new _ol_interaction_Translate_({
|
||||
const translate = new Translate({
|
||||
features: select.getFeatures()
|
||||
});
|
||||
|
||||
|
||||
@@ -22,12 +22,12 @@ import TranslateEventType from '../interaction/TranslateEventType.js';
|
||||
* @param {olx.interaction.TranslateOptions=} opt_options Options.
|
||||
* @api
|
||||
*/
|
||||
const _ol_interaction_Translate_ = function(opt_options) {
|
||||
const Translate = function(opt_options) {
|
||||
PointerInteraction.call(this, {
|
||||
handleDownEvent: _ol_interaction_Translate_.handleDownEvent_,
|
||||
handleDragEvent: _ol_interaction_Translate_.handleDragEvent_,
|
||||
handleMoveEvent: _ol_interaction_Translate_.handleMoveEvent_,
|
||||
handleUpEvent: _ol_interaction_Translate_.handleUpEvent_
|
||||
handleDownEvent: Translate.handleDownEvent_,
|
||||
handleDragEvent: Translate.handleDragEvent_,
|
||||
handleMoveEvent: Translate.handleMoveEvent_,
|
||||
handleUpEvent: Translate.handleUpEvent_
|
||||
});
|
||||
|
||||
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}
|
||||
* @private
|
||||
*/
|
||||
_ol_interaction_Translate_.handleDownEvent_ = function(event) {
|
||||
Translate.handleDownEvent_ = function(event) {
|
||||
this.lastFeature_ = this.featuresAtPixel_(event.pixel, event.map);
|
||||
if (!this.lastCoordinate_ && this.lastFeature_) {
|
||||
this.lastCoordinate_ = event.coordinate;
|
||||
_ol_interaction_Translate_.handleMoveEvent_.call(this, event);
|
||||
Translate.handleMoveEvent_.call(this, event);
|
||||
|
||||
const features = this.features_ || new Collection([this.lastFeature_]);
|
||||
|
||||
this.dispatchEvent(
|
||||
new _ol_interaction_Translate_.Event(
|
||||
new Translate.Event(
|
||||
TranslateEventType.TRANSLATESTART, features,
|
||||
event.coordinate));
|
||||
return true;
|
||||
@@ -118,15 +118,15 @@ _ol_interaction_Translate_.handleDownEvent_ = function(event) {
|
||||
* @this {ol.interaction.Translate}
|
||||
* @private
|
||||
*/
|
||||
_ol_interaction_Translate_.handleUpEvent_ = function(event) {
|
||||
Translate.handleUpEvent_ = function(event) {
|
||||
if (this.lastCoordinate_) {
|
||||
this.lastCoordinate_ = null;
|
||||
_ol_interaction_Translate_.handleMoveEvent_.call(this, event);
|
||||
Translate.handleMoveEvent_.call(this, event);
|
||||
|
||||
const features = this.features_ || new Collection([this.lastFeature_]);
|
||||
|
||||
this.dispatchEvent(
|
||||
new _ol_interaction_Translate_.Event(
|
||||
new Translate.Event(
|
||||
TranslateEventType.TRANSLATEEND, features,
|
||||
event.coordinate));
|
||||
return true;
|
||||
@@ -140,7 +140,7 @@ _ol_interaction_Translate_.handleUpEvent_ = function(event) {
|
||||
* @this {ol.interaction.Translate}
|
||||
* @private
|
||||
*/
|
||||
_ol_interaction_Translate_.handleDragEvent_ = function(event) {
|
||||
Translate.handleDragEvent_ = function(event) {
|
||||
if (this.lastCoordinate_) {
|
||||
const newCoordinate = event.coordinate;
|
||||
const deltaX = newCoordinate[0] - this.lastCoordinate_[0];
|
||||
@@ -156,7 +156,7 @@ _ol_interaction_Translate_.handleDragEvent_ = function(event) {
|
||||
|
||||
this.lastCoordinate_ = newCoordinate;
|
||||
this.dispatchEvent(
|
||||
new _ol_interaction_Translate_.Event(
|
||||
new Translate.Event(
|
||||
TranslateEventType.TRANSLATING, features,
|
||||
newCoordinate));
|
||||
}
|
||||
@@ -168,7 +168,7 @@ _ol_interaction_Translate_.handleDragEvent_ = function(event) {
|
||||
* @this {ol.interaction.Translate}
|
||||
* @private
|
||||
*/
|
||||
_ol_interaction_Translate_.handleMoveEvent_ = function(event) {
|
||||
Translate.handleMoveEvent_ = function(event) {
|
||||
const elem = event.map.getViewport();
|
||||
|
||||
// Change the cursor to grab/grabbing if hovering any of the features managed
|
||||
@@ -191,7 +191,7 @@ _ol_interaction_Translate_.handleMoveEvent_ = function(event) {
|
||||
* coordinates.
|
||||
* @private
|
||||
*/
|
||||
_ol_interaction_Translate_.prototype.featuresAtPixel_ = function(pixel, map) {
|
||||
Translate.prototype.featuresAtPixel_ = function(pixel, map) {
|
||||
return map.forEachFeatureAtPixel(pixel,
|
||||
function(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.
|
||||
* @api
|
||||
*/
|
||||
_ol_interaction_Translate_.prototype.getHitTolerance = function() {
|
||||
Translate.prototype.getHitTolerance = function() {
|
||||
return this.hitTolerance_;
|
||||
};
|
||||
|
||||
@@ -221,7 +221,7 @@ _ol_interaction_Translate_.prototype.getHitTolerance = function() {
|
||||
* @param {number} hitTolerance Hit tolerance in pixels.
|
||||
* @api
|
||||
*/
|
||||
_ol_interaction_Translate_.prototype.setHitTolerance = function(hitTolerance) {
|
||||
Translate.prototype.setHitTolerance = function(hitTolerance) {
|
||||
this.hitTolerance_ = hitTolerance;
|
||||
};
|
||||
|
||||
@@ -229,7 +229,7 @@ _ol_interaction_Translate_.prototype.setHitTolerance = function(hitTolerance) {
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
_ol_interaction_Translate_.prototype.setMap = function(map) {
|
||||
Translate.prototype.setMap = function(map) {
|
||||
const oldMap = this.getMap();
|
||||
PointerInteraction.prototype.setMap.call(this, map);
|
||||
this.updateState_(oldMap);
|
||||
@@ -239,7 +239,7 @@ _ol_interaction_Translate_.prototype.setMap = function(map) {
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
_ol_interaction_Translate_.prototype.handleActiveChanged_ = function() {
|
||||
Translate.prototype.handleActiveChanged_ = function() {
|
||||
this.updateState_(null);
|
||||
};
|
||||
|
||||
@@ -248,7 +248,7 @@ _ol_interaction_Translate_.prototype.handleActiveChanged_ = function() {
|
||||
* @param {ol.PluggableMap} oldMap Old map.
|
||||
* @private
|
||||
*/
|
||||
_ol_interaction_Translate_.prototype.updateState_ = function(oldMap) {
|
||||
Translate.prototype.updateState_ = function(oldMap) {
|
||||
let map = this.getMap();
|
||||
const active = this.getActive();
|
||||
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.Coordinate} coordinate The event coordinate.
|
||||
*/
|
||||
_ol_interaction_Translate_.Event = function(type, features, coordinate) {
|
||||
Translate.Event = function(type, features, coordinate) {
|
||||
|
||||
Event.call(this, type);
|
||||
|
||||
@@ -292,5 +292,5 @@ _ol_interaction_Translate_.Event = function(type, features, coordinate) {
|
||||
*/
|
||||
this.coordinate = coordinate;
|
||||
};
|
||||
inherits(_ol_interaction_Translate_.Event, Event);
|
||||
export default _ol_interaction_Translate_;
|
||||
inherits(Translate.Event, Event);
|
||||
export default Translate;
|
||||
|
||||
@@ -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 _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 VectorLayer from '../../../../src/ol/layer/Vector.js';
|
||||
import PointerEvent from '../../../../src/ol/pointer/PointerEvent.js';
|
||||
@@ -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(_ol_interaction_Translate_.Event);
|
||||
expect(startevent).to.be.an(Translate.Event);
|
||||
expect(startevent.type).to.eql('translatestart');
|
||||
|
||||
// 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');
|
||||
|
||||
// make sure we get change events to events array
|
||||
@@ -132,10 +132,10 @@ describe('ol.interaction.Translate', function() {
|
||||
describe('constructor', function() {
|
||||
|
||||
it('creates a new interaction', function() {
|
||||
const translate = new _ol_interaction_Translate_({
|
||||
const translate = new Translate({
|
||||
features: features
|
||||
});
|
||||
expect(translate).to.be.a(_ol_interaction_Translate_);
|
||||
expect(translate).to.be.a(Translate);
|
||||
expect(translate).to.be.a(Interaction);
|
||||
});
|
||||
|
||||
@@ -144,7 +144,7 @@ describe('ol.interaction.Translate', function() {
|
||||
describe('setActive', function() {
|
||||
|
||||
it('works when the map is not set', function() {
|
||||
const translate = new _ol_interaction_Translate_({
|
||||
const translate = new Translate({
|
||||
features: features
|
||||
});
|
||||
expect(translate.getActive()).to.be(true);
|
||||
@@ -158,7 +158,7 @@ describe('ol.interaction.Translate', function() {
|
||||
let translate;
|
||||
|
||||
beforeEach(function() {
|
||||
translate = new _ol_interaction_Translate_({
|
||||
translate = new Translate({
|
||||
features: new Collection([features[0]])
|
||||
});
|
||||
map.addInteraction(translate);
|
||||
@@ -197,7 +197,7 @@ describe('ol.interaction.Translate', function() {
|
||||
let translate;
|
||||
|
||||
beforeEach(function() {
|
||||
translate = new _ol_interaction_Translate_();
|
||||
translate = new Translate();
|
||||
map.addInteraction(translate);
|
||||
});
|
||||
|
||||
@@ -219,7 +219,7 @@ describe('ol.interaction.Translate', function() {
|
||||
let element, translate;
|
||||
|
||||
beforeEach(function() {
|
||||
translate = new _ol_interaction_Translate_();
|
||||
translate = new Translate();
|
||||
map.addInteraction(translate);
|
||||
element = map.getViewport();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user