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:
@@ -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]);
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user