diff --git a/ShadowEditor.Web/locales/zh-CN.json b/ShadowEditor.Web/locales/zh-CN.json index 163b4691..224d6ec6 100644 --- a/ShadowEditor.Web/locales/zh-CN.json +++ b/ShadowEditor.Web/locales/zh-CN.json @@ -963,5 +963,6 @@ "Backup Database": "备份数据库", "Backup database successfully!": "备份数据库成功!", "mongodump.exe is not existed.": "mongodump.exe不存在。", - "Backing up, please wait.": "正在备份,请稍后。" + "Backing up, please wait.": "正在备份,请稍后。", + "Start area measurement.": "开始面积测量。" } \ No newline at end of file diff --git a/ShadowEditor.Web/src/editor/toolbar/MeasureTools.jsx b/ShadowEditor.Web/src/editor/toolbar/MeasureTools.jsx index 6ddea92f..403b3826 100644 --- a/ShadowEditor.Web/src/editor/toolbar/MeasureTools.jsx +++ b/ShadowEditor.Web/src/editor/toolbar/MeasureTools.jsx @@ -1,5 +1,6 @@ import { ToolbarSeparator, IconButton } from '../../third_party'; import DistanceTool from '../tools/DistanceTool'; +import AreaTool from '../tools/AreaTool'; /** * 测量工具 @@ -18,6 +19,7 @@ class MeasureTools extends React.Component { this.handleMeasureDistance = this.handleMeasureDistance.bind(this); this.handleEndMeasureDistance = this.handleEndMeasureDistance.bind(this); this.handleMeasureArea = this.handleMeasureArea.bind(this); + this.handleEndMeasureArea = this.handleEndMeasureArea.bind(this); this.handleMeasureAngle = this.handleMeasureAngle.bind(this); } @@ -70,7 +72,21 @@ class MeasureTools extends React.Component { // --------------------------- 面积测量 ------------------------------------- handleMeasureArea() { + if (this.areaTool === undefined) { + this.areaTool = new AreaTool(); + this.areaTool.on(`end.${this.id}`, this.handleEndMeasureArea); + } + this.areaTool.start(); + this.setState({ + areaToolEnabled: true + }); + app.toast(_t('Start area measurement.')); + } + handleEndMeasureArea() { + this.setState({ + areaToolEnabled: false + }); } // --------------------------- 角度测量 --------------------------------------- diff --git a/ShadowEditor.Web/src/editor/tools/AreaTool.js b/ShadowEditor.Web/src/editor/tools/AreaTool.js index 8c37afbe..a0c4713d 100644 --- a/ShadowEditor.Web/src/editor/tools/AreaTool.js +++ b/ShadowEditor.Web/src/editor/tools/AreaTool.js @@ -2,7 +2,7 @@ import BaseTool from './BaseTool'; import UnscaledText from '../../object/text/UnscaledText'; /** - * 距离测量工具 + * 面积测量工具 */ class AreaTool extends BaseTool { constructor() { @@ -105,7 +105,7 @@ class AreaTool extends BaseTool { dist += Math.sqrt( (this.positions[i] - this.positions[i - 3]) ** 2, (this.positions[i + 1] - this.positions[i - 2]) ** 2, - (this.positions[i + 2] - this.positions[i - 1]) ** 2, + (this.positions[i + 2] - this.positions[i - 1]) ** 2 ); }