raster.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. /**
  2. * [ONEMAP.M.projectController]
  3. * @return {[object]}
  4. */
  5. define(function (tplLayout) {
  6. /**
  7. * 初始化并订阅事件
  8. * @return {[type]} [description]
  9. */
  10. /**
  11. * 模块数据 用于数据存储和外部调用
  12. * @type {Object}
  13. * 数据存放
  14. */
  15. var modValue = {
  16. RASTER: {},
  17. model: {},
  18. seleted_guid: null,
  19. stereoscopic_handle: null,
  20. }
  21. /**
  22. * 状态值
  23. * @type {Boolean}
  24. * @default false
  25. * @private
  26. */
  27. var status = {
  28. initialized: false,
  29. isShowChild: false,
  30. connect: false,
  31. webSocketState: false
  32. };
  33. function init() {
  34. if (!localStorage.getItem("systemToken")) {
  35. ONEMAP.C.publisher.publish({
  36. type: 'warning',
  37. message: '用户尚未登录!'
  38. }, 'noteBar::add');
  39. return;
  40. }
  41. if (!status.initialized) {
  42. subscribe();
  43. bindEvent();
  44. // prototypeBind();
  45. status.initialized = true;
  46. // $("#threeData").parent().find(".menu-content").show();
  47. }
  48. ONEMAP.C.publisher.publish({
  49. modName: 'raster'
  50. }, 'menuListClick');
  51. }
  52. function prototypeBind() {
  53. //1.0GLTG插件
  54. var fixGltf = function (gltf) {
  55. if (!gltf.extensionsUsed) {
  56. return;
  57. }
  58. var v = gltf.extensionsUsed.indexOf('KHR_technique_webgl');
  59. var t = gltf.extensionsRequired.indexOf('KHR_technique_webgl');
  60. // 中招了。。
  61. if (v !== -1) {
  62. gltf.extensionsRequired.splice(t, 1, 'KHR_techniques_webgl');
  63. gltf.extensionsUsed.splice(v, 1, 'KHR_techniques_webgl');
  64. gltf.extensions = gltf.extensions || {};
  65. gltf.extensions['KHR_techniques_webgl'] = {};
  66. gltf.extensions['KHR_techniques_webgl'].programs = gltf.programs;
  67. gltf.extensions['KHR_techniques_webgl'].shaders = gltf.shaders;
  68. gltf.extensions['KHR_techniques_webgl'].techniques = gltf.techniques;
  69. var techniques = gltf.extensions['KHR_techniques_webgl'].techniques;
  70. gltf.materials.forEach(function (mat, index) {
  71. gltf.materials[index].extensions['KHR_technique_webgl'].values = gltf.materials[index].values;
  72. gltf.materials[index].extensions['KHR_techniques_webgl'] = gltf.materials[index].extensions['KHR_technique_webgl'];
  73. var vtxfMaterialExtension = gltf.materials[index].extensions['KHR_techniques_webgl'];
  74. for (var value in vtxfMaterialExtension.values) {
  75. var us = techniques[vtxfMaterialExtension.technique].uniforms;
  76. for (var key in us) {
  77. if (us[key] === value) {
  78. vtxfMaterialExtension.values[key] = vtxfMaterialExtension.values[value];
  79. delete vtxfMaterialExtension.values[value];
  80. break;
  81. }
  82. }
  83. };
  84. });
  85. techniques.forEach(function (t) {
  86. for (var attribute in t.attributes) {
  87. var name = t.attributes[attribute];
  88. t.attributes[attribute] = t.parameters[name];
  89. };
  90. for (var uniform in t.uniforms) {
  91. var name = t.uniforms[uniform];
  92. t.uniforms[uniform] = t.parameters[name];
  93. };
  94. });
  95. }
  96. }
  97. Object.defineProperties(Cesium.Model.prototype, {
  98. _cachedGltf: {
  99. set: function (value) {
  100. this._vtxf_cachedGltf = value;
  101. if (this._vtxf_cachedGltf && this._vtxf_cachedGltf._gltf) {
  102. fixGltf(this._vtxf_cachedGltf._gltf);
  103. }
  104. },
  105. get: function () {
  106. return this._vtxf_cachedGltf;
  107. }
  108. }
  109. });
  110. }
  111. function bindEvent() {
  112. $.ajax({
  113. type: "POST",
  114. headers: {
  115. token: localStorage.getItem("systemToken"),
  116. },
  117. data: {
  118. columnId: onemapUrlConfig.columnConfig.raster.id,
  119. states: "3",
  120. pageSize: 1000,
  121. page: 0,
  122. },
  123. dataType: "json",
  124. url: onemapUrlConfig.DMS_URL + '/dms/content/selectContentList',
  125. success: function (result) {
  126. if (result.code != 200) {
  127. ONEMAP.C.publisher.publish({
  128. type: 'warning',
  129. message: result.message,
  130. }, 'noteBar::add');
  131. return
  132. }
  133. let data = result.content.data;
  134. let thrData = data.map(function (item) {
  135. return {
  136. "category": "倾斜摄影",
  137. "info": "",
  138. "type": "raster",
  139. "name": item.title,
  140. "item": item
  141. }
  142. })
  143. let threeLength = thrData.length;
  144. var ul = $('<ul class="menu-content"></ul>');
  145. for (var i = 0; i < threeLength; i++) {
  146. var threeDlist = $('<li class="item" cid="' + i + '"><input type="checkbox" class="zt-cbx" layer=""><span class="meun-checkBox menu-select-no"></span><span class="no-bg">' + thrData[i].name + '</span></li>');
  147. ul.append(threeDlist);
  148. }
  149. var html = ul.html();
  150. $(".rasterContent .menu-content").html(html);
  151. $(".rasterContent li").unbind('click').bind('click', function () {
  152. var menuCheckBox = $(this).find('.meun-checkBox');
  153. var ztCbx = $(this).find('.zt-cbx');
  154. if (menuCheckBox.hasClass("menu-select-no")) {
  155. menuCheckBox.removeClass('menu-select-no').addClass("menu-select");
  156. if (!map23DData.display.map3D) {
  157. $("#mapModelChange .bg")[0].click()
  158. }
  159. var idx = $(this).attr('cid');
  160. var modelData = thrData[idx];
  161. var guid = null
  162. var options = {};
  163. guid = add3DRASTER(modelData);
  164. options = {
  165. action: "add",
  166. DOM: {
  167. guid: guid,
  168. type: "RASTER",
  169. name: $(this).find('.no-bg').text(),
  170. },
  171. mod: "RASTER"
  172. }
  173. if (!guid) return
  174. ztCbx.attr("layer", guid);
  175. ztCbx.attr("class", "zt-cbx " + guid);
  176. ONEMAP.M.myLayers.myLayerControl(options); // 添加信息到“我的图层”
  177. ONEMAP.C.publisher.subscribe(layerAction, guid);
  178. } else {
  179. menuCheckBox.removeClass('menu-select').addClass("menu-select-no");
  180. var guid = ztCbx.attr("layer");
  181. removeRASTER(guid)
  182. ONEMAP.M.myLayers.myLayerControl({
  183. action: "remove",
  184. DOMid: guid
  185. }); // 移除数据层
  186. }
  187. })
  188. },
  189. error: function (result) {
  190. }
  191. })
  192. }
  193. function layerAction(options) {
  194. if (options.guid.split("-")[0] == "RASTER") {
  195. if (options.action == "remove") {
  196. removeRASTER(options.guid)
  197. } else if (options.action == "opacity") {
  198. opacityRASTER(options)
  199. } else if (options.action == "controlShow") {
  200. controlShowRASTER(options)
  201. } else if (options.action == "up" || options.action == "down") {
  202. } else if (options.action == "location") {
  203. locationVECTOR(options)
  204. }
  205. }
  206. }
  207. /**
  208. * 加载/移除倾斜摄影
  209. * @return {[type]} [description]
  210. */
  211. function add3DRASTER(options) {
  212. var guid = map23DControl.buildGuid('RASTER-3DData');
  213. var items = options.item;
  214. let indexGuid = "";
  215. if (items.tile_server_type == "0") {
  216. // arcgis
  217. indexGuid += "0"
  218. } else if (items.tile_server_type == "1") {
  219. // xyz
  220. indexGuid += "1"
  221. }
  222. if (items.c_epsg == "EPSG:4326") {
  223. indexGuid += "0"
  224. }
  225. if (items.c_epsg == "EPSG:sh2000") {
  226. indexGuid += "1"
  227. }
  228. var layer = null;
  229. switch (indexGuid) {
  230. case "00":
  231. layer = map3DViewer.map.imageryLayers.addImageryProvider(new Cesium.ArcGisMapServerImageryProvider({
  232. url: items.c_url
  233. }));
  234. break;
  235. case "01":
  236. layer = map3DViewer.map.imageryLayers.addImageryProvider(new Cesium.CGCS2000ArcGisMapServerImageryProvider({
  237. url: items.c_url
  238. }));
  239. break;
  240. case "10":
  241. layer = map3DViewer.map.imageryLayers.addImageryProvider(new Cesium.UrlTemplateImageryProvider({
  242. url: items.c_url
  243. }));
  244. break;
  245. case "11":
  246. break;
  247. default:
  248. break;
  249. }
  250. var bbox = JSON.parse(items.c_bbox)
  251. var extentR = turf.bbox(bbox);
  252. Cesium.Rectangle.fromDegrees(extentR[0], extentR[1], extentR[2], extentR[3])
  253. map3DViewer.map.camera.flyTo({
  254. destination: Cesium.Rectangle.fromDegrees(extentR[0], extentR[1], extentR[2], extentR[3]),
  255. });
  256. modValue.RASTER[guid] = layer
  257. modValue.RASTER[guid + "_extent"] = extentR
  258. return guid;
  259. };
  260. function removeRASTER(guid) {
  261. map3DViewer.map.imageryLayers.remove(modValue.RASTER[guid]);
  262. delete modValue.RASTER[guid];
  263. }
  264. function opacityRASTER(options) {
  265. modValue.RASTER[options.guid].alpha = options.options.opacity
  266. }
  267. function controlShowRASTER(options) {
  268. if (options.options.show)
  269. modValue.RASTER[options.guid].show = true
  270. if (!options.options.show)
  271. modValue.RASTER[options.guid].show = false
  272. }
  273. function locationVECTOR(options) {
  274. let extentR = modValue.RASTER[options.guid + "_extent"]
  275. map3DViewer.map.camera.flyTo({
  276. destination: Cesium.Rectangle.fromDegrees(extentR[0], extentR[1], extentR[2], extentR[3]),
  277. });
  278. }
  279. /**
  280. * 设置界面
  281. */
  282. function setLayout() {
  283. }
  284. /**
  285. * 界面重置
  286. * @return {[type]} [description]
  287. */
  288. function layoutResize(options) {
  289. if (options.modName != "raster") {
  290. remove();
  291. } else {
  292. if (status.isShowChild) {
  293. remove();
  294. } else {
  295. $("#menu .rasterContent").addClass('active');
  296. status.isShowChild = true;
  297. if (map23DData.show3DAlert) {
  298. ONEMAP.C.publisher.publish('3D', 'layout::mapStyle');
  299. }
  300. }
  301. }
  302. }
  303. /**
  304. * 模块移除
  305. * @return {[type]} [description]
  306. */
  307. function remove() {
  308. //取消订阅
  309. unSubscribe();
  310. $("#menu .rasterContent").removeClass('active');
  311. status.isShowChild = false;
  312. }
  313. /**
  314. * 注册订阅
  315. * @type {Function}
  316. * 推送:ONEMAP.C.publisher.publish(options,'moduleName::type');
  317. * 订阅:ONEMAP.C.publisher.subscribe(layoutResize,'sideBarLayoutChange');
  318. */
  319. function subscribe() {
  320. ONEMAP.C.publisher.subscribe(layoutResize, 'menuListClick');
  321. // ONEMAP.C.publisher.subscribe(remove, 'cleanMap');
  322. }
  323. /**
  324. * 取消订阅
  325. * @type {Function}
  326. * 取消订阅:ONEMAP.C.publisher.unSubscribe(layoutResize,'sideBarLayoutChange');
  327. */
  328. function unSubscribe() {
  329. }
  330. return ONEMAP.M.threeData = {
  331. init: init
  332. }
  333. });