mirror of
https://github.com/motajs/template.git
synced 2026-04-12 15:11:10 +08:00
chore: 调整地图文字对象结构
This commit is contained in:
parent
0b6cecda60
commit
838f33347d
@ -128,17 +128,17 @@ export class OnMapTextRenderer
|
||||
const baseX = area.mapX * this.renderer.cellWidth;
|
||||
const baseY = area.mapY * this.renderer.cellHeight;
|
||||
for (const renderable of area.getRenderables()) {
|
||||
const x = baseX + renderable.px - renderWidth / 2;
|
||||
const y = renderHeight / 2 - (baseY + renderable.py);
|
||||
const x = baseX + (renderable.px ?? 0) - renderWidth / 2;
|
||||
const y = renderHeight / 2 - (baseY + (renderable.py ?? 0));
|
||||
ctx.font = renderable.font.string();
|
||||
ctx.textAlign = renderable.textAlign;
|
||||
ctx.textBaseline = renderable.textBaseline;
|
||||
if (renderable.strokeStyle) {
|
||||
ctx.strokeStyle = renderable.strokeStyle;
|
||||
ctx.textAlign = renderable.textAlign ?? 'left';
|
||||
ctx.textBaseline = renderable.textBaseline ?? 'top';
|
||||
if (renderable.stroke) {
|
||||
ctx.strokeStyle = renderable.strokeStyle ?? 'black';
|
||||
ctx.strokeText(renderable.text, x, -y);
|
||||
}
|
||||
if (renderable.fillStyle) {
|
||||
ctx.fillStyle = renderable.fillStyle;
|
||||
if (renderable.fill) {
|
||||
ctx.fillStyle = renderable.fillStyle ?? 'white';
|
||||
ctx.fillText(renderable.text, x, -y);
|
||||
}
|
||||
}
|
||||
|
||||
@ -186,18 +186,22 @@ export interface IMapTextRenderable {
|
||||
readonly text: string;
|
||||
/** 文本字体 */
|
||||
readonly font: Font;
|
||||
/** 是否填充 */
|
||||
readonly fill?: boolean;
|
||||
/** 是否描边 */
|
||||
readonly stroke?: boolean;
|
||||
/** 文本填充样式 */
|
||||
readonly fillStyle: CanvasStyle;
|
||||
readonly fillStyle?: CanvasStyle;
|
||||
/** 文本描边样式 */
|
||||
readonly strokeStyle: CanvasStyle;
|
||||
readonly strokeStyle?: CanvasStyle;
|
||||
/** 文本横坐标,注意 {@link IMapTextArea.addTextRenderable} 的相对关系 */
|
||||
readonly px: number;
|
||||
readonly px?: number;
|
||||
/** 文本纵坐标,注意 {@link IMapTextArea.addTextRenderable} 的相对关系 */
|
||||
readonly py: number;
|
||||
readonly py?: number;
|
||||
/** 文本横向对齐方式 */
|
||||
readonly textAlign: CanvasTextAlign;
|
||||
readonly textAlign?: CanvasTextAlign;
|
||||
/** 文本纵向对齐方式 */
|
||||
readonly textBaseline: CanvasTextBaseline;
|
||||
readonly textBaseline?: CanvasTextBaseline;
|
||||
}
|
||||
|
||||
export interface IMapTextRequested {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user