Skip to content

Commit 49f5ca2

Browse files
committed
【杨琨】【添加注释】
1 parent a3a3bb9 commit 49f5ca2

File tree

1 file changed

+142
-38
lines changed

1 file changed

+142
-38
lines changed

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

Lines changed: 142 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
/*
2-
* @Author: your name
3-
* @Date: 2021-10-25 10:22:13
4-
* @LastEditTime: 2022-05-20 20:10:07
5-
* @LastEditors: zk
6-
* @Description: In User Settings Edit
7-
* @FilePath: \MapGISPlotBase\src\3DPlot\Primitive\ElementInstance\SvgElementInstance.js
8-
*/
91
import {Vector2} from "../../../PlotUtilBase/Math/Vector2";
102
import {Vector3} from "../../../PlotUtilBase/Math/Vector3";
113
import PolylineCurve3 from "../../../../service/PlotUtilBase/Curves/PolylineCurve3";
@@ -16,6 +8,15 @@ import {ExtrudeGeometryUtil} from "../../Utils/ExtrudeGeometryUtil";
168
import {Shape} from "../../../PlotUtilBase/Path2D/Shape";
179
import {setOffsetHeight} from "./Util";
1810

11+
/**
12+
* @class module:3DPlot.SvgElementInstance
13+
* @description 三维SVG符号解析对象
14+
* @author 基础平台-杨琨
15+
*
16+
* @param {Object} elem SVG符号对象
17+
* @param options - {Object} 初始化参数
18+
* @param {Number} [options.globelScale] 全局缩放系数
19+
*/
1920
export default class SvgElementInstance {
2021
constructor(elem, options = {}) {
2122
this._elem = elem;
@@ -26,6 +27,13 @@ export default class SvgElementInstance {
2627
this.instance = undefined;
2728
}
2829

30+
/**
31+
* @function module:3DPlot.SvgElementInstance.getInstance
32+
* @description 获取解析后的几何对象
33+
* @public
34+
*
35+
* @param {function} callback 回调函数
36+
*/
2937
getInstance(callback) {
3038
let that = this;
3139
this.svgToGeomInstances(this._elem, this._options, function (instance) {
@@ -34,6 +42,15 @@ export default class SvgElementInstance {
3442
});
3543
}
3644

45+
/**
46+
* @function module:3DPlot.SvgElementInstance.svgToGeomInstances
47+
* @description 将SVG解析为几何对象
48+
* @public
49+
*
50+
* @param {Object} elem SVG符号对象
51+
* @param {Object} options 额外参数
52+
* @param {function} callback 回调函数
53+
*/
3754
svgToGeomInstances(elem, options, callback) {
3855
const paths = [];
3956
elem.getPathElem(paths);
@@ -71,6 +88,13 @@ export default class SvgElementInstance {
7188
}
7289
}
7390

91+
/**
92+
* @function module:3DPlot.SvgElementInstance.getInstances
93+
* @description 将SVG里的各个部件解析为几何对象
94+
* @public
95+
*
96+
* @param {Object} opt 额外参数
97+
*/
7498
getInstances(opt) {
7599
let {sampleResult, type, paths, options, spans} = opt;
76100
let pathOffsetHeights, spanOffsetHeights, wallOffsetHeights;
@@ -127,6 +151,14 @@ export default class SvgElementInstance {
127151
return {instances, wallOffsetHeights}
128152
}
129153

154+
/**
155+
* @function module:3DPlot.SvgElementInstance.pathElemToGeomInstance
156+
* @description 将SVG里的path元素解析为几何对象
157+
* @public
158+
*
159+
* @param {Object} pathElem path元素的符号对象
160+
* @param {Object} options 额外参数
161+
*/
130162
pathElemToGeomInstance(pathElem, options) {
131163
const instances = [];
132164
const style = pathElem.getContextStyle()
@@ -161,6 +193,14 @@ export default class SvgElementInstance {
161193
return instances;
162194
}
163195

196+
/**
197+
* @function module:3DPlot.SvgElementInstance.spanElemToGeomInstance
198+
* @description 将SVG里的span元素解析为几何对象
199+
* @public
200+
*
201+
* @param {Object} spanElem span元素的符号对象
202+
* @param {Object} options 额外参数
203+
*/
164204
spanElemToGeomInstance(spanElem, options) {
165205
if (!spanElem) return undefined;
166206

@@ -176,6 +216,13 @@ export default class SvgElementInstance {
176216
return this._generateCesiumGeometryInstance(spanElem, textGeo, options, this.getColor(spanElem, "fillStyle"));
177217
}
178218

219+
/**
220+
* @description 通过span元素生成三维的文字体对象
221+
* @private
222+
*
223+
* @param {Object} spanElem span元素的符号对象
224+
* @param {Number} textWidth 文字宽度
225+
*/
179226
_generateTextGeometry(spanElem, textWidth) {
180227
const text = spanElem.getText();
181228
const fontSize = spanElem.getStyle("font-size").getPixels();
@@ -185,6 +232,14 @@ export default class SvgElementInstance {
185232
return ExtrudeGeometryUtil.createExtrudeGeometryByDepth(shapes, 4, textWidth, 1);
186233
}
187234

235+
/**
236+
* @description 将svg里的线生成三维的管道体
237+
* @private
238+
*
239+
* @param {Array} coords 点坐标数组
240+
* @param {Number} strokeWidth 线宽
241+
* @param {Array} offsetHeights 有地形高程采样是的高度数组
242+
*/
188243
_generateStrokeGeometry(coords, strokeWidth, offsetHeights) {
189244
const vec3s = [];
190245
const coordsLen = coords.length;
@@ -218,6 +273,13 @@ export default class SvgElementInstance {
218273
return ExtrudeGeometryUtil.createExtrudeGeometryByPath([shape], undefined, polylineCurve, coordsLen * 2 - 3);
219274
}
220275

276+
/**
277+
* @description 将svg里的区生成三维的平面体
278+
* @private
279+
*
280+
* @param {Array} coords 点坐标数组
281+
* @param {Number} height 平面厚度
282+
*/
221283
_generateFillGeometry(coords, height) {
222284
const pts = [];
223285
let coordsLen = coords.length;
@@ -246,6 +308,15 @@ export default class SvgElementInstance {
246308
return ExtrudeGeometryUtil.createExtrudeGeometryByPath([shape], undefined, polylineCurve, 1);
247309
}
248310

311+
/**
312+
* @description 内部生成三维体的方法
313+
* @private
314+
*
315+
* @param {Object} elem SVG符号对象
316+
* @param {Object} extrudeGeom 三维线对象
317+
* @param {Object} options 额外参数
318+
* @param {Object} color 颜色
319+
*/
249320
_generateCesiumGeometryInstance(elem, extrudeGeom, options, color) {
250321
if (!defined(extrudeGeom)) return undefined;
251322

@@ -262,6 +333,15 @@ export default class SvgElementInstance {
262333
});
263334
}
264335

336+
/**
337+
* @description 根据类型获取颜色对象
338+
* @private
339+
*
340+
* @param {Object} ele SVG符号对象
341+
* @param {String} type 类型
342+
*
343+
* @return {Object} ret 颜色对象
344+
*/
265345
_getColorByType(ele, type) {
266346
let ret;
267347
const styles = ele.getContextStyle()
@@ -301,14 +381,35 @@ export default class SvgElementInstance {
301381
}
302382
}
303383

384+
/**
385+
* @function module:3DPlot.SvgElementInstance.transformExtrudeGeometry
386+
* @description: 平移三维几何体,主要针对经纬度和墨卡托坐标系进行的处理
387+
* @public
388+
*
389+
* @param {Object} extrudeGeom 三维几何体对象
390+
* @param {Object} options 额外参数
391+
*/
304392
transformExtrudeGeometry(extrudeGeom, options) {
305393
}
306394

395+
/**
396+
* @function module:3DPlot.SvgElementInstance.transformExtrudeGeometry
397+
* @description: 生成cesium的geometry对象
398+
* @public
399+
*
400+
* @param {Object} elem SVG符号对象
401+
* @param {Object} cesgeo 三维几何体对象
402+
* @param {Object} options 额外参数
403+
*/
307404
transfromGeoCesium(elem, cesgeo, options) {
308405
const {dimModHeight} = options;
309406
CesiumGeomUtil.translate(cesgeo, new Cesium.Cartesian3(0, 0, dimModHeight));
310407
}
311408

409+
/**
410+
* @description: 初始化地形高度采样参数
411+
* @private
412+
*/
312413
_initSampleOptions() {
313414
this.samplePoints = [];
314415
this.sampleConfigs = [];
@@ -317,6 +418,12 @@ export default class SvgElementInstance {
317418
this.index = 0;
318419
}
319420

421+
/**
422+
* @description: 获取坐标点数组
423+
* @private
424+
*
425+
* @return {Array} cacheCoords 坐标点数组
426+
*/
320427
_getCoords(path) {
321428
const {cacheCoords} = path;
322429
if (!cacheCoords) {
@@ -328,30 +435,8 @@ export default class SvgElementInstance {
328435

329436
/**
330437
* @description 全部点地形采样
331-
* @param path - {Object} 必选项,path对象
332-
* @return sample - {Object} 采样点(笛卡尔坐标)信息
333-
*/
334-
_getFullSample(path) {
335-
const cacheCoords = this._getCoords(path);
336-
337-
let samples = [], simpleConfig = [], startIndex = this.index, endIndex;
338-
for (let j = 0; j < cacheCoords.length; j++) {
339-
for (let k = 0; k < cacheCoords[j].length; k++) {
340-
let sample = this._mercatorTolonlat(cacheCoords[j][k]);
341-
samples.push(Cesium.Cartesian3.fromDegrees(sample.lon, sample.lat, 0));
342-
}
343-
endIndex = startIndex + cacheCoords[j].length - 1;
344-
simpleConfig.push({
345-
start: startIndex, end: endIndex
346-
})
347-
startIndex = endIndex + 1;
348-
}
349-
350-
return {samples, simpleConfig, endIndex}
351-
}
352-
353-
/**
354-
* @description 全部点地形采样
438+
* @private
439+
*
355440
* @param path - {Object} 必选项,path对象
356441
* @return sample - {Object} 采样点(笛卡尔坐标)信息
357442
*/
@@ -376,6 +461,8 @@ export default class SvgElementInstance {
376461

377462
/**
378463
* @description 指定点地形采样
464+
* @private
465+
*
379466
* @param points - {Array} 必选项,指定的采样点数组
380467
* @return sample - {Object} 采样点(笛卡尔坐标)信息
381468
*/
@@ -394,6 +481,12 @@ export default class SvgElementInstance {
394481
return {samples, simpleConfig, endIndex}
395482
}
396483

484+
/**
485+
* @description 保存高度采样点
486+
* @private
487+
*
488+
* @param {Object} path SVG部件符号对象
489+
*/
397490
_setPointsSample(path) {
398491
let originPnts = [];
399492
let parts = path.cacheCoords || path.getCoords();
@@ -405,6 +498,8 @@ export default class SvgElementInstance {
405498

406499
/**
407500
* @description 根据OriginPoint进行地形采样
501+
* @private
502+
*
408503
* @param originPnt - {Object} 必选项,originPnt对象
409504
* @return sample - {Object} 采样点(笛卡尔坐标)信息
410505
*/
@@ -423,6 +518,8 @@ export default class SvgElementInstance {
423518

424519
/**
425520
* @description 根据经纬度进行地形采样
521+
* @private
522+
*
426523
* @param Lonlat - {Object} 必选项,Lonlat对象
427524
* @return sample - {Object} 采样点(笛卡尔坐标)信息
428525
*/
@@ -438,6 +535,13 @@ export default class SvgElementInstance {
438535
return {samples, simpleConfig, endIndex}
439536
}
440537

538+
/**
539+
* @description 确定采样点所对应的SVG部件
540+
* @private
541+
*
542+
* @param {Object} sampleObj 采样点配置对象
543+
* @param {String} type 部件类型
544+
*/
441545
_setSamples(sampleObj, type) {
442546
type = type || 'path';
443547
this.samplePoints = this.samplePoints.concat(sampleObj.samples);
@@ -453,7 +557,8 @@ export default class SvgElementInstance {
453557

454558
/**
455559
* @description 取得采样参数
456-
* @param type - {String} 必选项,path类型
560+
* @private
561+
*
457562
* @param paths - {Array} 必选项,path数组
458563
* @param spans - {Array} 必选项,span数组
459564
* @return sampleOptions - {Object} 采样参数
@@ -485,13 +590,10 @@ export default class SvgElementInstance {
485590
}
486591
}
487592

488-
_getPointSampleOptions(lonlat) {
489-
this._initSampleOptions();
490-
this._setSamples(this._getLonlatSample(lonlat));
491-
}
492-
493593
/**
494594
* @description 根据采样结果取得每个部件的高程采样数组
595+
* @private
596+
*
495597
* @param sampleResult - {Array} 必选项,高程采样结果
496598
* @param type - {String} 可选项,类型,path或span
497599
* @return pathHeights - {Array} 所有部件的高程采样数组
@@ -518,6 +620,8 @@ export default class SvgElementInstance {
518620

519621
/**
520622
* @description 墨卡托坐标转经纬度坐标
623+
* @private
624+
*
521625
* @param mercator - {Object} 必选项,墨卡托坐标
522626
* @return lonlat - {Object} 经纬度坐标
523627
*/

0 commit comments

Comments
 (0)