Skip to content

Commit 36ed1e4

Browse files
committed
【杨琨】【颜色修改】
1 parent 84ea708 commit 36ed1e4

File tree

5 files changed

+78
-62
lines changed

5 files changed

+78
-62
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,20 @@ export default class DrawPoint extends DrawObject {
3535
if (!worldPos) return;
3636

3737
symbol.getElement().then(function (res) {
38-
const {classificationType} = that._symbol;
38+
const {classificationType, id} = that._symbol;
3939
res.classificationType = classificationType;
4040
const {style} = that._symbol;
4141
if(style && style.nodeStyles){
4242
res.initNodeStyles(style.nodeStyles);
4343
}
44-
44+
if(id){
45+
res.featureId = id;
46+
}
4547
that._primitive = PrimitiveFactory.createInstance(symbol.type, {
4648
positions: that.m_coords,
4749
element: res
4850
});
49-
51+
that._primitive.id = id;
5052
const lnglat = CesiumUtil.cartesian3ToDegrees(
5153
viewer.scene.globe.ellipsoid,
5254
worldPos

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,20 @@ export default class DrawPolyline extends DrawObject {
5959

6060
symbol.getElement().then(function (res) {
6161
if (!that._isAdded) {
62-
const {classificationType} = that._symbol;
62+
const {classificationType, id} = that._symbol;
6363
res.classificationType = classificationType;
6464
const {style} = that._symbol;
6565
if(style && style.nodeStyles){
6666
res.initNodeStyles(style.nodeStyles);
6767
}
68+
if(id){
69+
res.featureId = id;
70+
}
6871
that._primitive = PrimitiveFactory.createInstance(symbol.type, {
6972
positions: that.m_coords,
7073
element: res,
7174
});
75+
that._primitive.id = id;
7276
that._isAdded = true;
7377
that._plotLayer._primitiveCollection.add(that._primitive);
7478
}

src/service/3DPlot/PlotLayer3D.js

Lines changed: 47 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ class PlotLayer3D extends Observable {
1717
super();
1818
//viewer对象
1919
this._viewer = viewer;
20-
//标绘图元id列表
21-
this._plotList = [];
2220
//primitive数组
2321
this._primitiveCollection = new Cesium.PrimitiveCollection();
2422
//图元可否编辑
@@ -40,7 +38,6 @@ class PlotLayer3D extends Observable {
4038
*/
4139
addPlot(plot) {
4240
this._primitiveCollection.add(plot);
43-
this._plotList.push(plot.id);
4441
return plot;
4542
}
4643

@@ -55,33 +52,11 @@ class PlotLayer3D extends Observable {
5552
* @function module:PlotLayer3D.removePlotByID
5653
* @description 根据标绘图元ID删除标绘图元
5754
* @param id - {String} 必选项,要删除的标绘图元ID
58-
* @return {Object} json
55+
* @return {Object} json,被删除的标绘图元
5956
*/
6057
removePlotByID(id) {
61-
//删除图元列表中的id
62-
for (let j = 0; j < this._plotList.length; j++) {
63-
if (id === this._plotList[j]) {
64-
this._plotList.splice(j, 1);
65-
break;
66-
}
67-
}
68-
69-
return this._removePlotByID(id);
70-
}
71-
72-
_removePlotByID(id) {
73-
let scene = this._getScene();
74-
let result;
75-
76-
//删除标绘图元
77-
for (let i = 0; i < scene.primitives.length; i++) {
78-
if (id === scene.primitives[i].id) {
79-
result = scene.primitives.remove(scene.primitives[i]);
80-
break;
81-
}
82-
}
83-
84-
return result;
58+
let plot = this.getPlotByID(id);
59+
return this.removePlot(plot);
8560
}
8661

8762
/**
@@ -91,42 +66,45 @@ class PlotLayer3D extends Observable {
9166
* @return {Object} json
9267
*/
9368
removePlot(plot) {
94-
let scene = this._getScene();
95-
96-
//删除图元列表中的id
97-
for (let i = 0; i < this._plotList.length; i++) {
98-
if (id === this._plotList[i]) {
99-
this._plotList.splice(i, 1);
100-
break;
101-
}
69+
let plotLayer = this._getPlotLayer();
70+
if(plotLayer){
71+
return plotLayer.remove(plot);
10272
}
103-
104-
return scene.primitives.remove(plot);
10573
}
10674

10775
/**
10876
* @function module:PlotLayer3D.getPlotByID
10977
* @description 根据标绘图元ID获取标绘图元
11078
* @param id - {String} 必选项,标绘图元ID
111-
* @return {Object} json
79+
* @return {Object} json,没找到返回undefined
11280
*/
11381
getPlotByID(id) {
114-
let index = this._getPlotIndexById(id);
115-
let scene = this._getScene();
82+
let plotLayer = this._getPlotLayer();
83+
84+
if(!plotLayer) {
85+
return undefined;
86+
}
11687

88+
let index = this._getPlotIndexById(id, plotLayer);
89+
const {_primitives} = plotLayer;
11790
if (index !== undefined) {
11891
return _primitives[index];
11992
}
12093
return undefined;
12194
}
12295

123-
_getPlotIndexById(id) {
124-
let scene = this._getScene();
125-
96+
/**
97+
* @description 根据标绘图元ID获取标绘图元的index
98+
* @private
99+
*
100+
* @param id - {String} 必选项,标绘图元ID
101+
* @param plotLayer - {Object} 必选项,标绘图层
102+
* @return {Number} index
103+
*/
104+
_getPlotIndexById(id, plotLayer) {
126105
let index = undefined;
127106

128-
const {_primitives} = scene.primitives;
129-
107+
const {_primitives} = plotLayer;
130108
for (let i = 0; i < _primitives.length; i++) {
131109
if (id === _primitives[i].id) {
132110
index = i;
@@ -136,17 +114,35 @@ class PlotLayer3D extends Observable {
136114

137115
return index;
138116
}
117+
/**
118+
* @description 根据标绘图层ID获取标绘图层
119+
* @private
120+
*
121+
* @return {Object} plotLayer 标绘图层,没找到返回undefined
122+
*/
123+
_getPlotLayer() {
124+
let scene = this._getScene();
125+
//根据图层id寻找标绘图层
126+
const {_primitives} = scene.primitives;
127+
//标绘图层
128+
let primitiveCollection;
129+
for (let i = 0; i < _primitives.length; i++) {
130+
if (this._id === _primitives[i]._id) {
131+
primitiveCollection = _primitives[i];
132+
break;
133+
}
134+
}
135+
136+
return primitiveCollection;
137+
}
139138

140139
/**
141140
* @function module:PlotLayer3D.removeAll
142141
* @description 移除图层下的所有标绘图元
143142
*/
144143
removeAll() {
145-
for (let i = 0; i < this._plotList.length; i++) {
146-
this._removePlotByID(this._plotList[i]);
147-
}
148-
149-
this._plotList = [];
144+
let plotLayer = this._getPlotLayer();
145+
plotLayer.removeAll();
150146
}
151147

152148
/**
@@ -206,8 +202,6 @@ class PlotLayer3D extends Observable {
206202
primitive.fromGeoJSON(geoFeature);
207203
primitive.id = id + "_" + parseInt(String(Math.random() * 1000000000));
208204

209-
that._plotList.push(primitive.id);
210-
211205
that._addPrimitive(primitive);
212206
});
213207
}

src/service/3DPlot/Primitive/BasePlotPrimitive.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* @property show 是否显示
1313
*/
1414

15-
export default class BasePlotPrimitive {
15+
class BasePlotPrimitive {
1616
constructor(options) {
1717
Cesium.Check.defined('options', options);
1818
Cesium.Check.defined('options.element', options.element);
@@ -35,7 +35,7 @@ export default class BasePlotPrimitive {
3535

3636
this._positions = [];
3737

38-
const { positions } = this._elem;
38+
const {positions} = this._elem;
3939
for (let i = 0; i < positions.length; i += 1) {
4040
const tempPos = this._elem.positions[i];
4141
this._positions.push(Cesium.Cartesian3.fromDegrees(tempPos.x, tempPos.y));
@@ -237,7 +237,7 @@ export default class BasePlotPrimitive {
237237
v[s] = this[s];
238238
});
239239
return v;
240-
240+
241241
}
242242

243243
/**
@@ -295,7 +295,7 @@ export default class BasePlotPrimitive {
295295
type: 'Image',
296296
uniforms: {
297297
image: this.getColorRamp([0.0, 1], [wallColor, WallGradColor], true),
298-
repeat: { x: 1, y: 1 }
298+
repeat: {x: 1, y: 1}
299299
}
300300
}
301301
})
@@ -367,4 +367,20 @@ export default class BasePlotPrimitive {
367367
else ctx.fillRect(0, 0, 100, 1);
368368
return ramp;
369369
}
370+
371+
/**
372+
* @description: 设置标绘图元样式,必须通过此方法设置,修改样式的属性无效
373+
* @param key {String} 样式名
374+
* @param value {Any} 样式值
375+
* @param value {Any} 样式值
376+
* @param nodeIds {String} 图元部件ID字符串,可传入多个id,以逗号分隔,当id有多个时,可统一修改多个部件的样式,
377+
* 若找不到id则不做改变
378+
* @return {*}
379+
*/
380+
setStyle(key, value, nodeIds) {
381+
console.log("this._elem",this._elem)
382+
this.setValue(key, value, nodeIds);
383+
}
370384
}
385+
386+
export default BasePlotPrimitive;

src/service/PlotBase/SvgLoader/element/BasePlotElement.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ class BasePlotElement extends SvgElement {
334334
setNodeAttr(type, value, childIds) {
335335
const {baseSVGAttributes, extendElementAttributes} =
336336
this.getSaveBaseAttributes();
337-
const baseSVGStyleAttributes = this.styleObject.getSVGStyleNameArr();
337+
const baseSVGStyleAttributes = this.getStyleObject().getSVGStyleNameArr();
338338

339339
let val = value;
340340

0 commit comments

Comments
 (0)