/** * [ONEMAP.M.projectController] * @return {[object]} */ define(function (tplLayout) { /** * 初始化并订阅事件 * @return {[type]} [description] */ /** * 模块数据 用于数据存储和外部调用 * @type {Object} * 数据存放 */ var modValue = { VECTOR: {}, } 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, "layerInfo": item } var guid = null var options = {}; var that = this; $.ajax({ type: "POST", data: { columnId: modelData.layerInfo.id, token: localStorage.getItem("systemToken"), }, dataType: "json", url: onemapUrlConfig.DMS_URL + '/dms/content/getVectorData', success: function (result) { if (result.code != undefined) { ONEMAP.C.publisher.publish({ type: 'warning', message: result.message, }, 'noteBar::add'); return } if (result.features.length == 0) { ONEMAP.C.publisher.publish({ type: 'warning', message: "当前图层无数据!", }, 'noteBar::add'); return } modelData.geo = result guid = add3DVECTOR(modelData); options = { action: "add", DOM: { guid: guid, type: "VECTOR", name: item.title, }, mod: "VECTOR" } if (!guid) return ONEMAP.M.myLayers.myLayerControl(options); // 添加信息到“我的图层” ONEMAP.C.publisher.subscribe(layerAction, guid); } }) } function remove(options) { var guid = options.guid ? options.guid : "VECTOR--" + options.id; removeVECTOR({ guid: guid }) ONEMAP.M.myLayers.myLayerControl({ action: "remove", DOMid: guid }); // 移除数据层 } function bindEvent() { $.ajax({ type: "POST", headers: { token: localStorage.getItem("systemToken"), }, data: { id: onemapUrlConfig.columnConfig.vector.id, }, dataType: "json", url: onemapUrlConfig.DMS_URL + '/dms/column/selectChild', success: function (result) { if (result.code != 200) return let data = result.content; let thrData = data.map(function (item) { return { "category": "倾斜摄影", "info": "", "type": "vector", "name": item.title, "item": item } }) let threeLength = thrData.length; var ul = $(''); for (var i = 0; i < threeLength; i++) { var threeDlist = $('
  • ' + thrData[i].name + '
  • '); ul.append(threeDlist); } var html = ul.html(); $(".vectorContent .menu-content").html(html); $(".vectorContent li").unbind('click').bind('click', function () { var menuCheckBox = $(this).find('.meun-checkBox'); var ztCbx = $(this).find('.zt-cbx'); if (menuCheckBox.hasClass("menu-select-no")) { menuCheckBox.removeClass('menu-select-no').addClass("menu-select"); if (!map23DData.display.map3D) { $("#mapModelChange .bg")[0].click() } var idx = $(this).attr('cid'); var modelData = thrData[idx]; var guid = null var options = {}; let that = this; $.ajax({ type: "POST", data: { columnId: modelData.item.id, token: localStorage.getItem("systemToken"), }, dataType: "json", url: onemapUrlConfig.DMS_URL + '/dms/content/getVectorData', success: function (result) { if (result.code != undefined) { ONEMAP.C.publisher.publish({ type: 'warning', message: result.message, }, 'noteBar::add'); return } guid = add3DVECTOR({ data: result }); options = { action: "add", DOM: { guid: guid, type: "VECTOR", name: $(that).find('.no-bg').text(), }, mod: "VECTOR" } if (!guid) return ztCbx.attr("layer", guid); ztCbx.attr("class", "zt-cbx " + guid); ONEMAP.M.myLayers.myLayerControl(options); // 添加信息到“我的图层” ONEMAP.C.publisher.subscribe(layerAction, guid); } }) } else { menuCheckBox.removeClass('menu-select').addClass("menu-select-no"); var guid = ztCbx.attr("layer"); removeVECTOR(guid) ONEMAP.M.myLayers.myLayerControl({ action: "remove", DOMid: guid }); // 移除数据层 } }) }, error: function (result) { } }) } function layerAction(options) { if (options.guid.split("--")[0] == "VECTOR") { if (options.action == "remove") { // removeVECTOR(options.guid) remove(options) modValue.cancelSelected(Number(options.guid.split("--")[1])); } else if (options.action == "opacity") { opacityVECTOR(options) } else if (options.action == "controlShow") { controlShowVECTOR(options) } else if (options.action == "up" || options.action == "down") { } else if (options.action == "location") { locationVECTOR(options) } } } /** * 加载 * @return {[type]} [description] */ function add3DVECTOR(options) { // var guid = map23DControl.buildGuid('VECTOR-3DData'); var guid = "VECTOR--" + options.layerInfo.id Cesium.GeoJsonDataSource.load(options.geo).then( function (dataSource) { dataSource.name = guid; map3DViewer.map.dataSources.add(dataSource); modValue.VECTOR[guid] = dataSource; var entities = dataSource.entities.values; for (var i = 0; i < entities.length; i++) { var entity = entities[i]; if (entity.billboard) { entity.billboard = undefined; entity.point = new Cesium.PointGraphics({ show: true, pixelSize: 15, heightReference: Cesium.HeightReference.CLAMP_TO_GROUND, color: Cesium.Color.fromCssColorString("#aed0ff"), outlineColor: Cesium.Color.fromCssColorString("#3388ff"), outlineWidth: 2, scaleByDistance: new Cesium.NearFarScalar(10000, 1, 20000, 0.5), // translucencyByDistance: new Cesium.NearFarScalar(1500, 1, 20000, 0.2), // distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0, 20000) }) } if (entity.polyline) { entity.polyline.width = 4; entity.polyline.material = Cesium.Color.fromCssColorString("#3388ff"); // 颜色 } if (entity.polygon) { entity.polygon.height = 0.2; entity.polygon.outline = true; // 边框是否显示 entity.polygon.outlineColor = Cesium.Color.fromCssColorString("#3388ff"); // 边框颜色 entity.polygon.outlineWidth = 4; // 边框宽度 entity.polygon.material = Cesium.Color.fromCssColorString("#aed0ff");// 填充色 } } var extentR = turf.bbox(options.geo); map3DViewer.map.camera.flyTo({ destination: Cesium.Rectangle.fromDegrees(extentR[0], extentR[1], extentR[2], extentR[3]), }); modValue.VECTOR[guid + "_extent"] = extentR; } ); return guid; }; function removeVECTOR(options) { // map3DViewer.map.imageryLayers.remove(modValue.VECTOR[guid]); // delete modValue.VECTOR[guid]; map3DViewer.map.dataSources.remove(map3DViewer.map.dataSources.getByName(options.guid)[0]); delete modValue.VECTOR[options.guid]; } function opacityVECTOR(options) { modValue.VECTOR[options.guid].entities.values.map(function (entity) { if (entity.point) { entity.point = new Cesium.PointGraphics({ show: true, pixelSize: 15, heightReference: Cesium.HeightReference.CLAMP_TO_GROUND, color: Cesium.Color.fromCssColorString("#aed0ff").withAlpha(options.options.opacity), outlineColor: Cesium.Color.fromCssColorString("#3388ff").withAlpha(options.options.opacity), outlineWidth: 2, scaleByDistance: new Cesium.NearFarScalar(10000, 1, 20000, 0.5), }) } if (entity.polyline) { entity.polyline.material = Cesium.Color.fromCssColorString("#3388ff").withAlpha(options.options.opacity); // 颜色 } if (entity.polygon) { entity.polygon.outlineColor = Cesium.Color.fromCssColorString("#3388ff").withAlpha(options.options.opacity); // 边框颜色 entity.polygon.material = Cesium.Color.fromCssColorString("#aed0ff").withAlpha(options.options.opacity);// 填充色 } }) } function controlShowVECTOR(options) { if (options.options.show) modValue.VECTOR[options.guid].show = true if (!options.options.show) modValue.VECTOR[options.guid].show = false } function locationVECTOR(options) { let extentR = modValue.VECTOR[options.guid + "_extent"] map3DViewer.map.camera.flyTo({ destination: Cesium.Rectangle.fromDegrees(extentR[0], extentR[1], extentR[2], extentR[3]), }); } return ONEMAP.M.threeData = { add: add, remove: remove, } });