Skip to content

Commit 5c1ed8e

Browse files
author
zhaokai
committed
Merge branch 'webclient_plot' of github.com:MapGIS/WebClient-JavaScript into webclient_plot
2 parents 22e60f9 + a685b39 commit 5c1ed8e

File tree

7 files changed

+778
-591
lines changed

7 files changed

+778
-591
lines changed

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

Lines changed: 12 additions & 6 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() {
@@ -38,15 +41,17 @@ export default class DrawPoint extends DrawObject {
3841
const {classificationType} = that._symbol;
3942
res.classificationType = classificationType;
4043
const {style} = that._symbol;
41-
if(style){
42-
res.initNodeStyles(style);
44+
if(style && style.nodeStyles){
45+
res.initNodeStyles(style.nodeStyles);
4346
}
44-
4547
that._primitive = PrimitiveFactory.createInstance(symbol.type, {
4648
positions: that.m_coords,
4749
element: res
4850
});
49-
51+
that._primitive.id = res.featureId;
52+
if(that._addedPlot){
53+
that._addedPlot(that._primitive);
54+
}
5055
const lnglat = CesiumUtil.cartesian3ToDegrees(
5156
viewer.scene.globe.ellipsoid,
5257
worldPos
@@ -65,8 +70,9 @@ export default class DrawPoint extends DrawObject {
6570

6671
removeHooks() {
6772
const handler = this._handler;
68-
// handler.removeInputAction();
6973
handler.destroy();
7074
this._handler = null;
75+
this._isAdded = false;
76+
this.m_coords = [];
7177
}
7278
}

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

Lines changed: 23 additions & 5 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,19 +66,27 @@ export default class DrawPolyline extends DrawObject {
5866
if (!worldPos) return;
5967

6068
symbol.getElement().then(function (res) {
61-
if (!that._isAdded) {
69+
if (!that._isAdded && that._handler) {
6270
const {classificationType} = that._symbol;
6371
res.classificationType = classificationType;
6472
const {style} = that._symbol;
65-
if(style){
66-
res.initNodeStyles(style);
73+
if(style && style.nodeStyles){
74+
res.initNodeStyles(style.nodeStyles);
6775
}
6876
that._primitive = PrimitiveFactory.createInstance(symbol.type, {
6977
positions: that.m_coords,
7078
element: res,
7179
});
80+
that._primitive.id = res.featureId;
7281
that._isAdded = true;
7382
that._plotLayer._primitiveCollection.add(that._primitive);
83+
if(that._addedPlot){
84+
that._addedPlot(that._primitive);
85+
}
86+
}
87+
88+
if(!that._handler){
89+
return;
7490
}
7591

7692
const lnglat = CesiumUtil.cartesian3ToDegrees(
@@ -98,6 +114,7 @@ export default class DrawPolyline extends DrawObject {
98114
});
99115
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
100116

117+
//双击事件,结束绘制图元
101118
handler.setInputAction((event) => {
102119
this.fireFinishEvent({ plotObj3D: this._primitive });
103120
this.disable();
@@ -113,8 +130,9 @@ export default class DrawPolyline extends DrawObject {
113130
look(this.viewer, this.m_coords[this.m_coords.length - 1], 1000);
114131
}
115132

116-
// handler.removeInputAction();
117133
handler.destroy();
118134
this._handler = null;
135+
this._isAdded = false;
136+
this.m_coords = [];
119137
}
120138
}

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)