123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230 |
- /**
- * [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,
- }
- });
|