vector.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  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. }
  18. function prototypeBind() {
  19. //1.0GLTG插件
  20. var fixGltf = function (gltf) {
  21. if (!gltf.extensionsUsed) {
  22. return;
  23. }
  24. var v = gltf.extensionsUsed.indexOf('KHR_technique_webgl');
  25. var t = gltf.extensionsRequired.indexOf('KHR_technique_webgl');
  26. // 中招了。。
  27. if (v !== -1) {
  28. gltf.extensionsRequired.splice(t, 1, 'KHR_techniques_webgl');
  29. gltf.extensionsUsed.splice(v, 1, 'KHR_techniques_webgl');
  30. gltf.extensions = gltf.extensions || {};
  31. gltf.extensions['KHR_techniques_webgl'] = {};
  32. gltf.extensions['KHR_techniques_webgl'].programs = gltf.programs;
  33. gltf.extensions['KHR_techniques_webgl'].shaders = gltf.shaders;
  34. gltf.extensions['KHR_techniques_webgl'].techniques = gltf.techniques;
  35. var techniques = gltf.extensions['KHR_techniques_webgl'].techniques;
  36. gltf.materials.forEach(function (mat, index) {
  37. gltf.materials[index].extensions['KHR_technique_webgl'].values = gltf.materials[index].values;
  38. gltf.materials[index].extensions['KHR_techniques_webgl'] = gltf.materials[index].extensions['KHR_technique_webgl'];
  39. var vtxfMaterialExtension = gltf.materials[index].extensions['KHR_techniques_webgl'];
  40. for (var value in vtxfMaterialExtension.values) {
  41. var us = techniques[vtxfMaterialExtension.technique].uniforms;
  42. for (var key in us) {
  43. if (us[key] === value) {
  44. vtxfMaterialExtension.values[key] = vtxfMaterialExtension.values[value];
  45. delete vtxfMaterialExtension.values[value];
  46. break;
  47. }
  48. }
  49. };
  50. });
  51. techniques.forEach(function (t) {
  52. for (var attribute in t.attributes) {
  53. var name = t.attributes[attribute];
  54. t.attributes[attribute] = t.parameters[name];
  55. };
  56. for (var uniform in t.uniforms) {
  57. var name = t.uniforms[uniform];
  58. t.uniforms[uniform] = t.parameters[name];
  59. };
  60. });
  61. }
  62. }
  63. Object.defineProperties(Cesium.Model.prototype, {
  64. _cachedGltf: {
  65. set: function (value) {
  66. this._vtxf_cachedGltf = value;
  67. if (this._vtxf_cachedGltf && this._vtxf_cachedGltf._gltf) {
  68. fixGltf(this._vtxf_cachedGltf._gltf);
  69. }
  70. },
  71. get: function () {
  72. return this._vtxf_cachedGltf;
  73. }
  74. }
  75. });
  76. }
  77. function add(item, cancelSelected) {
  78. modValue.cancelSelected = cancelSelected
  79. var modelData = {
  80. "category": "倾斜摄影",
  81. "info": "",
  82. "name": item.title,
  83. "layerInfo": item
  84. }
  85. var guid = null
  86. var options = {};
  87. var that = this;
  88. $.ajax({
  89. type: "POST",
  90. data: {
  91. columnId: modelData.layerInfo.id,
  92. token: localStorage.getItem("systemToken"),
  93. },
  94. dataType: "json",
  95. url: onemapUrlConfig.DMS_URL + '/dms/content/getVectorData',
  96. success: function (result) {
  97. if (result.code != undefined) {
  98. ONEMAP.C.publisher.publish({
  99. type: 'warning',
  100. message: result.message,
  101. }, 'noteBar::add');
  102. return
  103. }
  104. if (result.features.length == 0) {
  105. ONEMAP.C.publisher.publish({
  106. type: 'warning',
  107. message: "当前图层无数据!",
  108. }, 'noteBar::add');
  109. return
  110. }
  111. modelData.geo = result
  112. guid = add3DVECTOR(modelData);
  113. options = {
  114. action: "add",
  115. DOM: {
  116. guid: guid,
  117. type: "VECTOR",
  118. name: item.title,
  119. },
  120. mod: "VECTOR"
  121. }
  122. if (!guid) return
  123. ONEMAP.M.myLayers.myLayerControl(options); // 添加信息到“我的图层”
  124. ONEMAP.C.publisher.subscribe(layerAction, guid);
  125. }
  126. })
  127. }
  128. function remove(options) {
  129. var guid = options.guid ? options.guid : "VECTOR--" + options.id;
  130. removeVECTOR({ guid: guid })
  131. ONEMAP.M.myLayers.myLayerControl({
  132. action: "remove",
  133. DOMid: guid
  134. }); // 移除数据层
  135. }
  136. function bindEvent() {
  137. $.ajax({
  138. type: "POST",
  139. headers: {
  140. token: localStorage.getItem("systemToken"),
  141. },
  142. data: {
  143. id: onemapUrlConfig.columnConfig.vector.id,
  144. },
  145. dataType: "json",
  146. url: onemapUrlConfig.DMS_URL + '/dms/column/selectChild',
  147. success: function (result) {
  148. if (result.code != 200) return
  149. let data = result.content;
  150. let thrData = data.map(function (item) {
  151. return {
  152. "category": "倾斜摄影",
  153. "info": "",
  154. "type": "vector",
  155. "name": item.title,
  156. "item": item
  157. }
  158. })
  159. let threeLength = thrData.length;
  160. var ul = $('<ul class="menu-content"></ul>');
  161. for (var i = 0; i < threeLength; i++) {
  162. 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>');
  163. ul.append(threeDlist);
  164. }
  165. var html = ul.html();
  166. $(".vectorContent .menu-content").html(html);
  167. $(".vectorContent li").unbind('click').bind('click', function () {
  168. var menuCheckBox = $(this).find('.meun-checkBox');
  169. var ztCbx = $(this).find('.zt-cbx');
  170. if (menuCheckBox.hasClass("menu-select-no")) {
  171. menuCheckBox.removeClass('menu-select-no').addClass("menu-select");
  172. if (!map23DData.display.map3D) {
  173. $("#mapModelChange .bg")[0].click()
  174. }
  175. var idx = $(this).attr('cid');
  176. var modelData = thrData[idx];
  177. var guid = null
  178. var options = {};
  179. let that = this;
  180. $.ajax({
  181. type: "POST",
  182. data: {
  183. columnId: modelData.item.id,
  184. token: localStorage.getItem("systemToken"),
  185. },
  186. dataType: "json",
  187. url: onemapUrlConfig.DMS_URL + '/dms/content/getVectorData',
  188. success: function (result) {
  189. if (result.code != undefined) {
  190. ONEMAP.C.publisher.publish({
  191. type: 'warning',
  192. message: result.message,
  193. }, 'noteBar::add');
  194. return
  195. }
  196. guid = add3DVECTOR({ data: result });
  197. options = {
  198. action: "add",
  199. DOM: {
  200. guid: guid,
  201. type: "VECTOR",
  202. name: $(that).find('.no-bg').text(),
  203. },
  204. mod: "VECTOR"
  205. }
  206. if (!guid) return
  207. ztCbx.attr("layer", guid);
  208. ztCbx.attr("class", "zt-cbx " + guid);
  209. ONEMAP.M.myLayers.myLayerControl(options); // 添加信息到“我的图层”
  210. ONEMAP.C.publisher.subscribe(layerAction, guid);
  211. }
  212. })
  213. } else {
  214. menuCheckBox.removeClass('menu-select').addClass("menu-select-no");
  215. var guid = ztCbx.attr("layer");
  216. removeVECTOR(guid)
  217. ONEMAP.M.myLayers.myLayerControl({
  218. action: "remove",
  219. DOMid: guid
  220. }); // 移除数据层
  221. }
  222. })
  223. },
  224. error: function (result) {
  225. }
  226. })
  227. }
  228. function layerAction(options) {
  229. if (options.guid.split("--")[0] == "VECTOR") {
  230. if (options.action == "remove") {
  231. // removeVECTOR(options.guid)
  232. remove(options)
  233. modValue.cancelSelected(Number(options.guid.split("--")[1]));
  234. } else if (options.action == "opacity") {
  235. opacityVECTOR(options)
  236. } else if (options.action == "controlShow") {
  237. controlShowVECTOR(options)
  238. } else if (options.action == "up" || options.action == "down") {
  239. } else if (options.action == "location") {
  240. locationVECTOR(options)
  241. }
  242. }
  243. }
  244. /**
  245. * 加载
  246. * @return {[type]} [description]
  247. */
  248. function add3DVECTOR(options) {
  249. // var guid = map23DControl.buildGuid('VECTOR-3DData');
  250. var guid = "VECTOR--" + options.layerInfo.id
  251. Cesium.GeoJsonDataSource.load(options.geo).then(
  252. function (dataSource) {
  253. dataSource.name = guid;
  254. map3DViewer.map.dataSources.add(dataSource);
  255. modValue.VECTOR[guid] = dataSource;
  256. var entities = dataSource.entities.values;
  257. for (var i = 0; i < entities.length; i++) {
  258. var entity = entities[i];
  259. if (entity.billboard) {
  260. entity.billboard = undefined;
  261. entity.point = new Cesium.PointGraphics({
  262. show: true,
  263. pixelSize: 15,
  264. heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
  265. color: Cesium.Color.fromCssColorString("#aed0ff"),
  266. outlineColor: Cesium.Color.fromCssColorString("#3388ff"),
  267. outlineWidth: 2,
  268. scaleByDistance: new Cesium.NearFarScalar(10000, 1, 20000, 0.5),
  269. // translucencyByDistance: new Cesium.NearFarScalar(1500, 1, 20000, 0.2),
  270. // distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0, 20000)
  271. })
  272. }
  273. if (entity.polyline) {
  274. entity.polyline.width = 4;
  275. entity.polyline.material = Cesium.Color.fromCssColorString("#3388ff"); // 颜色
  276. }
  277. if (entity.polygon) {
  278. entity.polygon.height = 0.2;
  279. entity.polygon.outline = true; // 边框是否显示
  280. entity.polygon.outlineColor = Cesium.Color.fromCssColorString("#3388ff"); // 边框颜色
  281. entity.polygon.outlineWidth = 4; // 边框宽度
  282. entity.polygon.material = Cesium.Color.fromCssColorString("#aed0ff");// 填充色
  283. }
  284. }
  285. var extentR = turf.bbox(options.geo);
  286. map3DViewer.map.camera.flyTo({
  287. destination: Cesium.Rectangle.fromDegrees(extentR[0], extentR[1], extentR[2], extentR[3]),
  288. });
  289. modValue.VECTOR[guid + "_extent"] = extentR;
  290. }
  291. );
  292. return guid;
  293. };
  294. function removeVECTOR(options) {
  295. // map3DViewer.map.imageryLayers.remove(modValue.VECTOR[guid]);
  296. // delete modValue.VECTOR[guid];
  297. map3DViewer.map.dataSources.remove(map3DViewer.map.dataSources.getByName(options.guid)[0]);
  298. delete modValue.VECTOR[options.guid];
  299. }
  300. function opacityVECTOR(options) {
  301. modValue.VECTOR[options.guid].entities.values.map(function (entity) {
  302. if (entity.point) {
  303. entity.point = new Cesium.PointGraphics({
  304. show: true,
  305. pixelSize: 15,
  306. heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
  307. color: Cesium.Color.fromCssColorString("#aed0ff").withAlpha(options.options.opacity),
  308. outlineColor: Cesium.Color.fromCssColorString("#3388ff").withAlpha(options.options.opacity),
  309. outlineWidth: 2,
  310. scaleByDistance: new Cesium.NearFarScalar(10000, 1, 20000, 0.5),
  311. })
  312. }
  313. if (entity.polyline) {
  314. entity.polyline.material = Cesium.Color.fromCssColorString("#3388ff").withAlpha(options.options.opacity); // 颜色
  315. }
  316. if (entity.polygon) {
  317. entity.polygon.outlineColor = Cesium.Color.fromCssColorString("#3388ff").withAlpha(options.options.opacity); // 边框颜色
  318. entity.polygon.material = Cesium.Color.fromCssColorString("#aed0ff").withAlpha(options.options.opacity);// 填充色
  319. }
  320. })
  321. }
  322. function controlShowVECTOR(options) {
  323. if (options.options.show)
  324. modValue.VECTOR[options.guid].show = true
  325. if (!options.options.show)
  326. modValue.VECTOR[options.guid].show = false
  327. }
  328. function locationVECTOR(options) {
  329. let extentR = modValue.VECTOR[options.guid + "_extent"]
  330. map3DViewer.map.camera.flyTo({
  331. destination: Cesium.Rectangle.fromDegrees(extentR[0], extentR[1], extentR[2], extentR[3]),
  332. });
  333. }
  334. return ONEMAP.M.threeData = {
  335. add: add,
  336. remove: remove,
  337. }
  338. });