/** * [ONEMAP.M.projectController] * @return {[object]} */ define(function () { /** * 初始化并订阅事件 * @return {[type]} [description] */ /** * 模块数据 用于数据存储和外部调用 * @type {Object} * 数据存放 */ var modValue = { RASTER: {}, 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": "", "type": "raster", "name": item.title, "item": item, "layerInfo": item } var guid = null var options = {}; guid = add3DRASTER(modelData); options = { action: "add", DOM: { guid: guid, type: "RASTER", name: item.title, }, mod: "RASTER" } if (!guid) return ONEMAP.M.myLayers.myLayerControl(options); // 添加信息到“我的图层” ONEMAP.C.publisher.subscribe(layerAction, guid); } function remove(options) { var guid = options.guid ? options.guid : "RASTER--" + options.id; removeRASTER(guid) modValue.cancelSelected(guid); ONEMAP.M.myLayers.myLayerControl({ action: "remove", DOMid: guid }); // 移除数据层 } function layerAction(options) { if (options.guid.split("--")[0] == "RASTER") { if (options.action == "remove") { // removeRASTER(options.guid) remove(options) modValue.cancelSelected(options.guid.split("--")[1]); } else if (options.action == "opacity") { opacityRASTER(options) } else if (options.action == "controlShow") { controlShowRASTER(options) } else if (options.action == "up" || options.action == "down") { } else if (options.action == "location") { locationVECTOR(options) } } } /** * 加载/移除倾斜摄影 * @return {[type]} [description] */ function add3DRASTER(options) { // var guid = map23DControl.buildGuid('RASTER-3DData'); var guid = 'RASTER--' + options.layerInfo.id var items = options.item; let indexGuid = ""; if (items.c_tile_server_type == "0") { // arcgis indexGuid += "0" } else if (items.c_tile_server_type == "1") { // xyz indexGuid += "1" } if (items.c_epsg == "EPSG:4326") { indexGuid += "0" } else if (items.c_epsg == "EPSG:sh2000") { indexGuid += "1" } var layer = null; switch (indexGuid) { case "00": layer = map3DViewer.map.imageryLayers.addImageryProvider(new Cesium.ArcGisMapServerImageryProvider({ url: items.c_url })); break; case "01": layer = map3DViewer.map.imageryLayers.addImageryProvider(new Cesium.CGCS2000ArcGisMapServerImageryProvider({ url: items.c_url })); break; case "10": layer = map3DViewer.map.imageryLayers.addImageryProvider(new Cesium.UrlTemplateImageryProvider({ url: items.c_url })); break; case "11": break; default: break; } var bbox = JSON.parse(items.c_bbox) var extentR = turf.bbox(bbox); Cesium.Rectangle.fromDegrees(extentR[0], extentR[1], extentR[2], extentR[3]) map3DViewer.map.camera.flyTo({ destination: Cesium.Rectangle.fromDegrees(extentR[0], extentR[1], extentR[2], extentR[3]), }); modValue.RASTER[guid] = layer modValue.RASTER[guid + "_extent"] = extentR return guid; }; function removeRASTER(guid) { map3DViewer.map.imageryLayers.remove(modValue.RASTER[guid]); delete modValue.RASTER[guid]; } function opacityRASTER(options) { modValue.RASTER[options.guid].alpha = options.options.opacity } function controlShowRASTER(options) { if (options.options.show) modValue.RASTER[options.guid].show = true if (!options.options.show) modValue.RASTER[options.guid].show = false } function locationVECTOR(options) { let extentR = modValue.RASTER[options.guid + "_extent"] map3DViewer.map.camera.flyTo({ destination: Cesium.Rectangle.fromDegrees(extentR[0], extentR[1], extentR[2], extentR[3]), }); } return ONEMAP.M.Raster = { add: add, remove: remove, } });