Added hitTolerance test

This commit is contained in:
simonseyock
2016-09-28 12:49:24 +02:00
committed by simonseyock
parent e95778e47f
commit 85893646c4

View File

@@ -30,7 +30,7 @@ describe('ol.renderer.canvas.Map', function() {
var layer, map, target;
beforeEach(function() {
beforeEach(function(done) {
target = document.createElement('div');
target.style.width = '100px';
target.style.height = '100px';
@@ -42,6 +42,14 @@ describe('ol.renderer.canvas.Map', function() {
zoom: 0
})
});
// 1 x 1 pixel black icon
var img = document.createElement('img');
img.onload = function() {
done();
};
img.src = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAAAAAA6fptVAAAACklEQVR4nGNiAAAABgADNjd8qAAAAABJRU5ErkJggg==';
layer = new ol.layer.Vector({
source: new ol.source.Vector({
features: [
@@ -49,6 +57,12 @@ describe('ol.renderer.canvas.Map', function() {
geometry: new ol.geom.Point([0, 0])
})
]
}),
style: new ol.style.Style({
image: new ol.style.Icon({
img : img,
imgSize: [1, 1]
})
})
});
});
@@ -113,6 +127,39 @@ describe('ol.renderer.canvas.Map', function() {
}).to.not.throwException();
});
it('calls callback for clicks inside of the hitTolerance', function() {
map.addLayer(layer);
map.renderSync();
var cb1 = sinon.spy();
var cb2 = sinon.spy();
var pixel = map.getPixelFromCoordinate([0, 0]);
var pixelsInside = [
[pixel[0] + 9, pixel[1]],
[pixel[0] - 9, pixel[1]],
[pixel[0], pixel[1] + 9],
[pixel[0], pixel[1] - 9]
];
var pixelsOutside = [
[pixel[0] + 9, pixel[1] + 9],
[pixel[0] - 9, pixel[1] + 9],
[pixel[0] + 9, pixel[1] - 9],
[pixel[0] - 9, pixel[1] - 9]
];
for (var i = 0; i < 4; i++) {
map.forEachFeatureAtPixel(pixelsInside[i], {hitTolerance:10}, cb1);
}
expect(cb1.callCount).to.be(4);
expect(cb1.firstCall.args[1]).to.be(layer);
for (var j = 0; j < 4; j++) {
map.forEachFeatureAtPixel(pixelsOutside[j], {hitTolerance:10}, cb2);
}
expect(cb2).not.to.be.called();
});
});
describe('#renderFrame()', function() {