Bail out when there is no fill and stroke

This commit is contained in:
Andreas Hocevar
2016-08-24 12:04:50 +02:00
parent 30ed4a29c8
commit 65d03bfbfb
2 changed files with 34 additions and 9 deletions

View File

@@ -1202,12 +1202,16 @@ ol.inherits(ol.render.canvas.PolygonReplay, ol.render.canvas.Replay);
*/ */
ol.render.canvas.PolygonReplay.prototype.drawFlatCoordinatess_ = function(flatCoordinates, offset, ends, stride) { ol.render.canvas.PolygonReplay.prototype.drawFlatCoordinatess_ = function(flatCoordinates, offset, ends, stride) {
var state = this.state_; var state = this.state_;
var fill = state.fillStyle !== undefined;
var stroke = state.strokeStyle != undefined;
var numEnds = ends.length;
if (!fill && !stroke) {
return ends[numEnds - 1];
}
var beginPathInstruction = [ol.render.canvas.Instruction.BEGIN_PATH]; var beginPathInstruction = [ol.render.canvas.Instruction.BEGIN_PATH];
this.instructions.push(beginPathInstruction); this.instructions.push(beginPathInstruction);
this.hitDetectionInstructions.push(beginPathInstruction); this.hitDetectionInstructions.push(beginPathInstruction);
var stroke = state.strokeStyle != undefined; for (var i = 0; i < numEnds; ++i) {
var i, ii;
for (i = 0, ii = ends.length; i < ii; ++i) {
var end = ends[i]; var end = ends[i];
var myBegin = this.coordinates.length; var myBegin = this.coordinates.length;
var myEnd = this.appendFlatCoordinates(flatCoordinates, offset, end, stride, var myEnd = this.appendFlatCoordinates(flatCoordinates, offset, end, stride,
@@ -1231,7 +1235,7 @@ ol.render.canvas.PolygonReplay.prototype.drawFlatCoordinatess_ = function(flatCo
// FIXME or all polygons together? // FIXME or all polygons together?
var fillInstruction = [ol.render.canvas.Instruction.FILL]; var fillInstruction = [ol.render.canvas.Instruction.FILL];
this.hitDetectionInstructions.push(fillInstruction); this.hitDetectionInstructions.push(fillInstruction);
if (state.fillStyle !== undefined) { if (fill) {
this.instructions.push(fillInstruction); this.instructions.push(fillInstruction);
} }
if (stroke) { if (stroke) {

View File

@@ -108,14 +108,35 @@ describe('ol.render.canvas.LineStringReplay', function() {
describe('ol.render.canvas.PolygonReplay', function() { describe('ol.render.canvas.PolygonReplay', function() {
var replay;
beforeEach(function() {
var tolerance = 1;
var extent = [-180, -90, 180, 90];
var resolution = 10;
replay = new ol.render.canvas.PolygonReplay(tolerance, extent,
resolution);
});
describe('#drawFlatCoordinatess_()', function() {
it('returns correct offset', function() {
var coords = [1, 2, 3, 4, 5, 6, 1, 2, 1, 2, 3, 4, 5, 6, 1, 2];
var ends = [7, 14];
var stroke = new ol.style.Stroke({
width: 5
});
replay.setFillStrokeStyle(null, stroke);
var offset = replay.drawFlatCoordinatess_(coords, 0, ends, 2);
expect(offset).to.be(14);
replay.setFillStrokeStyle(null, null);
offset = replay.drawFlatCoordinatess_(coords, 0, ends, 2);
expect(offset).to.be(14);
});
});
describe('#getBufferedMaxExtent()', function() { describe('#getBufferedMaxExtent()', function() {
it('buffers the max extent to accommodate stroke width', function() { it('buffers the max extent to accommodate stroke width', function() {
var tolerance = 1;
var extent = [-180, -90, 180, 90];
var resolution = 10;
var replay = new ol.render.canvas.PolygonReplay(tolerance, extent,
resolution);
var stroke = new ol.style.Stroke({ var stroke = new ol.style.Stroke({
width: 5 width: 5
}); });