@@ -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 ;
0 commit comments