Skip to content

Commit eb8f574

Browse files
author
潘卓然ParnDeedlit
committed
2 parents 07f0a74 + 323ab42 commit eb8f574

File tree

2 files changed

+78
-16
lines changed

2 files changed

+78
-16
lines changed

src/cesiumjs/layer/M3DLayer.js

Lines changed: 69 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -73,26 +73,34 @@ export default class M3DLayer extends BaseLayer {
7373
/**
7474
* 添加m3d文档服务
7575
* @function module:客户端数据服务.M3DLayer.prototype.append
76-
* @param {String} url 服务地址
77-
* @param {Object} optionsParam 包含以下参数
78-
* @param {Boolean} [optionsParam.autoReset = true] 是否自动定位
79-
* @param {Boolean} [optionsParam.synchronous = true] 是否异步请求
80-
* @param {Function} [optionsParam.loaded = function] 回调函数
81-
* @param {DefaultProxy} [optionsParam.proxy = defaultProxy] 代理
82-
* @param {Boolean} [optionsParam.showBoundingVolume = false] 是否显示包围盒
83-
* @param {Number} [optionsParam.maximumScreenSpaceError = 16] 用于控制模型显示细节 值较大将会渲染更少的贴图,进而可以提高性能,而较低的值将提高视觉质量
76+
* @param {String} url 服务地址
77+
* @param {Object} optionsParam 包含以下参数
78+
* @param {Boolean} [optionsParam.autoReset = true] 是否自动定位
79+
* @param {Boolean} [optionsParam.synchronous = true] 是否异步请求
80+
* @param {Function} [optionsParam.loaded = function] 回调函数
81+
* @param {DefaultProxy} [optionsParam.proxy = defaultProxy] 代理
82+
* @param {Boolean} [optionsParam.showBoundingVolume = false] 是否显示包围盒
83+
* @param {Number} [optionsParam.maximumScreenSpaceError = 16] 用于控制模型显示细节 值较大将会渲染更少的贴图,进而可以提高性能,而较低的值将提高视觉质量
84+
* @param {String} [options.layers=undefined] 图层过滤功能
8485
* @see {@link https://cesium.com/docs/cesiumjs-ref-doc/Cesium3DTileset.html}
8586
* @returns {Array<MapGISM3DSet>} 返回m3d图层对象数组,长度为图层对象个数
8687
* @example
88+
*
8789
* function callBackfunction(layer){
88-
* console.log(layer)
90+
* console.log(layer)
8991
* }
92+
*
93+
* // layers 属性类似二维服务
94+
* // layers=show:0,1 表示只显示 layerIndex 为 0, 1 的图层
95+
* // layers=hide:0,1 表示只隐藏 layerIndex 为 0, 1 的图层
96+
*
9097
* let result = m3d.append('http://develop.smaryun.com:6163/igs/rest/g3d/ModelM3D, {
91-
* autoReset:false,
92-
* synchronous:true,
93-
* showBoundingVolume:false,
94-
* maximumScreenSpaceError:16,
95-
* loaded:callBackfunction
98+
* autoReset:false,
99+
* synchronous:true,
100+
* showBoundingVolume:false,
101+
* maximumScreenSpaceError:16,
102+
* layers:'layers=show:0',
103+
* loaded:callBackfunction
96104
* });
97105
*
98106
*/
@@ -107,6 +115,38 @@ export default class M3DLayer extends BaseLayer {
107115
let proxy;
108116
const docLayers = [];
109117

118+
const layersString = defaultValue(op.layers, '');
119+
120+
let layersVec = layersString.split('=');
121+
122+
let layerShow = true;
123+
let indexArray = [];
124+
125+
if (layersVec.length === 2) {
126+
var tmpString = layersVec[1];
127+
layersVec = tmpString.split(':');
128+
129+
if (layersVec.length === 2) {
130+
if (layersVec[0] === 'show') {
131+
layerShow = true;
132+
} else if (layersVec[0] === 'hide') {
133+
layerShow = false;
134+
} else {
135+
// eslint-disable-next-line no-console
136+
console.log('layers 参数输入错误:' + layersString);
137+
}
138+
139+
tmpString = layersVec[1];
140+
layersVec = tmpString.split(',');
141+
142+
if (layersVec.length > 0) {
143+
for (var index = 0; index < layersVec.length; index++) {
144+
indexArray.push(parseInt(layersVec[index]));
145+
}
146+
}
147+
}
148+
}
149+
110150
if (Cesium.defined(options)) {
111151
if (Cesium.defined(options.proxy)) {
112152
// 不放在defaultValue中 new 会影响性能
@@ -130,7 +170,16 @@ export default class M3DLayer extends BaseLayer {
130170
const type = parseInt(layer.layerType, 10);
131171
if (type === LayerType.M3DLAYER) {
132172
const { layerRenderIndex, layerIndex, gdbpUrl, isVisible } = layer;
133-
const m3d = this.appendM3DLayer(baseUrl, layerRenderIndex, layerIndex, gdbpUrl, isVisible, true, options);
173+
174+
let isShow = true;
175+
176+
if (layersString.length > 7 && indexArray.length > 0) {
177+
isShow = (indexArray.indexOf(layerIndex) !== -1) === layerShow;
178+
} else {
179+
isShow = isVisible;
180+
}
181+
182+
const m3d = this.appendM3DLayer(baseUrl, layerRenderIndex, layerIndex, gdbpUrl, isShow, true, options);
134183
docLayers.push(m3d);
135184
m3d.readyPromise.then(_callBack);
136185
}
@@ -268,7 +317,11 @@ export default class M3DLayer extends BaseLayer {
268317
let hpr = new Cesium.Matrix3();
269318
const hprObj = new Cesium.HeadingPitchRoll(Cesium.Math.PI, Cesium.Math.PI, Cesium.Math.PI);
270319
hpr = Cesium.Matrix3.fromHeadingPitchRoll(hprObj, hpr);
271-
const modelMatrix = Cesium.Matrix4.multiplyByTranslation(Cesium.Transforms.eastNorthUpToFixedFrame(Cesium.Cartesian3.fromDegrees(longtitude, latitude, 0)), new Cesium.Cartesian3(), new Cesium.Matrix4());
320+
const modelMatrix = Cesium.Matrix4.multiplyByTranslation(
321+
Cesium.Transforms.eastNorthUpToFixedFrame(Cesium.Cartesian3.fromDegrees(longtitude, latitude, 0)),
322+
new Cesium.Cartesian3(),
323+
new Cesium.Matrix4()
324+
);
272325
Cesium.Matrix4.multiplyByMatrix3(modelMatrix, hpr, modelMatrix);
273326
const { _root } = tileSet;
274327
_root.transform = modelMatrix;

src/cesiumjs/layer/TilesLayer.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ export default class TilesLayer extends BaseLayer {
7373
* @param {Number} [optionsParam.rowNum=1] 瓦片初始级的列数 默认为1
7474
* @param {Number} [optionsParam.maxLevel=19] 瓦片最大显示级数 默认为19
7575
* @param {String} [optionsParam.proxy] 转发代理
76+
* @param {Array} [options.gdbps] gdbps地址数组
77+
* @param {String} [options.layers] layers参数,用于过滤图层
78+
*
7679
* @returns {ImageryLayer} 瓦片对象
7780
* @example
7881
* 如果裁瓦片的时候是按照经纬度裁剪的瓦片则只设置最大级数即可
@@ -91,6 +94,12 @@ export default class TilesLayer extends BaseLayer {
9194
append2DDocTile(url, optionsParam) {
9295
// 中地新版正常二维瓦片
9396
const options = Cesium.defaultValue(optionsParam, {});
97+
98+
if (Cesium.defined(options.gdbps) && Cesium.defined(options.layers)) {
99+
// eslint-disable-next-line no-console
100+
console.log('不能同时定义 gdbps 和 layers');
101+
}
102+
94103
options.url = url;
95104
const mapGis2DDocTile = this.viewer.imageryLayers.addImageryProvider(new Cesium.MapGIS2DDocMapProvider(options));
96105
return mapGis2DDocTile;

0 commit comments

Comments
 (0)