/** * [ONEMAP.M.projectController] * @return {[object]} */ define(function () { /** * 初始化并订阅事件 * @return {[type]} [description] */ /** * 模块数据 用于数据存储和外部调用 * @type {Object} * 数据存放 */ var modValue = { QXSY: {}, cancelSelected: null, } function prototypeBind() { //1.0GLTG插件 var fixGltf = function (gltf) { if (!gltf.extensionsUsed) { return; } var v = gltf.extensionsUsed.indexOf('KHR_technique_webgl'); var t = gltf.extensionsRequired.indexOf('KHR_technique_webgl'); // 中招了。。 if (v !== -1) { gltf.extensionsRequired.splice(t, 1, 'KHR_techniques_webgl'); gltf.extensionsUsed.splice(v, 1, 'KHR_techniques_webgl'); gltf.extensions = gltf.extensions || {}; gltf.extensions['KHR_techniques_webgl'] = {}; gltf.extensions['KHR_techniques_webgl'].programs = gltf.programs; gltf.extensions['KHR_techniques_webgl'].shaders = gltf.shaders; gltf.extensions['KHR_techniques_webgl'].techniques = gltf.techniques; var techniques = gltf.extensions['KHR_techniques_webgl'].techniques; gltf.materials.forEach(function (mat, index) { gltf.materials[index].extensions['KHR_technique_webgl'].values = gltf.materials[index].values; gltf.materials[index].extensions['KHR_techniques_webgl'] = gltf.materials[index].extensions['KHR_technique_webgl']; var vtxfMaterialExtension = gltf.materials[index].extensions['KHR_techniques_webgl']; for (var value in vtxfMaterialExtension.values) { var us = techniques[vtxfMaterialExtension.technique].uniforms; for (var key in us) { if (us[key] === value) { vtxfMaterialExtension.values[key] = vtxfMaterialExtension.values[value]; delete vtxfMaterialExtension.values[value]; break; } } }; }); techniques.forEach(function (t) { for (var attribute in t.attributes) { var name = t.attributes[attribute]; t.attributes[attribute] = t.parameters[name]; }; for (var uniform in t.uniforms) { var name = t.uniforms[uniform]; t.uniforms[uniform] = t.parameters[name]; }; }); } } Object.defineProperties(Cesium.Model.prototype, { _cachedGltf: { set: function (value) { this._vtxf_cachedGltf = value; if (this._vtxf_cachedGltf && this._vtxf_cachedGltf._gltf) { fixGltf(this._vtxf_cachedGltf._gltf); } }, get: function () { return this._vtxf_cachedGltf; } } }); } function add(item, cancelSelected) { modValue.cancelSelected = cancelSelected var modelData = { "category": "倾斜摄影", "info": "", "name": item.title, "url": item.c_url, "layerInfo": item } var guid = null var options = {}; guid = add3DQX(modelData); options = { action: "add", DOM: { guid: guid, type: "QXSY", name: item.title, }, mod: "QXSY" } if (!guid) { return } ONEMAP.M.myLayers.myLayerControl(options); // 添加信息到“我的图层” ONEMAP.C.publisher.subscribe(layerAction, guid); } function remove(options) { var guid = options.guid ? options.guid : "QXSY--" + options.id; modValue.cancelSelected(guid); removeQXSY({ guid: guid }); ONEMAP.M.myLayers.myLayerControl({ action: "remove", DOMid: guid }); // 移除数据层 } function layerAction(options) { if (options.guid.split("--")[0] == "QXSY") { if (options.action == "remove") { remove(options) // 执行传入方法,取消勾选 modValue.cancelSelected(options.guid.split("--")[1]); } else if (options.action == "opacity") { opacityQXSY(options) } else if (options.action == "controlShow") { controlShowQXSY(options) } else if (options.action == "location") { locationQXSY(options) } } } /** * 加载/移除倾斜摄影 * @return {[type]} [description] */ function add3DQX(options) { // var guid = map23DControl.buildGuid('QXSY-' + options.layerInfo.id + "-"); var guid = 'QXSY--' + options.layerInfo.id var tilesetUrl = options.url var tileset = new Cesium.Cesium3DTileset({ url: tilesetUrl, show: true, }); modValue.tileset = tileset map3DViewer.map.scene.primitives.add(tileset, 1); tileset.readyPromise.then(function (tileset) { // mapControl.viewer.camera.viewBoundingSphere(tileset.boundingSphere, new Cesium.HeadingPitchRange(0, -0.5, 0)); // changeHeight(0) }); map3DViewer.map.zoomTo(tileset); modValue.QXSY[guid] = tileset return guid; }; function removeQXSY(options) { map3DViewer.map.scene.primitives.remove(modValue.QXSY[options.guid]); delete modValue.QXSY[options.guid]; } function opacityQXSY(options) { // if (options.options.opacity) // modValue.QXSY[options.guid].show = true // if (!options.options.opacity) // modValue.QXSY[options.guid].show = false modValue.QXSY[options.guid].style = new Cesium.Cesium3DTileStyle({ // //写法一 color: "color('rgba(255,255,255," + options.options.opacity + ")')", // //写法2 // color: { // evaluateColor: function (feature, result) { // let color = new Cesium.Color(1, 1, 1, options.options.opacity); // return color; // } // }, show: true, }) } function controlShowQXSY(options) { if (options.options.show) modValue.QXSY[options.guid].show = true if (!options.options.show) modValue.QXSY[options.guid].show = false } function locationQXSY(options) { map3DViewer.map.zoomTo(modValue.QXSY[options.guid]) } return ONEMAP.M.threeData = { add: add, remove: remove, } });