Skip to content

Commit 0f7f76e

Browse files
committed
【杨琨】【添加二三维联动-添加删除图元功能】
1 parent 64c5806 commit 0f7f76e

File tree

4 files changed

+64
-11
lines changed

4 files changed

+64
-11
lines changed

src/service/2DPlot/PlotLayer2D.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { PlotObjectFactory } from './Shapes/PlotObjectFactory';
1212
import { createGuid } from '../PlotUtilBase/Util/Guid';
1313
import SymbolManager from '../PlotBase/SymbolManager/SymbolManager';
1414
import FabricLineUtil from './EditTool/FabricLineUtil';
15+
import {addExtendLayersPlot, removeExtendLayersPlot} from "../3DPlot/Utils/PlotUtil";
1516

1617
export default class PlotLayer2D {
1718
constructor() {
@@ -26,6 +27,9 @@ export default class PlotLayer2D {
2627
// event
2728
this._objectModifiedEventAction = this._objectModifiedEventAction.bind(this);
2829
this._eventHandlers = [];
30+
31+
//二三维联动工具
32+
this._linkTool = undefined;
2933
}
3034

3135
/**
@@ -170,6 +174,7 @@ export default class PlotLayer2D {
170174
*/
171175
add(plotObj) {
172176
this.m_plotObjects.push(plotObj);
177+
addExtendLayersPlot(this._linkTool, plotObj);
173178
if (this._fabricCanvas) {
174179
this._fabricCanvas.add(plotObj);
175180
}
@@ -187,6 +192,7 @@ export default class PlotLayer2D {
187192
}
188193
if (this._fabricCanvas) {
189194
this._fabricCanvas.remove(plotObj);
195+
removeExtendLayersPlot(this._linkTool, plotObj);
190196
}
191197
}
192198
/**

src/service/3DPlot/PlotLayer3D.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {PrimitiveFactory} from "./Primitive/PrimitiveFactory";
88
import * as turf from "@turf/turf";
99
import Point from "../PlotUtilBase/Geometry/Point";
1010
import GeomUtil from "../PlotUtilBase/Geometry/GeomUtil";
11+
import {addExtendLayersPlot, removeExtendLayersPlot} from "./Utils/PlotUtil";
1112

1213
/**
1314
* @class module:3DPlot.PlotLayer3D
@@ -54,6 +55,9 @@ class PlotLayer3D extends Observable {
5455
shapeIcon: this._shapeIcon
5556
});
5657

58+
//二三维联动工具
59+
this._linkTool = undefined;
60+
5761
this._primitiveCollection._id = this._id;
5862
let scene = this._getScene();
5963
scene.primitives.add(this._primitiveCollection);
@@ -66,6 +70,7 @@ class PlotLayer3D extends Observable {
6670
*/
6771
addPlot(plot) {
6872
this._primitiveCollection.add(plot);
73+
addExtendLayersPlot(this._linkTool, plot);
6974
return plot;
7075
}
7176

@@ -96,6 +101,7 @@ class PlotLayer3D extends Observable {
96101
removePlot(plot) {
97102
let plotLayer = this._getPlotLayer();
98103
if (plotLayer) {
104+
removeExtendLayersPlot(this._linkTool, plot);
99105
return plotLayer.remove(plot);
100106
}
101107
}

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

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,36 @@ function getCenterByCartesian(positions) {
3535
* @param {Object} plot 要添加的图元
3636
*/
3737
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);
38+
if(!linkTool) return;
39+
const {_extendLayers, _isLinked} = linkTool;
40+
if (_isLinked) {
41+
for (let i = 0; i < _extendLayers.length; i++) {
42+
if (_extendLayers[i].addPrimitiveBy2DPlotObj) {
43+
_extendLayers[i].addPrimitiveBy2DPlotObj(plot);
44+
} else if (_extendLayers[i].addPlotObjectBy3DPlotObj) {
45+
_extendLayers[i].addPlotObjectBy3DPlotObj(plot);
46+
}
4447
}
4548
}
4649
}
4750

48-
export {getCenter, getCenterByCartesian, addExtendLayersPlot}
51+
/**
52+
* @description 二三维联动时,向扩展图层里面删除标绘图元
53+
* @param {Object} linkTool 二三维联动工具
54+
* @param {Object} plot 要删除的图元
55+
*/
56+
function removeExtendLayersPlot(linkTool, plot) {
57+
if(!linkTool) return;
58+
const {_extendLayers, _isLinked} = linkTool;
59+
if (_isLinked) {
60+
for (let i = 0; i < _extendLayers.length; i++) {
61+
if (_extendLayers[i].addPrimitiveBy2DPlotObj) {
62+
_extendLayers[i].remove(plot);
63+
} else if (_extendLayers[i].addPlotObjectBy3DPlotObj) {
64+
_extendLayers[i].removePlot(plot);
65+
}
66+
}
67+
}
68+
}
69+
70+
export {getCenter, getCenterByCartesian, addExtendLayersPlot, removeExtendLayersPlot}

src/service/PlotBase/LinkTool.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,22 @@ import * as Cesium from "cesium";
88
* @author 基础平台-杨琨
99
* @param {Object} plotLayer 三维标绘图层、二维标绘图层或者图层基类
1010
* @param {Array} containers 图层容器数组
11+
* @param {Object} options 初始化参数
12+
* @param {Boolean} [isLinked = true] 是否进行联动
1113
*/
12-
export default class LinkTool {
13-
constructor(plotLayer, containers) {
14+
class LinkTool {
15+
constructor(plotLayer, containers, options) {
16+
options = options || {};
1417
this._plotLayer = plotLayer;
1518
this._containers = containers;
1619
this._plotLayer._linkTool = this;
17-
this._isLinked = true;
1820
this._mapContainer = undefined;
1921
this._extendLayers = [];
2022

23+
const {isLinked = true} = options;
24+
//是否进行联动
25+
this._isLinked = isLinked;
26+
2127
if (this._plotLayer instanceof PlotLayer3D) {
2228
this._mapContainer = this._plotLayer._viewer;
2329
} else if (this._plotLayer instanceof PlotLayer2D) {
@@ -73,4 +79,17 @@ export default class LinkTool {
7379
}
7480
}
7581
}
76-
}
82+
}
83+
84+
Object.defineProperties(LinkTool.prototype, {
85+
isLinked: {
86+
get() {
87+
return this._isLinked;
88+
},
89+
set(v) {
90+
this._isLinked = v;
91+
}
92+
}
93+
})
94+
95+
export default LinkTool;

0 commit comments

Comments
 (0)