Skip to content

Commit 06b08c8

Browse files
committed
restore line's fillWithPattern, fix symbol.linePatternFile on LineString
1 parent e9c15d3 commit 06b08c8

File tree

1 file changed

+35
-35
lines changed

1 file changed

+35
-35
lines changed

packages/maptalks/src/core/Canvas.ts

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ const defaultChars = getDefaultCharacterSet();
116116
/**
117117
* 文本是否全部是默认字符
118118
* @param chars
119-
* @returns
119+
* @returns
120120
*/
121121
function textIsDefaultChars(chars: string[]) {
122122
for (let i = 0, len = chars.length; i < len; i++) {
@@ -141,12 +141,12 @@ function reverseChars(chars: string[]) {
141141

142142
/**
143143
* 字符的旋转角度
144-
* @param p1
145-
* @param p2
146-
* @param char
147-
* @param direction
148-
* @param isDefaultChars
149-
* @returns
144+
* @param p1
145+
* @param p2
146+
* @param char
147+
* @param direction
148+
* @param isDefaultChars
149+
* @returns
150150
*/
151151
function getCharRotation(p1: Point, p2: Point, char: string, direction: string, isDefaultChars: boolean) {
152152
const x0 = p1.x, y0 = p1.y;
@@ -176,9 +176,9 @@ function getCharRotation(p1: Point, p2: Point, char: string, direction: string,
176176

177177
/**
178178
* 测量字符的大小
179-
* @param char
180-
* @param fontSize
181-
* @returns
179+
* @param char
180+
* @param fontSize
181+
* @returns
182182
*/
183183
function measureCharSize(char: string, fontSize: number) {
184184
let w = fontSize, h = fontSize;
@@ -192,9 +192,9 @@ function measureCharSize(char: string, fontSize: number) {
192192

193193
/**
194194
* 计算文本的长度
195-
* @param textName
196-
* @param fontSize
197-
* @returns
195+
* @param textName
196+
* @param fontSize
197+
* @returns
198198
*/
199199
function measureTextLength(textName: string, fontSize: number) {
200200
let textLen = 0;
@@ -220,9 +220,9 @@ function getPercentPoint(segment: segmentType, dis: number) {
220220
/**
221221
* path 分割
222222
* https://github.com/deyihu/lineseg
223-
* @param points
224-
* @param options
225-
* @returns
223+
* @param points
224+
* @param options
225+
* @returns
226226
*/
227227
function lineSeg(points: Array<Point>, options: any) {
228228
options = Object.assign({ segDistance: 1, isGeo: true }, options);
@@ -298,8 +298,8 @@ function lineSeg(points: Array<Point>, options: any) {
298298

299299
/**
300300
* 文本路径方向
301-
* @param path
302-
* @returns
301+
* @param path
302+
* @returns
303303
*/
304304
function textPathDirection(path: Array<charItemType>) {
305305
const len = path.length;
@@ -330,10 +330,10 @@ function textPathDirection(path: Array<charItemType>) {
330330

331331
/**
332332
* 获取文本沿线路径的点
333-
* @param chunk
334-
* @param chars
335-
* @param fontSize
336-
* @returns
333+
* @param chunk
334+
* @param chars
335+
* @param fontSize
336+
* @returns
337337
*/
338338
function getTextPath(chunk: Array<Point>, chars: string[], fontSize: number, globalCollisonIndex: CollisionIndex) {
339339
const total = pathDistance(chunk);
@@ -1122,12 +1122,12 @@ const Canvas = {
11221122
/**
11231123
* mock gradient path
11241124
* 利用颜色插值来模拟渐变的Path
1125-
* @param ctx
1126-
* @param points
1127-
* @param lineDashArray
1128-
* @param lineOpacity
1129-
* @param isRing
1130-
* @returns
1125+
* @param ctx
1126+
* @param points
1127+
* @param lineDashArray
1128+
* @param lineOpacity
1129+
* @param isRing
1130+
* @returns
11311131
*/
11321132
_gradientPath(ctx: CanvasRenderingContext2D, points, lineDashArray, lineOpacity, isRing = false) {
11331133
if (!isNumber(lineOpacity)) {
@@ -1235,13 +1235,13 @@ const Canvas = {
12351235
function fillWithPattern(p1, p2) {
12361236
const degree = computeDegree(p1.x, p1.y, p2.x, p2.y);
12371237
ctx.save();
1238-
// const cosd = Math.cos(degree);
1239-
// if (Math.abs(cosd) < 1E-7) {
1240-
// //a vertical line
1241-
// ctx.translate(p1.x - ctx.lineWidth / 2, p1.y);
1242-
// } else {
1243-
// ctx.translate(p1.x, p1.y - ctx.lineWidth / 2 / cosd);
1244-
// }
1238+
const cosd = Math.cos(degree);
1239+
if (Math.abs(cosd) < 1E-7) {
1240+
//a vertical line
1241+
ctx.translate(p1.x - ctx.lineWidth / 2, p1.y);
1242+
} else {
1243+
ctx.translate(p1.x, p1.y - ctx.lineWidth / 2 / cosd);
1244+
}
12451245
ctx.rotate(degree);
12461246
Canvas._stroke(ctx, lineOpacity);
12471247
ctx.restore();

0 commit comments

Comments
 (0)