Skip to content

Commit 6722de7

Browse files
author
zhaokai
committed
【新增】【添加统一的样式接口,修改点符号的初始大小】
1 parent 1aef743 commit 6722de7

File tree

4 files changed

+107
-88
lines changed

4 files changed

+107
-88
lines changed

src/service/2DPlot/Shapes/PlotObject.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* @Author: your name
33
* @Date: 2021-07-05 11:32:52
4-
* @LastEditTime: 2022-06-08 09:54:23
4+
* @LastEditTime: 2022-07-02 15:05:58
55
* @LastEditors: zk
66
* @Description: In User Settings Edit
77
* @FilePath: \MapGISPlot\src\js\Shapes\PlotObject.js
@@ -91,6 +91,13 @@ const PlotObject = fabric.util.createClass(fabric.Object, {
9191
new Error('GeoJSON类型错误!');
9292
}
9393
},
94+
getStyleJSON(){
95+
const object = this._elem.getStyleJSON();
96+
return object;
97+
},
98+
setStyleJSON(object){
99+
this._elem.setStyleJSON(object)
100+
},
94101
isNotVisible: function () {
95102
return this.opacity === 0 || (!this.width && !this.height && this.strokeWidth === 0) || !this.visible || !this._elem.show;
96103
},

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

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {getCenter, getCenterByCartesian} from "../Utils/PlotUtil"
1+
import { getCenter, getCenterByCartesian } from '../Utils/PlotUtil';
22

33
/**
44
* @class module:3DPlot.BasePlotPrimitive
@@ -31,7 +31,7 @@ class BasePlotPrimitive {
3131

3232
this._positions = [];
3333

34-
const {positions} = this._elem;
34+
const { positions } = this._elem;
3535
for (let i = 0; i < positions.length; i += 1) {
3636
const tempPos = this._elem.positions[i];
3737
this._positions.push(Cesium.Cartesian3.fromDegrees(tempPos.x, tempPos.y));
@@ -49,10 +49,10 @@ class BasePlotPrimitive {
4949
*/
5050
_elemPropsUpdateHandler(event) {
5151
if (event.type === 'positions') {
52-
let {_positionBillboards,_shapeBillboards} = this;
52+
let { _positionBillboards, _shapeBillboards } = this;
5353
const positions = event.value;
5454

55-
if(_positionBillboards && _shapeBillboards){
55+
if (_positionBillboards && _shapeBillboards) {
5656
let prevCenter = getCenterByCartesian(this._positions);
5757
let center = getCenter(positions);
5858
let cartographicStart = Cesium.Cartographic.fromDegrees(prevCenter.geometry.coordinates[0], prevCenter.geometry.coordinates[1], 0);
@@ -62,15 +62,23 @@ class BasePlotPrimitive {
6262
//更新位置点坐标
6363
let _positionBillboard = _positionBillboards.get(0);
6464
let _positionBillboardCart = Cesium.Cartographic.fromCartesian(_positionBillboard.position);
65-
let positionPoint = Cesium.Cartesian3.fromDegrees(center.geometry.coordinates[0], center.geometry.coordinates[1], _positionBillboardCart.height);
65+
let positionPoint = Cesium.Cartesian3.fromDegrees(
66+
center.geometry.coordinates[0],
67+
center.geometry.coordinates[1],
68+
_positionBillboardCart.height
69+
);
6670
_positionBillboard.position = positionPoint;
6771
//更新控制点坐标
6872
//平移图元和形状控制点
6973
for (let i = 0; i < positions.length; i++) {
7074
let shapePoint = _shapeBillboards.get(i);
71-
if(shapePoint._isEdit === false){
75+
if (shapePoint._isEdit === false) {
7276
let shapePointCart = Cesium.Cartographic.fromCartesian(shapePoint.position);
73-
shapePoint.position = Cesium.Cartesian3.fromDegrees(Cesium.Math.toDegrees(shapePointCart.longitude) + offsetLng, Cesium.Math.toDegrees(shapePointCart.latitude) + offsetLat, 600);
77+
shapePoint.position = Cesium.Cartesian3.fromDegrees(
78+
Cesium.Math.toDegrees(shapePointCart.longitude) + offsetLng,
79+
Cesium.Math.toDegrees(shapePointCart.latitude) + offsetLat,
80+
600
81+
);
7482
}
7583
}
7684
}
@@ -253,6 +261,26 @@ class BasePlotPrimitive {
253261
}
254262
}
255263

264+
getStyleJSON() {
265+
const object = this._elem.getStyleJSON();
266+
const baseAttrNames = this.getPrimitiveBaseSaveAttributes();
267+
baseAttrNames.forEach((t) => {
268+
object[t] = this[t];
269+
});
270+
return object;
271+
}
272+
273+
setStyleJSON(object) {
274+
this._elem.setStyleJSON(object);
275+
const baseAttrNames = this.getPrimitiveBaseSaveAttributes();
276+
const keys = Object.keys(object);
277+
keys.forEach((t) => {
278+
if (baseAttrNames.indexOf(t) > -1) {
279+
this[t] = object[t];
280+
}
281+
});
282+
}
283+
256284
/**
257285
* @description: 初始化保存属性(必须和extend扩展数组对应)
258286
* @function module:3DPlot.BasePlotPrimitive.initBaseSaveAttributes
@@ -352,7 +380,7 @@ class BasePlotPrimitive {
352380
type: 'Image',
353381
uniforms: {
354382
image: this.getColorRamp([0.0, 1], [wallColor, WallGradColor], true),
355-
repeat: {x: 1, y: 1}
383+
repeat: { x: 1, y: 1 }
356384
}
357385
}
358386
})
@@ -456,7 +484,7 @@ class BasePlotPrimitive {
456484
* @return {Object} style 图元样式
457485
*/
458486
getStyle() {
459-
return this._elem.getStyleJSON();
487+
return this.getStyleJSON();
460488
}
461489
}
462490

src/service/3DPlot/Primitive/RegularPrimitive/SimplePointPrimitive.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ import RegularPointPrimitive from "./RegularPointPrimitive";
88
* @param options - {Object} 初始化参数
99
*/
1010
class SimplePointPrimitive extends RegularPointPrimitive {
11+
12+
constructor(options) {
13+
super(options);
14+
this.m_scale=50
15+
}
1116

1217
/**
1318
* @description 重写父类的initBaseSaveAttributes方法

0 commit comments

Comments
 (0)