Changes following code review
Add a type for FilterFunction and add tests for filter option.
This commit is contained in:
@@ -35,6 +35,13 @@ const TranslateEventType = {
|
|||||||
TRANSLATEEND: 'translateend'
|
TRANSLATEEND: 'translateend'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A function that takes an {@link module:ol/Feature} or
|
||||||
|
* {@link module:ol/render/Feature} and an
|
||||||
|
* {@link module:ol/layer/Layer} and returns `true` if the feature may be
|
||||||
|
* translated or `false` otherwise.
|
||||||
|
* @typedef {function(import("../Feature.js").FeatureLike, import("../layer/Layer.js").default):boolean} FilterFunction
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {Object} Options
|
* @typedef {Object} Options
|
||||||
|
|||||||
@@ -216,6 +216,47 @@ describe('ol.interaction.Translate', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('moving features, with filter option', function() {
|
||||||
|
let translate;
|
||||||
|
|
||||||
|
beforeEach(function() {
|
||||||
|
translate = new Translate({
|
||||||
|
filter: function(feature, layer) {
|
||||||
|
return feature == features[0];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
map.addInteraction(translate);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('moves a filter-passing feature', function() {
|
||||||
|
const events = trackEvents(features[0], translate);
|
||||||
|
|
||||||
|
simulateEvent('pointermove', 10, 20);
|
||||||
|
simulateEvent('pointerdown', 10, 20);
|
||||||
|
simulateEvent('pointerdrag', 50, -40);
|
||||||
|
simulateEvent('pointerup', 50, -40);
|
||||||
|
const geometry = features[0].getGeometry();
|
||||||
|
expect(geometry).to.be.a(Point);
|
||||||
|
expect(geometry.getCoordinates()).to.eql([50, 40]);
|
||||||
|
|
||||||
|
validateEvents(events, [features[0]]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not move a filter-discarded feature', function() {
|
||||||
|
const events = trackEvents(features[0], translate);
|
||||||
|
|
||||||
|
simulateEvent('pointermove', 20, 30);
|
||||||
|
simulateEvent('pointerdown', 20, 30);
|
||||||
|
simulateEvent('pointerdrag', 50, -40);
|
||||||
|
simulateEvent('pointerup', 50, -40);
|
||||||
|
const geometry = features[1].getGeometry();
|
||||||
|
expect(geometry).to.be.a(Point);
|
||||||
|
expect(geometry.getCoordinates()).to.eql([20, -30]);
|
||||||
|
|
||||||
|
expect(events).to.be.empty();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('changes css cursor', function() {
|
describe('changes css cursor', function() {
|
||||||
let element, translate;
|
let element, translate;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user