Skip to content

Commit

Permalink
fix vertical line's pattern, close #977
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzhenn committed Aug 5, 2019
1 parent a1da1da commit 9ad5b93
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 7 additions & 1 deletion src/core/Canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,13 @@ const Canvas = {
function fillWithPattern(p1, p2) {
const degree = computeDegree(p1.x, p1.y, p2.x, p2.y);
ctx.save();
ctx.translate(p1.x, p1.y - ctx.lineWidth / 2 / Math.cos(degree));
const cosd = Math.cos(degree);
if (Math.abs(cosd) < 1E-7) {
//a vertical line
ctx.translate(p1.x - ctx.lineWidth / 2, p1.y);
} else {
ctx.translate(p1.x, p1.y - ctx.lineWidth / 2 / cosd);
}
ctx.rotate(degree);
Canvas._stroke(ctx, lineOpacity);
ctx.restore();
Expand Down
6 changes: 3 additions & 3 deletions test/geometry/symbol/StrokeAndFillSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('StrokeAndFillSpec', function () {
});

it('line pattern', function (done) {
var line = new maptalks.LineString([center, center.add(0.0001, 0)], {
var line = new maptalks.LineString([center, center.add(0, -0.0001)], {
symbol:{
'linePatternFile' : 'resources/pattern2.png',
'lineOpacity' : 1,
Expand All @@ -60,7 +60,7 @@ describe('StrokeAndFillSpec', function () {
});
var v = new maptalks.VectorLayer('v').addTo(map);
v.once('layerload', function () {
expect(v).not.to.be.painted(0, 0, [0, 0, 0]);
expect(v).to.be.painted(0, 0);
done();
});
v.addGeometry(line);
Expand All @@ -79,7 +79,7 @@ describe('StrokeAndFillSpec', function () {
});
var v = new maptalks.VectorLayer('v').addTo(map);
v.once('layerload', function () {
expect(v).not.to.be.painted(0, 0, [255, 255, 255]);
expect(v).to.be.painted(0, 0);
done();
});
v.addGeometry(line);
Expand Down

0 comments on commit 9ad5b93

Please sign in to comment.