Skip to content

Commit 4c634d1

Browse files
committed
【杨琨】【贴地代码 - 线】
1 parent 0b1f681 commit 4c634d1

File tree

6 files changed

+444
-153
lines changed

6 files changed

+444
-153
lines changed

src/service/3DPlot/Primitive/ElementInstance/RegularLineElementInstance.js

Lines changed: 75 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ import MainElement from "../../../../service/PlotBase/SvgLoader/element/extend/M
1212
import { defined } from "../../../PlotUtilBase/Check";
1313

1414
export default class RegularLineElementInstance extends SvgElementInstance {
15-
svgToGeomInstances(elem, options) {
16-
const instances = super.svgToGeomInstances(elem, options);
17-
const wallGeomInstances = this.generateWallGeometryInstances(elem, options);
18-
return { instances, wallGeomInstances };
15+
svgToGeomInstances(elem, options, callback) {
16+
let that = this;
17+
super.svgToGeomInstances(elem, options, function (instances, wallOffsetHeights) {
18+
const wallGeomInstances = that.generateWallGeometryInstances(elem, options, wallOffsetHeights);
19+
callback({ instances, wallGeomInstances });
20+
});
1921
}
2022

2123
/**
@@ -24,17 +26,24 @@ export default class RegularLineElementInstance extends SvgElementInstance {
2426
* @param {*} options
2527
* @returns
2628
*/
27-
generateWallGeometryInstances(elem, options) {
29+
generateWallGeometryInstances(elem, options, wallOffsetHeights) {
2830
if (!options.isOpenWall) return undefined;
2931

3032
const paths = [];
3133
elem.getPathElem(paths);
3234

33-
let instances = [];
35+
let instances = [], wallIndex = 0, wallOffsetHeightArray;
3436
for (let i = 0; i < paths.length; i += 1) {
37+
const {type} = paths[i];
38+
if(type === 'extendline' || type === 'mainline'){
39+
wallOffsetHeightArray = wallOffsetHeights[wallIndex];
40+
wallIndex++;
41+
}
42+
3543
const wallGeomInstance = this.pathElemToWallGeomInstance(
3644
paths[i],
37-
options
45+
options,
46+
wallOffsetHeightArray
3847
);
3948
if (!defined(wallGeomInstance)) continue;
4049
if (Array.isArray(wallGeomInstance)) {
@@ -46,7 +55,7 @@ export default class RegularLineElementInstance extends SvgElementInstance {
4655
return instances;
4756
}
4857

49-
pathElemToWallGeomInstance(pathElem, options) {
58+
pathElemToWallGeomInstance(pathElem, options, wallOffsetHeights) {
5059
const wallHeight = options.dimModHeight;
5160
const wallColor = options.wallColor;
5261
const cesiumWallColor = Cesium.ColorGeometryInstanceAttribute.fromColor(
@@ -55,31 +64,60 @@ export default class RegularLineElementInstance extends SvgElementInstance {
5564

5665
const parts = pathElem.cacheCoords || pathElem.getCoords();
5766
const instances = [];
58-
for (let i = 0; i < parts.length; i += 1) {
59-
const coords = parts[i];
60-
61-
const degreeArrayHeights = [];
62-
for (let j = 0; j < coords.length; j += 1) {
63-
const coord = coords[j];
64-
const res = CesiumUtil.WebMercatorUnProject(coord.x, coord.y);
65-
degreeArrayHeights.push(res.x, res.y, wallHeight);
67+
if(wallOffsetHeights instanceof Array && wallOffsetHeights.length > 0){
68+
for (let i = 0; i < parts.length; i += 1) {
69+
const coords = parts[i];
70+
71+
const degreeArrayHeights = [];
72+
for (let j = 0; j < coords.length; j += 1) {
73+
const coord = coords[j];
74+
const res = CesiumUtil.WebMercatorUnProject(coord.x, coord.y);
75+
degreeArrayHeights.push(res.x, res.y, wallHeight + wallOffsetHeights[i][j]);
76+
}
77+
78+
const wallGeometry = Cesium.WallGeometry.createGeometry(
79+
new Cesium.WallGeometry({
80+
positions:
81+
Cesium.Cartesian3.fromDegreesArrayHeights(degreeArrayHeights),
82+
})
83+
);
84+
85+
instances.push(
86+
new Cesium.GeometryInstance({
87+
geometry: wallGeometry,
88+
attributes: {
89+
color: cesiumWallColor,
90+
},
91+
})
92+
);
6693
}
94+
}else {
95+
for (let i = 0; i < parts.length; i += 1) {
96+
const coords = parts[i];
6797

68-
const wallGeometry = Cesium.WallGeometry.createGeometry(
69-
new Cesium.WallGeometry({
70-
positions:
71-
Cesium.Cartesian3.fromDegreesArrayHeights(degreeArrayHeights),
72-
})
73-
);
98+
const degreeArrayHeights = [];
99+
for (let j = 0; j < coords.length; j += 1) {
100+
const coord = coords[j];
101+
const res = CesiumUtil.WebMercatorUnProject(coord.x, coord.y);
102+
degreeArrayHeights.push(res.x, res.y, wallHeight);
103+
}
104+
105+
const wallGeometry = Cesium.WallGeometry.createGeometry(
106+
new Cesium.WallGeometry({
107+
positions:
108+
Cesium.Cartesian3.fromDegreesArrayHeights(degreeArrayHeights),
109+
})
110+
);
74111

75-
instances.push(
76-
new Cesium.GeometryInstance({
77-
geometry: wallGeometry,
78-
attributes: {
79-
color: cesiumWallColor,
80-
},
81-
})
82-
);
112+
instances.push(
113+
new Cesium.GeometryInstance({
114+
geometry: wallGeometry,
115+
attributes: {
116+
color: cesiumWallColor,
117+
},
118+
})
119+
);
120+
}
83121
}
84122

85123
return instances;
@@ -94,6 +132,7 @@ export default class RegularLineElementInstance extends SvgElementInstance {
94132
const lineWidth=style.lineWidth
95133
const strokeWidthSize = lineWidth*this.globelScale/2;
96134
const _fillWidthSize = this.fillDefaultWidth*this.globelScale/2
135+
const {offsetHeights} = options;
97136

98137
const parts = pathElem.cacheCoords || pathElem.getCoords();
99138

@@ -102,13 +141,17 @@ export default class RegularLineElementInstance extends SvgElementInstance {
102141
if (stroke && stroke !== "none") {
103142

104143
for (let i = 0; i < parts.length; i += 1) {
144+
let offsetHeight;
145+
if(offsetHeights){
146+
offsetHeight = offsetHeights[i];
147+
}
105148
const coords = parts[i];
106149
const geometry = this._generateStrokeGeometry(
107150
coords,
108-
isMainElement ? strokeWidthSize - 5 : strokeWidthSize
151+
isMainElement ? strokeWidthSize - 5 : strokeWidthSize,
152+
offsetHeight
109153
);
110154
geometry.modDetail=pathElem.getGeometryDetail(i)
111-
112155
const instance = this._generateCesiumGeometryInstance(
113156
pathElem,
114157
geometry,

src/service/3DPlot/Primitive/ElementInstance/SimpleLineElementInstance.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import MainElement from '../../../../service/PlotBase/SvgLoader/element/extend/M
1212
import RegularLineElementInstance from './RegularLineElementInstance';
1313

1414
export default class SimpleLineElementInstance extends RegularLineElementInstance {
15-
pathElemToWallGeomInstance(pathElem, options) {
15+
pathElemToWallGeomInstance(pathElem, options, wallOffsetHeights) {
1616
if (!(pathElem instanceof MainElement)) return undefined;
17-
return super.pathElemToWallGeomInstance(pathElem, options);
17+
return super.pathElemToWallGeomInstance(pathElem, options, wallOffsetHeights);
1818
}
1919

2020
transfromGeoCesium(elem, cesgeo, options) {

0 commit comments

Comments
 (0)