Skip to content

Commit 64c5806

Browse files
committed
【杨琨】【添加二三维联动-绘制功能】
1 parent fd547cc commit 64c5806

File tree

6 files changed

+33
-4
lines changed

6 files changed

+33
-4
lines changed

src/service/2DPlot/Draw/DrawPoint2D.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import DrawObject from "../../PlotBase/Draw/DrawObject";
99
import Point from "../../PlotUtilBase/Geometry/Point";
1010
import {PlotObjectFactory} from "../Shapes/PlotObjectFactory";
11+
import {addExtendLayersPlot} from "../../3DPlot/Utils/PlotUtil";
1112

1213
export default class DrawPoint2D extends DrawObject {
1314
constructor(fabricCanvas, symbol, options) {
@@ -50,6 +51,7 @@ export default class DrawPoint2D extends DrawObject {
5051
if(this._addedPlot){
5152
this._addedPlot(object);
5253
}
54+
addExtendLayersPlot(this.m_fabricCanvas._linkTool, object);
5355
this.disable();
5456
})
5557

src/service/2DPlot/Draw/DrawPolyline2D.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
*/
88
import DrawObject from '../../PlotBase/Draw/DrawObject';
99
import Point from '../../PlotUtilBase/Geometry/Point';
10-
import { PlotObjectFactory } from '../Shapes/PlotObjectFactory';
10+
import {PlotObjectFactory} from '../Shapes/PlotObjectFactory';
11+
import {addExtendLayersPlot} from "../../3DPlot/Utils/PlotUtil";
1112

1213
const _ = require('lodash');
1314
export default class DrawPolyline2D extends DrawObject {
@@ -48,16 +49,17 @@ export default class DrawPolyline2D extends DrawObject {
4849
this.m_fabricCanvas.requestRenderAll();
4950
}
5051
}
52+
5153
innerOnMouseUp(event) {
5254
if (!this.m_startDrawing) this.m_startDrawing = true;
5355

5456
const pnt = this.m_coordSys.pointToData([event.pointer.x, event.pointer.y]);
5557
const lastPnt = this.m_coords.length > 2 ? this.m_coords[this.m_coords.length - 2] : null;
5658

5759
if (lastPnt && Math.abs(pnt[0] - lastPnt.x) < 1e-4 && Math.abs(pnt[1] - lastPnt.y) < 1e-4) {
58-
this.fireFinishEvent({ plotObj2D: this.m_object });
60+
this.fireFinishEvent({plotObj2D: this.m_object});
5961
this.m_startDrawing = false;
60-
if(this._addedPlot){
62+
if (this._addedPlot) {
6163
this._addedPlot(this.m_object);
6264
}
6365
this.disable();
@@ -71,6 +73,7 @@ export default class DrawPolyline2D extends DrawObject {
7173
canvas: this.m_fabricCanvas
7274
});
7375
this.m_fabricCanvas.add(this.m_object);
76+
addExtendLayersPlot(this.m_fabricCanvas._linkTool, this.m_object);
7477
});
7578
}
7679
}

src/service/3DPlot/Draw/DrawPoint.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import DrawObject from "../../../service/PlotBase/Draw/DrawObject";
22
import {PrimitiveFactory} from "../Primitive/PrimitiveFactory";
33
import {CesiumUtil} from "../Utils/CesiumUtil";
4+
import {addExtendLayersPlot} from "../Utils/PlotUtil";
45

56
/**
67
* @class module:3DPlot.DrawPoint
@@ -67,6 +68,7 @@ export default class DrawPoint extends DrawObject {
6768
that._plotLayer._primitiveCollection.add(that._primitive);
6869

6970
that._primitive.positions = that.m_coords;
71+
addExtendLayersPlot(that._plotLayer._linkTool, that._primitive);
7072
that.disable();
7173
that.fireFinishEvent({plotObj3D: that._primitive});
7274
});

src/service/3DPlot/Draw/DrawPolyline.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import PrimitiveFactory from "../Primitive/index";
33
import {CesiumUtil} from "../Utils/CesiumUtil";
44
import GeomUtil from "../../../service/PlotUtilBase/Geometry/GeomUtil";
55
import Point from "../../../service/PlotUtilBase/Geometry/Point";
6+
import {addExtendLayersPlot} from "../Utils/PlotUtil";
67

78
function look(viewer, center, offset) {
89
if (!viewer) {
@@ -120,6 +121,7 @@ export default class DrawPolyline extends DrawObject {
120121
//双击事件,结束绘制图元
121122
handler.setInputAction((event) => {
122123
this.fireFinishEvent({ plotObj3D: this._primitive });
124+
addExtendLayersPlot(this._plotLayer._linkTool, this._primitive);
123125
this.disable();
124126
}, Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK);
125127

src/service/3DPlot/Utils/PlotUtil.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,20 @@ function getCenterByCartesian(positions) {
2929
return turf.center(turf.featureCollection(points));
3030
}
3131

32-
export {getCenter, getCenterByCartesian}
32+
/**
33+
* @description 二三维联动时,向扩展图层里面添加标绘图元
34+
* @param {Object} linkTool 二三维联动工具
35+
* @param {Object} plot 要添加的图元
36+
*/
37+
function addExtendLayersPlot(linkTool, plot) {
38+
const {_extendLayers} = linkTool;
39+
for (let i = 0; i < _extendLayers.length; i++) {
40+
if(_extendLayers[i].addPrimitiveBy2DPlotObj){
41+
_extendLayers[i].addPrimitiveBy2DPlotObj(plot);
42+
}else if(_extendLayers[i].addPlotObjectBy3DPlotObj) {
43+
_extendLayers[i].addPlotObjectBy3DPlotObj(plot);
44+
}
45+
}
46+
}
47+
48+
export {getCenter, getCenterByCartesian, addExtendLayersPlot}

src/service/PlotBase/LinkTool.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export default class LinkTool {
1616
this._plotLayer._linkTool = this;
1717
this._isLinked = true;
1818
this._mapContainer = undefined;
19+
this._extendLayers = [];
1920

2021
if (this._plotLayer instanceof PlotLayer3D) {
2122
this._mapContainer = this._plotLayer._viewer;
@@ -33,6 +34,8 @@ export default class LinkTool {
3334
_initPlotLayers() {
3435
if (!this._containers) return;
3536

37+
this._extendLayers = [];
38+
3639
for (let i = 0; i < this._containers.length; i++) {
3740
let id, type, _plotLayer, _container = this._containers[i];
3841
if (_container._container) {
@@ -66,6 +69,7 @@ export default class LinkTool {
6669
}
6770
break;
6871
}
72+
this._extendLayers.push(_plotLayer);
6973
}
7074
}
7175
}

0 commit comments

Comments
 (0)