vector.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  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. VECTOR: {},
  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: 'vector'
  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. id: onemapUrlConfig.columnConfig.vector.id,
  119. },
  120. dataType: "json",
  121. url: onemapUrlConfig.DMS_URL + '/dms/column/selectChild',
  122. success: function (result) {
  123. if (result.code != 200) return
  124. let data = result.content;
  125. let thrData = data.map(function (item) {
  126. return {
  127. "category": "倾斜摄影",
  128. "info": "",
  129. "type": "vector",
  130. "name": item.title,
  131. "item": item
  132. }
  133. })
  134. let threeLength = thrData.length;
  135. var ul = $('<ul class="menu-content"></ul>');
  136. for (var i = 0; i < threeLength; i++) {
  137. 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>');
  138. ul.append(threeDlist);
  139. }
  140. var html = ul.html();
  141. $(".vectorContent .menu-content").html(html);
  142. $(".vectorContent li").unbind('click').bind('click', function () {
  143. var menuCheckBox = $(this).find('.meun-checkBox');
  144. var ztCbx = $(this).find('.zt-cbx');
  145. if (menuCheckBox.hasClass("menu-select-no")) {
  146. menuCheckBox.removeClass('menu-select-no').addClass("menu-select");
  147. if (!map23DData.display.map3D) {
  148. $("#mapModelChange .bg")[0].click()
  149. }
  150. var idx = $(this).attr('cid');
  151. var modelData = thrData[idx];
  152. var guid = null
  153. var options = {};
  154. let that = this;
  155. $.ajax({
  156. type: "POST",
  157. data: {
  158. columnId: modelData.item.id,
  159. token: localStorage.getItem("systemToken"),
  160. },
  161. dataType: "json",
  162. url: onemapUrlConfig.DMS_URL + '/dms/content/getVectorData',
  163. success: function (result) {
  164. if (result.code != undefined) {
  165. ONEMAP.C.publisher.publish({
  166. type: 'warning',
  167. message: result.message,
  168. }, 'noteBar::add');
  169. return
  170. }
  171. guid = add3DVECTOR({ data: result });
  172. options = {
  173. action: "add",
  174. DOM: {
  175. guid: guid,
  176. type: "VECTOR",
  177. name: $(that).find('.no-bg').text(),
  178. },
  179. mod: "VECTOR"
  180. }
  181. if (!guid) return
  182. ztCbx.attr("layer", guid);
  183. ztCbx.attr("class", "zt-cbx " + guid);
  184. ONEMAP.M.myLayers.myLayerControl(options); // 添加信息到“我的图层”
  185. ONEMAP.C.publisher.subscribe(layerAction, guid);
  186. }
  187. })
  188. } else {
  189. menuCheckBox.removeClass('menu-select').addClass("menu-select-no");
  190. var guid = ztCbx.attr("layer");
  191. removeVECTOR(guid)
  192. ONEMAP.M.myLayers.myLayerControl({
  193. action: "remove",
  194. DOMid: guid
  195. }); // 移除数据层
  196. }
  197. })
  198. },
  199. error: function (result) {
  200. }
  201. })
  202. }
  203. function layerAction(options) {
  204. if (options.guid.split("-")[0] == "VECTOR") {
  205. if (options.action == "remove") {
  206. removeVECTOR(options.guid)
  207. } else if (options.action == "opacity") {
  208. opacityVECTOR(options)
  209. } else if (options.action == "controlShow") {
  210. controlShowVECTOR(options)
  211. } else if (options.action == "up" || options.action == "down") {
  212. } else if (options.action == "location") {
  213. locationVECTOR(options)
  214. }
  215. }
  216. }
  217. /**
  218. * 加载/移除倾斜摄影
  219. * @return {[type]} [description]
  220. */
  221. function add3DVECTOR(options) {
  222. var guid = map23DControl.buildGuid('VECTOR-3DData');
  223. Cesium.GeoJsonDataSource.load(options.data).then(
  224. function (dataSource) {
  225. dataSource.name = guid;
  226. map3DViewer.map.dataSources.add(dataSource);
  227. modValue.VECTOR[guid] = dataSource;
  228. var entities = dataSource.entities.values;
  229. for (var i = 0; i < entities.length; i++) {
  230. var entity = entities[i];
  231. if (entity.billboard) {
  232. entity.billboard = undefined;
  233. entity.point = new Cesium.PointGraphics({
  234. show: true,
  235. pixelSize: 15,
  236. heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
  237. color: Cesium.Color.fromCssColorString("#aed0ff"),
  238. outlineColor: Cesium.Color.fromCssColorString("#3388ff"),
  239. outlineWidth: 2,
  240. scaleByDistance: new Cesium.NearFarScalar(10000, 1, 20000, 0.5),
  241. // translucencyByDistance: new Cesium.NearFarScalar(1500, 1, 20000, 0.2),
  242. // distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0, 20000)
  243. })
  244. }
  245. if (entity.polyline) {
  246. entity.polyline.width = 4;
  247. entity.polyline.material = Cesium.Color.fromCssColorString("#3388ff"); // 颜色
  248. }
  249. if (entity.polygon) {
  250. entity.polygon.height = 0.2;
  251. entity.polygon.outline = true; // 边框是否显示
  252. entity.polygon.outlineColor = Cesium.Color.fromCssColorString("#3388ff"); // 边框颜色
  253. entity.polygon.outlineWidth = 4; // 边框宽度
  254. entity.polygon.material = Cesium.Color.fromCssColorString("#aed0ff");// 填充色
  255. }
  256. }
  257. var extentR = turf.bbox(options.data);
  258. map3DViewer.map.camera.flyTo({
  259. destination: Cesium.Rectangle.fromDegrees(extentR[0], extentR[1], extentR[2], extentR[3]),
  260. });
  261. modValue.VECTOR[guid + "_extent"] = extentR;
  262. }
  263. );
  264. return guid;
  265. };
  266. function removeVECTOR(guid) {
  267. // map3DViewer.map.imageryLayers.remove(modValue.VECTOR[guid]);
  268. // delete modValue.VECTOR[guid];
  269. map3DViewer.map.dataSources.remove(map3DViewer.map.dataSources.getByName(guid)[0]);
  270. delete modValue.VECTOR[guid];
  271. }
  272. function opacityVECTOR(options) {
  273. modValue.VECTOR[options.guid].entities.values.map(function (entity) {
  274. if (entity.point) {
  275. entity.point = new Cesium.PointGraphics({
  276. show: true,
  277. pixelSize: 15,
  278. heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
  279. color: Cesium.Color.fromCssColorString("#aed0ff").withAlpha(options.options.opacity),
  280. outlineColor: Cesium.Color.fromCssColorString("#3388ff").withAlpha(options.options.opacity),
  281. outlineWidth: 2,
  282. scaleByDistance: new Cesium.NearFarScalar(10000, 1, 20000, 0.5),
  283. })
  284. }
  285. if (entity.polyline) {
  286. entity.polyline.material = Cesium.Color.fromCssColorString("#3388ff").withAlpha(options.options.opacity); // 颜色
  287. }
  288. if (entity.polygon) {
  289. entity.polygon.outlineColor = Cesium.Color.fromCssColorString("#3388ff").withAlpha(options.options.opacity); // 边框颜色
  290. entity.polygon.material = Cesium.Color.fromCssColorString("#aed0ff").withAlpha(options.options.opacity);// 填充色
  291. }
  292. })
  293. }
  294. function controlShowVECTOR(options) {
  295. if (options.options.show)
  296. modValue.VECTOR[options.guid].show = true
  297. if (!options.options.show)
  298. modValue.VECTOR[options.guid].show = false
  299. }
  300. function locationVECTOR(options) {
  301. let extentR = modValue.VECTOR[options.guid + "_extent"]
  302. map3DViewer.map.camera.flyTo({
  303. destination: Cesium.Rectangle.fromDegrees(extentR[0], extentR[1], extentR[2], extentR[3]),
  304. });
  305. }
  306. /**
  307. * 设置界面
  308. */
  309. function setLayout() {
  310. }
  311. /**
  312. * 界面重置
  313. * @return {[type]} [description]
  314. */
  315. function layoutResize(options) {
  316. if (options.modName != "vector") {
  317. remove();
  318. } else {
  319. if (status.isShowChild) {
  320. remove();
  321. } else {
  322. $("#menu .vectorContent").addClass('active');
  323. status.isShowChild = true;
  324. if (map23DData.show3DAlert) {
  325. ONEMAP.C.publisher.publish('3D', 'layout::mapStyle');
  326. }
  327. }
  328. }
  329. }
  330. /**
  331. * 模块移除
  332. * @return {[type]} [description]
  333. */
  334. function remove() {
  335. //取消订阅
  336. unSubscribe();
  337. $("#menu .vectorContent").removeClass('active');
  338. status.isShowChild = false;
  339. }
  340. /**
  341. * 注册订阅
  342. * @type {Function}
  343. * 推送:ONEMAP.C.publisher.publish(options,'moduleName::type');
  344. * 订阅:ONEMAP.C.publisher.subscribe(layoutResize,'sideBarLayoutChange');
  345. */
  346. function subscribe() {
  347. ONEMAP.C.publisher.subscribe(layoutResize, 'menuListClick');
  348. // ONEMAP.C.publisher.subscribe(remove, 'cleanMap');
  349. }
  350. /**
  351. * 取消订阅
  352. * @type {Function}
  353. * 取消订阅:ONEMAP.C.publisher.unSubscribe(layoutResize,'sideBarLayoutChange');
  354. */
  355. function unSubscribe() {
  356. }
  357. return ONEMAP.M.threeData = {
  358. init: init
  359. }
  360. });