Skip to content

Commit a685b39

Browse files
committed
【杨琨】【颜色修改】
1 parent 843a125 commit a685b39

File tree

3 files changed

+94
-56
lines changed

3 files changed

+94
-56
lines changed

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@ import {PrimitiveFactory} from "../Primitive/PrimitiveFactory";
1212
import {CesiumUtil} from "../Utils/CesiumUtil";
1313

1414
export default class DrawPoint extends DrawObject {
15-
constructor(viewer, symbol, plotLayer) {
15+
constructor(viewer, symbol, plotLayer, options) {
1616
super();
1717
this._viewer = viewer;
1818
this._symbol = symbol;
1919
this.m_coords = [];
2020
this._primitive = null;
2121
this._plotLayer = plotLayer;
22+
//绘制完成回调函数
23+
const {addedPlot} = options;
24+
this._addedPlot = addedPlot;
2225
}
2326

2427
addHooks() {
@@ -35,20 +38,20 @@ export default class DrawPoint extends DrawObject {
3538
if (!worldPos) return;
3639

3740
symbol.getElement().then(function (res) {
38-
const {classificationType, id} = that._symbol;
41+
const {classificationType} = that._symbol;
3942
res.classificationType = classificationType;
4043
const {style} = that._symbol;
4144
if(style && style.nodeStyles){
4245
res.initNodeStyles(style.nodeStyles);
4346
}
44-
if(id){
45-
res.featureId = id;
46-
}
4747
that._primitive = PrimitiveFactory.createInstance(symbol.type, {
4848
positions: that.m_coords,
4949
element: res
5050
});
51-
that._primitive.id = id;
51+
that._primitive.id = res.featureId;
52+
if(that._addedPlot){
53+
that._addedPlot(that._primitive);
54+
}
5255
const lnglat = CesiumUtil.cartesian3ToDegrees(
5356
viewer.scene.globe.ellipsoid,
5457
worldPos
@@ -67,8 +70,9 @@ export default class DrawPoint extends DrawObject {
6770

6871
removeHooks() {
6972
const handler = this._handler;
70-
// handler.removeInputAction();
7173
handler.destroy();
7274
this._handler = null;
75+
this._isAdded = false;
76+
this.m_coords = [];
7377
}
7478
}

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

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function look(viewer, center, offset) {
3232
}
3333

3434
export default class DrawPolyline extends DrawObject {
35-
constructor(viewer, symbol, plotLayer) {
35+
constructor(viewer, symbol, plotLayer, options) {
3636
super();
3737
this.m_coords = [];
3838
this._viewer = viewer;
@@ -41,14 +41,22 @@ export default class DrawPolyline extends DrawObject {
4141
this._isAdded = false;
4242
this._plotLayer = plotLayer;
4343
this.uuid = Math.random() * 10000000;
44+
//绘制完成回调函数
45+
const {addedPlot} = options;
46+
this._addedPlot = addedPlot;
4447
}
4548

49+
/**
50+
* @description 添加点击事件
51+
* @private
52+
*/
4653
addHooks() {
4754
const viewer = this._viewer;
4855
const symbol = this._symbol;
4956
const handler = new Cesium.ScreenSpaceEventHandler(viewer.canvas);
5057
let that = this;
5158

59+
//单击事件,开始绘制图元
5260
handler.setInputAction((event) => {
5361
const worldPos = viewer.scene.globe.pick(
5462
viewer.camera.getPickRay(event.position),
@@ -58,23 +66,27 @@ export default class DrawPolyline extends DrawObject {
5866
if (!worldPos) return;
5967

6068
symbol.getElement().then(function (res) {
61-
if (!that._isAdded) {
62-
const {classificationType, id} = that._symbol;
69+
if (!that._isAdded && that._handler) {
70+
const {classificationType} = that._symbol;
6371
res.classificationType = classificationType;
6472
const {style} = that._symbol;
6573
if(style && style.nodeStyles){
6674
res.initNodeStyles(style.nodeStyles);
6775
}
68-
if(id){
69-
res.featureId = id;
70-
}
7176
that._primitive = PrimitiveFactory.createInstance(symbol.type, {
7277
positions: that.m_coords,
7378
element: res,
7479
});
75-
that._primitive.id = id;
80+
that._primitive.id = res.featureId;
7681
that._isAdded = true;
7782
that._plotLayer._primitiveCollection.add(that._primitive);
83+
if(that._addedPlot){
84+
that._addedPlot(that._primitive);
85+
}
86+
}
87+
88+
if(!that._handler){
89+
return;
7890
}
7991

8092
const lnglat = CesiumUtil.cartesian3ToDegrees(
@@ -102,6 +114,7 @@ export default class DrawPolyline extends DrawObject {
102114
});
103115
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
104116

117+
//双击事件,结束绘制图元
105118
handler.setInputAction((event) => {
106119
this.fireFinishEvent({ plotObj3D: this._primitive });
107120
this.disable();
@@ -117,8 +130,9 @@ export default class DrawPolyline extends DrawObject {
117130
look(this.viewer, this.m_coords[this.m_coords.length - 1], 1000);
118131
}
119132

120-
// handler.removeInputAction();
121133
handler.destroy();
122134
this._handler = null;
135+
this._isAdded = false;
136+
this.m_coords = [];
123137
}
124138
}

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

Lines changed: 61 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,55 +4,75 @@ import {DrawPlotObjectFactory3D} from "./DrawPlotObjectFactory3D";
44
* @class module:3DPlot.DrawTool
55
* @description 行业标绘绘制工具
66
* @author 基础平台-杨琨
7-
* @param {PlotLayer3D} layer
7+
* @param {PlotLayer3D} layer 标绘图层
8+
* @param {Object} options 绘制参数
89
*/
910
class DrawTool {
10-
constructor(layer) {
11-
//标绘图层
12-
this._plotLayer = layer;
13-
//绘制工具
14-
this._drawTool = undefined;
15-
}
16-
17-
/**
18-
* @function module:3DPlot.DrawTool.setLayer
19-
* @description 设置要作用的标绘图层
20-
* @param layer - {PlotLayer3D} 必选项,标绘图层
21-
*/
22-
setLayer(layer) {
23-
this._plotLayer = layer;
24-
}
25-
26-
/**
27-
* @function module:3DPlot.DrawTool.drawPlot
28-
* @description 绘制标绘图元
29-
* @param symbol - {Object} 必选项,标绘图元的符号对象
30-
*/
31-
drawPlot(symbol) {
32-
if (!this._drawTool) {
33-
this._drawTool = DrawPlotObjectFactory3D.createInstance(
34-
symbol.type,
35-
this._plotLayer._viewer,
36-
symbol,
37-
this._plotLayer
38-
);
11+
constructor(layer, options) {
12+
//标绘图层
13+
this._plotLayer = layer;
14+
//绘制工具
15+
this._drawTool = undefined;
16+
//SVG的url
17+
this._symbolUrl = undefined;
18+
//绘制参数
19+
this._options = options;
20+
}
3921

22+
/**
23+
* @function module:3DPlot.DrawTool.setLayer
24+
* @description 设置要作用的标绘图层
25+
* @param layer - {PlotLayer3D} 必选项,标绘图层
26+
*/
27+
setLayer(layer) {
28+
this._plotLayer = layer;
4029
}
4130

42-
this._drawTool.enable();
43-
}
31+
/**
32+
* @function module:3DPlot.DrawTool.drawPlot
33+
* @description 绘制标绘图元
34+
* @param symbol - {Object} 必选项,标绘图元的符号对象
35+
*/
36+
drawPlot(symbol) {
37+
//一直是原有符号
38+
if (!this._drawTool) {
39+
this._symbolUrl = symbol.src;
40+
this._drawTool = DrawPlotObjectFactory3D.createInstance(
41+
symbol.type,
42+
this._plotLayer._viewer,
43+
symbol,
44+
this._plotLayer,
45+
this._options
46+
);
47+
}
48+
49+
//换新符号
50+
if (symbol.should !== this._symbolUrl) {
51+
this._symbolUrl = symbol.src;
52+
this._drawTool = DrawPlotObjectFactory3D.createInstance(
53+
symbol.type,
54+
this._plotLayer._viewer,
55+
symbol,
56+
this._plotLayer,
57+
this._options
58+
);
59+
}
4460

45-
/**
46-
* @function module:3DPlot.DrawTool.stopDraw
47-
* @description 停止绘制
48-
*/
49-
stopDraw() {
50-
if (this._drawTool) {
51-
this._drawTool.disable();
61+
//开始绘制
62+
this._drawTool.enable();
5263
}
5364

54-
this._drawTool = undefined;
55-
}
65+
/**
66+
* @function module:3DPlot.DrawTool.stopDraw
67+
* @description 停止绘制
68+
*/
69+
stopDraw() {
70+
if (this._drawTool) {
71+
this._drawTool.disable();
72+
}
73+
74+
this._drawTool = undefined;
75+
}
5676
}
5777

5878
export default DrawTool;

0 commit comments

Comments
 (0)