Listen only to change event triggered by the feature

ol.Feature catch change event from its geometry and trigger a change
event itself. ol.Feature will also trigger change event when its
geometryName has changed
This commit is contained in:
Thomas Chandelle
2017-01-20 11:52:50 +01:00
parent 7408a09b83
commit 8a440b0c20
2 changed files with 55 additions and 42 deletions

View File

@@ -122,13 +122,57 @@ describe('ol.interaction.Snap', function() {
var event = {
pixel: [7 + width / 2, height / 2 - 4],
coorinate: [7, 4],
coordinate: [7, 4],
map: map
};
ol.interaction.Snap.handleEvent_.call(snapInteraction, event);
expect(event.coordinate).to.eql([10, 0]);
});
it('handle geometry changes', function() {
var line = new ol.Feature(new ol.geom.LineString([[-10, 0], [0, 0]]));
var snapInteraction = new ol.interaction.Snap({
features: new ol.Collection([line]),
pixelTolerance: 5,
edge: false
});
snapInteraction.setMap(map);
line.getGeometry().setCoordinates([[-10, 0], [10, 0]]);
var event = {
pixel: [7 + width / 2, height / 2 - 4],
coordinate: [7, 4],
map: map
};
ol.interaction.Snap.handleEvent_.call(snapInteraction, event);
expect(event.coordinate).to.eql([10, 0]);
});
it('handle geometry name changes', function() {
var line = new ol.Feature({
geometry: new ol.geom.LineString([[-10, 0], [0, 0]]),
alt_geometry: new ol.geom.LineString([[-10, 0], [10, 0]])
});
var snapInteraction = new ol.interaction.Snap({
features: new ol.Collection([line]),
pixelTolerance: 5,
edge: false
});
snapInteraction.setMap(map);
line.setGeometryName('alt_geometry');
var event = {
pixel: [7 + width / 2, height / 2 - 4],
coordinate: [7, 4],
map: map
};
ol.interaction.Snap.handleEvent_.call(snapInteraction, event);
expect(event.coordinate).to.eql([10, 0]);
});
});
});