Merge pull request #4339 from bartvde/issue-4337

Make sure drawImage width and height are not too big
This commit is contained in:
Bart van den Eijnden
2015-10-29 17:17:20 +01:00
3 changed files with 14 additions and 3 deletions
+4 -2
View File
@@ -343,8 +343,10 @@ ol.render.canvas.Replay.prototype.replay_ = function(
context.globalAlpha = alpha * opacity; context.globalAlpha = alpha * opacity;
} }
context.drawImage(image, originX, originY, width, height, var w = width - originX;
x, y, width * pixelRatio, height * pixelRatio); var h = height - originY;
context.drawImage(image, originX, originY, w, h, x, y,
w * pixelRatio, h * pixelRatio);
if (opacity != 1) { if (opacity != 1) {
context.globalAlpha = alpha; context.globalAlpha = alpha;
Binary file not shown.

After

Width:  |  Height:  |  Size: 838 B

+10 -1
View File
@@ -30,7 +30,7 @@ describe('ol.rendering.style.Icon', function() {
disposeMap(map); disposeMap(map);
}); });
function createFeatures(callback) { function createFeatures(callback, offset) {
var feature; var feature;
feature = new ol.Feature({ feature = new ol.Feature({
geometry: new ol.geom.Point([0, 0]) geometry: new ol.geom.Point([0, 0])
@@ -44,6 +44,7 @@ describe('ol.rendering.style.Icon', function() {
anchorXUnits: 'fraction', anchorXUnits: 'fraction',
anchorYUnits: 'pixels', anchorYUnits: 'pixels',
opacity: 0.75, opacity: 0.75,
offset: offset,
scale: 0.5, scale: 0.5,
img: img, img: img,
imgSize: [32, 48] imgSize: [32, 48]
@@ -63,6 +64,14 @@ describe('ol.rendering.style.Icon', function() {
}); });
}); });
it('tests the canvas renderer with an offset', function(done) {
map = createMap('canvas');
createFeatures(function() {
expectResemble(map, 'spec/ol/style/expected/icon-canvas-offset.png',
IMAGE_TOLERANCE, done);
}, [10, 10]);
});
it('tests the WebGL renderer', function(done) { it('tests the WebGL renderer', function(done) {
assertWebGL(); assertWebGL();
map = createMap('webgl'); map = createMap('webgl');