raster.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. /**
  2. * [ONEMAP.M.projectController]
  3. * @return {[object]}
  4. */
  5. define(function () {
  6. /**
  7. * 初始化并订阅事件
  8. * @return {[type]} [description]
  9. */
  10. /**
  11. * 模块数据 用于数据存储和外部调用
  12. * @type {Object}
  13. * 数据存放
  14. */
  15. var modValue = {
  16. RASTER: {},
  17. cancelSelected: null,
  18. }
  19. function prototypeBind() {
  20. //1.0GLTG插件
  21. var fixGltf = function (gltf) {
  22. if (!gltf.extensionsUsed) {
  23. return;
  24. }
  25. var v = gltf.extensionsUsed.indexOf('KHR_technique_webgl');
  26. var t = gltf.extensionsRequired.indexOf('KHR_technique_webgl');
  27. // 中招了。。
  28. if (v !== -1) {
  29. gltf.extensionsRequired.splice(t, 1, 'KHR_techniques_webgl');
  30. gltf.extensionsUsed.splice(v, 1, 'KHR_techniques_webgl');
  31. gltf.extensions = gltf.extensions || {};
  32. gltf.extensions['KHR_techniques_webgl'] = {};
  33. gltf.extensions['KHR_techniques_webgl'].programs = gltf.programs;
  34. gltf.extensions['KHR_techniques_webgl'].shaders = gltf.shaders;
  35. gltf.extensions['KHR_techniques_webgl'].techniques = gltf.techniques;
  36. var techniques = gltf.extensions['KHR_techniques_webgl'].techniques;
  37. gltf.materials.forEach(function (mat, index) {
  38. gltf.materials[index].extensions['KHR_technique_webgl'].values = gltf.materials[index].values;
  39. gltf.materials[index].extensions['KHR_techniques_webgl'] = gltf.materials[index].extensions['KHR_technique_webgl'];
  40. var vtxfMaterialExtension = gltf.materials[index].extensions['KHR_techniques_webgl'];
  41. for (var value in vtxfMaterialExtension.values) {
  42. var us = techniques[vtxfMaterialExtension.technique].uniforms;
  43. for (var key in us) {
  44. if (us[key] === value) {
  45. vtxfMaterialExtension.values[key] = vtxfMaterialExtension.values[value];
  46. delete vtxfMaterialExtension.values[value];
  47. break;
  48. }
  49. }
  50. };
  51. });
  52. techniques.forEach(function (t) {
  53. for (var attribute in t.attributes) {
  54. var name = t.attributes[attribute];
  55. t.attributes[attribute] = t.parameters[name];
  56. };
  57. for (var uniform in t.uniforms) {
  58. var name = t.uniforms[uniform];
  59. t.uniforms[uniform] = t.parameters[name];
  60. };
  61. });
  62. }
  63. }
  64. Object.defineProperties(Cesium.Model.prototype, {
  65. _cachedGltf: {
  66. set: function (value) {
  67. this._vtxf_cachedGltf = value;
  68. if (this._vtxf_cachedGltf && this._vtxf_cachedGltf._gltf) {
  69. fixGltf(this._vtxf_cachedGltf._gltf);
  70. }
  71. },
  72. get: function () {
  73. return this._vtxf_cachedGltf;
  74. }
  75. }
  76. });
  77. }
  78. function add(item, cancelSelected) {
  79. modValue.cancelSelected = cancelSelected
  80. var modelData = {
  81. "category": "倾斜摄影",
  82. "info": "",
  83. "type": "raster",
  84. "name": item.title,
  85. "item": item,
  86. "layerInfo": item
  87. }
  88. var guid = null
  89. var options = {};
  90. guid = add3DRASTER(modelData);
  91. options = {
  92. action: "add",
  93. DOM: {
  94. guid: guid,
  95. type: "RASTER",
  96. name: item.title,
  97. },
  98. mod: "RASTER"
  99. }
  100. if (!guid) return
  101. ONEMAP.M.myLayers.myLayerControl(options); // 添加信息到“我的图层”
  102. ONEMAP.C.publisher.subscribe(layerAction, guid);
  103. }
  104. function remove(options) {
  105. var guid = options.guid ? options.guid : "RASTER--" + options.id;
  106. removeRASTER(guid)
  107. modValue.cancelSelected(guid);
  108. ONEMAP.M.myLayers.myLayerControl({
  109. action: "remove",
  110. DOMid: guid
  111. }); // 移除数据层
  112. }
  113. function layerAction(options) {
  114. if (options.guid.split("--")[0] == "RASTER") {
  115. if (options.action == "remove") {
  116. // removeRASTER(options.guid)
  117. remove(options)
  118. modValue.cancelSelected(options.guid.split("--")[1]);
  119. } else if (options.action == "opacity") {
  120. opacityRASTER(options)
  121. } else if (options.action == "controlShow") {
  122. controlShowRASTER(options)
  123. } else if (options.action == "up" || options.action == "down") {
  124. } else if (options.action == "location") {
  125. locationVECTOR(options)
  126. }
  127. }
  128. }
  129. /**
  130. * 加载/移除倾斜摄影
  131. * @return {[type]} [description]
  132. */
  133. function add3DRASTER(options) {
  134. // var guid = map23DControl.buildGuid('RASTER-3DData');
  135. var guid = 'RASTER--' + options.layerInfo.id
  136. var items = options.item;
  137. let indexGuid = "";
  138. if (items.c_tile_server_type == "0") {
  139. // arcgis
  140. indexGuid += "0"
  141. } else if (items.c_tile_server_type == "1") {
  142. // xyz
  143. indexGuid += "1"
  144. }
  145. if (items.c_epsg == "EPSG:4326") {
  146. indexGuid += "0"
  147. } else if (items.c_epsg == "EPSG:sh2000") {
  148. indexGuid += "1"
  149. }
  150. var layer = null;
  151. switch (indexGuid) {
  152. case "00":
  153. layer = map3DViewer.map.imageryLayers.addImageryProvider(new Cesium.ArcGisMapServerImageryProvider({
  154. url: items.c_url
  155. }));
  156. break;
  157. case "01":
  158. layer = map3DViewer.map.imageryLayers.addImageryProvider(new Cesium.CGCS2000ArcGisMapServerImageryProvider({
  159. url: items.c_url
  160. }));
  161. break;
  162. case "10":
  163. layer = map3DViewer.map.imageryLayers.addImageryProvider(new Cesium.UrlTemplateImageryProvider({
  164. url: items.c_url
  165. }));
  166. break;
  167. case "11":
  168. break;
  169. default:
  170. break;
  171. }
  172. var bbox = JSON.parse(items.c_bbox)
  173. var extentR = turf.bbox(bbox);
  174. Cesium.Rectangle.fromDegrees(extentR[0], extentR[1], extentR[2], extentR[3])
  175. map3DViewer.map.camera.flyTo({
  176. destination: Cesium.Rectangle.fromDegrees(extentR[0], extentR[1], extentR[2], extentR[3]),
  177. });
  178. modValue.RASTER[guid] = layer
  179. modValue.RASTER[guid + "_extent"] = extentR
  180. return guid;
  181. };
  182. function removeRASTER(guid) {
  183. map3DViewer.map.imageryLayers.remove(modValue.RASTER[guid]);
  184. delete modValue.RASTER[guid];
  185. }
  186. function opacityRASTER(options) {
  187. modValue.RASTER[options.guid].alpha = options.options.opacity
  188. }
  189. function controlShowRASTER(options) {
  190. if (options.options.show)
  191. modValue.RASTER[options.guid].show = true
  192. if (!options.options.show)
  193. modValue.RASTER[options.guid].show = false
  194. }
  195. function locationVECTOR(options) {
  196. let extentR = modValue.RASTER[options.guid + "_extent"]
  197. map3DViewer.map.camera.flyTo({
  198. destination: Cesium.Rectangle.fromDegrees(extentR[0], extentR[1], extentR[2], extentR[3]),
  199. });
  200. }
  201. return ONEMAP.M.Raster = {
  202. add: add,
  203. remove: remove,
  204. }
  205. });