Merge pull request #3065 from tsauerwein/webgl-point-hit-detection

Add hit-detection support for WebGL
This commit is contained in:
Tobias Sauerwein
2015-01-22 10:19:37 +01:00
17 changed files with 609 additions and 156 deletions

View File

@@ -16,9 +16,15 @@ describe('ol.render.webgl.ImageReplay', function() {
imageStyle.getImage = function() {
return image;
};
imageStyle.getHitDetectionImage = function() {
return image;
};
imageStyle.getImageSize = function() {
return [512, 512];
};
imageStyle.getHitDetectionImageSize = function() {
return [512, 512];
};
imageStyle.getOrigin = function() {
return [200, 200];
};
@@ -59,14 +65,20 @@ describe('ol.render.webgl.ImageReplay', function() {
expect(replay.width_).to.be(256);
expect(replay.images_).to.have.length(1);
expect(replay.groupIndices_).to.have.length(0);
expect(replay.hitDetectionImages_).to.have.length(1);
expect(replay.hitDetectionGroupIndices_).to.have.length(0);
replay.setImageStyle(imageStyle1);
expect(replay.images_).to.have.length(1);
expect(replay.groupIndices_).to.have.length(0);
expect(replay.hitDetectionImages_).to.have.length(1);
expect(replay.hitDetectionGroupIndices_).to.have.length(0);
replay.setImageStyle(imageStyle2);
expect(replay.images_).to.have.length(2);
expect(replay.groupIndices_).to.have.length(1);
expect(replay.hitDetectionImages_).to.have.length(2);
expect(replay.hitDetectionGroupIndices_).to.have.length(1);
});
});

View File

@@ -191,7 +191,7 @@ describe('ol.style.AtlasManager', function() {
expect(info).to.eql({
offsetX: 1, offsetY: 1, image: manager.atlases_[0].canvas_,
hitOffsetX: undefined, hitOffsetY: undefined, hitImage: undefined});
hitImage: manager.hitAtlases_[0].canvas_});
expect(manager.getInfo('1')).to.eql(info);
});
@@ -202,7 +202,6 @@ describe('ol.style.AtlasManager', function() {
expect(info).to.eql({
offsetX: 1, offsetY: 1, image: manager.atlases_[0].canvas_,
hitOffsetX: 1, hitOffsetY: 1,
hitImage: manager.hitAtlases_[0].canvas_});
expect(manager.getInfo('1')).to.eql(info);
@@ -258,6 +257,20 @@ describe('ol.style.AtlasManager', function() {
expect(manager.add('2', 2048, 2048, defaultRender, defaultRender))
.to.eql(null);
});
it('always has the same offset for the hit-detection', function() {
var manager = new ol.style.AtlasManager({initialSize: 128});
// add one image without hit-detection callback
var info = manager.add('1', 32, 32, defaultRender);
// add then one with hit-detection callback
info = manager.add('2', 32, 32, defaultRender, defaultRender);
expect(info).to.eql({
offsetX: 34, offsetY: 1, image: manager.atlases_[0].canvas_,
hitImage: manager.hitAtlases_[0].canvas_});
expect(manager.getInfo('2')).to.eql(info);
});
});
describe('#getInfo', function() {

View File

@@ -16,7 +16,6 @@ describe('ol.style.Circle', function() {
expect(style.getImage()).to.not.be(style.getHitDetectionImage());
expect(style.getHitDetectionImage()).to.be.an(HTMLCanvasElement);
expect(style.getHitDetectionImageSize()).to.eql([21, 21]);
expect(style.getHitDetectionOrigin()).to.eql([0, 0]);
});
it('creates a canvas if no atlas is used (fill-style)', function() {
@@ -35,7 +34,6 @@ describe('ol.style.Circle', function() {
expect(style.getImage()).to.be(style.getHitDetectionImage());
expect(style.getHitDetectionImage()).to.be.an(HTMLCanvasElement);
expect(style.getHitDetectionImageSize()).to.eql([21, 21]);
expect(style.getHitDetectionOrigin()).to.eql([0, 0]);
});
it('adds itself to an atlas manager (no fill-style)', function() {
@@ -50,7 +48,6 @@ describe('ol.style.Circle', function() {
expect(style.getImage()).to.not.be(style.getHitDetectionImage());
expect(style.getHitDetectionImage()).to.be.an(HTMLCanvasElement);
expect(style.getHitDetectionImageSize()).to.eql([512, 512]);
expect(style.getHitDetectionOrigin()).to.eql([1, 1]);
});
it('adds itself to an atlas manager (fill-style)', function() {
@@ -71,7 +68,6 @@ describe('ol.style.Circle', function() {
expect(style.getImage()).to.be(style.getHitDetectionImage());
expect(style.getHitDetectionImage()).to.be.an(HTMLCanvasElement);
expect(style.getHitDetectionImageSize()).to.eql([512, 512]);
expect(style.getHitDetectionOrigin()).to.eql([1, 1]);
});
});

View File

@@ -49,7 +49,6 @@ describe('ol.style.RegularShape', function() {
expect(style.getImage()).to.not.be(style.getHitDetectionImage());
expect(style.getHitDetectionImage()).to.be.an(HTMLCanvasElement);
expect(style.getHitDetectionImageSize()).to.eql([21, 21]);
expect(style.getHitDetectionOrigin()).to.eql([0, 0]);
});
it('creates a canvas if no atlas is used (fill-style)', function() {
@@ -68,7 +67,6 @@ describe('ol.style.RegularShape', function() {
expect(style.getImage()).to.be(style.getHitDetectionImage());
expect(style.getHitDetectionImage()).to.be.an(HTMLCanvasElement);
expect(style.getHitDetectionImageSize()).to.eql([21, 21]);
expect(style.getHitDetectionOrigin()).to.eql([0, 0]);
});
it('adds itself to an atlas manager (no fill-style)', function() {
@@ -84,7 +82,6 @@ describe('ol.style.RegularShape', function() {
expect(style.getImage()).to.not.be(style.getHitDetectionImage());
expect(style.getHitDetectionImage()).to.be.an(HTMLCanvasElement);
expect(style.getHitDetectionImageSize()).to.eql([512, 512]);
expect(style.getHitDetectionOrigin()).to.eql([1, 1]);
});
it('adds itself to an atlas manager (fill-style)', function() {
@@ -105,7 +102,6 @@ describe('ol.style.RegularShape', function() {
expect(style.getImage()).to.be(style.getHitDetectionImage());
expect(style.getHitDetectionImage()).to.be.an(HTMLCanvasElement);
expect(style.getHitDetectionImageSize()).to.eql([512, 512]);
expect(style.getHitDetectionOrigin()).to.eql([1, 1]);
});
});