优化
This commit is contained in:
@@ -252,6 +252,8 @@ export interface RenderLabelOptions {
|
||||
/** 输出格式,默认 png */
|
||||
imageFormat?: 'png' | 'jpeg';
|
||||
jpegQuality?: number;
|
||||
/** 为 false 时不裁剪到画布边界(用于拖动浮层完整显示元素) */
|
||||
clipToCanvas?: boolean;
|
||||
}
|
||||
|
||||
/** 离屏渲染标签为 PNG data URL */
|
||||
@@ -269,6 +271,7 @@ export async function renderLabelToDataUrl(options: RenderLabelOptions): Promise
|
||||
scale: scaleOption = 16,
|
||||
imageFormat = 'png',
|
||||
jpegQuality = 0.92,
|
||||
clipToCanvas = true,
|
||||
} = options;
|
||||
|
||||
const scale = scaleOption;
|
||||
@@ -295,9 +298,11 @@ export async function renderLabelToDataUrl(options: RenderLabelOptions): Promise
|
||||
}
|
||||
|
||||
ctx.save();
|
||||
ctx.beginPath();
|
||||
ctx.rect(0, 0, canvas.width, canvas.height);
|
||||
ctx.clip();
|
||||
if (clipToCanvas) {
|
||||
ctx.beginPath();
|
||||
ctx.rect(0, 0, canvas.width, canvas.height);
|
||||
ctx.clip();
|
||||
}
|
||||
|
||||
for (const elem of elements) {
|
||||
const ex = Math.round(elem.x * scale);
|
||||
|
||||
Reference in New Issue
Block a user