MainMap.vue 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106
  1. <template>
  2. <div class="cesium_div" id="cesium_id"></div>
  3. <el-radio-group class="choose" v-model="radio" @change="changeRadio">
  4. <el-radio
  5. v-for="(item, index) in effect"
  6. :key="index"
  7. :label="item.label"
  8. >{{ item.name }}</el-radio
  9. >
  10. </el-radio-group>
  11. <el-switch
  12. v-model="value1"
  13. @change="changeSwitch"
  14. class="switch"
  15. active-text="上海中心大厦"
  16. inactive-text="室内模型"
  17. />
  18. </template>
  19. <script>
  20. export default {
  21. name: "SHLJZ",
  22. props: {
  23. msg: String,
  24. },
  25. data() {
  26. return {
  27. topK: systemConfig.flyLine,
  28. radio: 0,
  29. value1: true,
  30. radius: 1800,
  31. effect: [
  32. {
  33. name: "无",
  34. label: 0,
  35. },
  36. {
  37. name: "雨",
  38. label: 1,
  39. },
  40. {
  41. name: "雪",
  42. label: 2,
  43. },
  44. {
  45. name: "雾",
  46. label: 3,
  47. },
  48. ],
  49. };
  50. },
  51. methods: {},
  52. mounted() {
  53. let that = this;
  54. let viewer = new Cesium.Viewer("cesium_id", {
  55. shouldAnimate: true,
  56. animation: false, //动画控制不显示
  57. timeline: false, //时间线不显示
  58. fullscreenButton: false, //全屏按钮不显示
  59. infoBox: false,
  60. baseLayerPicker: false, //地图切换不显示
  61. imageryProvider: new Cesium.SingleTileImageryProvider({
  62. url: (function createColorCanvas(color) {
  63. let width = 1,
  64. height = 1;
  65. let canvas = document.createElement("canvas");
  66. canvas.width = width;
  67. canvas.height = height;
  68. let ctx = canvas.getContext("2d");
  69. ctx.fillStyle = color;
  70. ctx.fillRect(0, 0, width, height);
  71. return canvas.toDataURL();
  72. })("#ffffff00"),
  73. rectangle: Cesium.Rectangle.fromDegrees(-180.0, -90.0, 180.0, 90.0),
  74. }),
  75. geocoder: false,
  76. homeButton: false,
  77. selectionIndicator: false, // 去除绿色选择框
  78. sceneModePicker: false,
  79. navigationHelpButton: false,
  80. scene3DOnly: true, // 仅以3D渲染以节省GPU内存
  81. useBrowserRecommendedResolution: true, // 以浏览器建议的分辨率渲染
  82. });
  83. globalVariable.viewer = viewer;
  84. viewer.camera.flyTo({
  85. destination: Cesium.Cartesian3.fromDegrees(
  86. 121.49254337380488,
  87. 31.219286378124917,
  88. 631.5765993791605
  89. ),
  90. orientation: {
  91. heading: Cesium.Math.toRadians(30.69861679518457),
  92. pitch: Cesium.Math.toRadians(-12.45131041368068),
  93. roll: 0.0,
  94. },
  95. });
  96. //去除版权标记
  97. viewer._cesiumWidget._creditContainer.style.display = "none";
  98. // 关闭太原光
  99. // viewer.scene.sun.show = true;
  100. // 开启阴影
  101. // viewer.shadows = true;
  102. // 阴影强度
  103. // viewer.shadowMap.darkness = 0.65;
  104. this.initMap(viewer);
  105. this.addEffect(viewer);
  106. // 白膜
  107. let shBmTileset = this.add3DTiles(
  108. viewer,
  109. systemConfig.server.lujiazui,
  110. false
  111. );
  112. shBmTileset.readyPromise.then(function (tileset) {
  113. tileset.style = new Cesium.Cesium3DTileStyle({
  114. color: {
  115. conditions: [
  116. ["true", "color('rgb(33,76,142)',0.7)"], //135,206,250 51, 153, 255
  117. ],
  118. },
  119. });
  120. that.panyi(tileset);
  121. });
  122. shBmTileset.customShader = new Cesium.CustomShader({
  123. lightingModel: Cesium.LightingModel.UNLIT,
  124. fragmentShaderText: `
  125. void fragmentMain(FragmentInput fsInput, inout czm_modelMaterial material) {
  126. float _baseHeight = 0.0; // 物体的基础高度,需要修改成一个合适的建筑基础高度
  127. float _heightRange = 50.0; // 高亮的范围(_baseHeight ~ _baseHeight + _ heightRange) 默认是 0-60米
  128. float _glowRange = 300.0; // 光环的移动范围(高度)
  129. vec3 position = fsInput.attributes.positionMC;
  130. float vtxf_height = position.y-_baseHeight;
  131. float vtxf_a11 = fract(czm_frameNumber / 120.0) * 3.14159265 * 2.0;
  132. float vtxf_a12 = vtxf_height / _heightRange + vtxf_a11 * 0.1;
  133. material.diffuse*= vec3(vtxf_a12, vtxf_a12, vtxf_a12);
  134. float time = fract(czm_frameNumber / 1000.0);
  135. time = abs(time - 0.5) * 1.2;
  136. float diff = step(0.005, abs(clamp(position.y / _glowRange, 0.0, 1.0) - time));
  137. material.diffuse += material.diffuse * (1.0 - diff);
  138. }
  139. `,
  140. });
  141. // 张金雨建模 外
  142. let shzxZJYTileset_N = this.add3DTiles(
  143. viewer,
  144. systemConfig.server.shzxZJY_wai,
  145. false
  146. );
  147. this.shzxZJYTileset_N = shzxZJYTileset_N;
  148. shzxZJYTileset_N.readyPromise.then(function (tileset) {
  149. tileset.style = new Cesium.Cesium3DTileStyle({
  150. color: {
  151. conditions: [
  152. // ["true", "color('rgb(0,255,255)',0.6)"]//135,206,250 51, 153, 255
  153. ["true", "color('rgb(0,252,255)',0.8)"], //135,206,250 51, 153, 255
  154. ],
  155. },
  156. });
  157. that.panyi(tileset);
  158. });
  159. shzxZJYTileset_N.customShader = new Cesium.CustomShader({
  160. lightingModel: Cesium.LightingModel.UNLIT,
  161. varyings: {
  162. v_normalMC: Cesium.VaryingType.VEC3,
  163. },
  164. vertexShaderText: `
  165. void vertexMain(VertexInput vsInput, inout czm_modelVertexOutput vsOutput) {
  166. v_normalMC = vsInput.attributes.normalMC;
  167. }
  168. `,
  169. fragmentShaderText: `
  170. void fragmentMain(FragmentInput fsInput, inout czm_modelMaterial material) {
  171. float _baseHeight = 0.0; // 物体的基础高度,需要修改成一个合适的建筑基础高度
  172. float _heightRange = 200.0; // 高亮的范围(_baseHeight ~ _baseHeight + _ heightRange) 默认是 0-60米
  173. float _glowRange = 600.0; // 光环的移动范围(高度)
  174. vec3 position = fsInput.attributes.positionMC;
  175. float vtxf_height = position.y-_baseHeight;
  176. float vtxf_a11 = fract(czm_frameNumber / 300.0) * 3.14159265 * 0.8;
  177. // float vtxf_a12 = vtxf_height / _heightRange + sin(vtxf_a11) * 0.5;
  178. float vtxf_a12 = vtxf_height / _heightRange + vtxf_a11 * 0.8;
  179. material.diffuse*= vec3(vtxf_a12, vtxf_a12, vtxf_a12);
  180. float time = fract(czm_frameNumber / 2000.0);
  181. time = abs(time - 0.5) * 2.0;
  182. float diff = step(0.03, abs(clamp(position.y / _glowRange, 0.0, 1.0) - time ));
  183. float diff2 = step(0.03, abs(clamp(position.y / _glowRange, 0.0, 1.0) - fract(time + 0.25 )));
  184. float diff3 = step(0.03, abs(clamp(position.y / _glowRange, 0.0, 1.0) - fract(time + 0.5 )) );
  185. float diff4 = step(0.03, abs(clamp(position.y / _glowRange, 0.0, 1.0) - fract(time + 0.75)));
  186. material.diffuse += material.diffuse * (1.0 - (diff * diff2 * diff3 * diff4)) * (1.0 - v_normalMC.y) * 10.0;
  187. }
  188. `,
  189. });
  190. // 张金雨建模 内
  191. let shzxZJYTileset_W = this.add3DTiles(
  192. viewer,
  193. systemConfig.server.shzxZJY_nei,
  194. false
  195. );
  196. this.shzxZJYTileset_W = shzxZJYTileset_W;
  197. shzxZJYTileset_W.readyPromise.then(function (tileset) {
  198. that.panyi(tileset);
  199. });
  200. // // 重要建筑
  201. // let mainBuildTileset = this.add3DTiles(
  202. // viewer,
  203. // systemConfig.server.mainBuild,
  204. // false
  205. // );
  206. // this.mainBuildTileset = mainBuildTileset;
  207. // mainBuildTileset.readyPromise.then(function (tileset) {
  208. // // tileset.modelMatrix = that.createMatrix4({
  209. // // longitude: 121.4983784,
  210. // // latitude: 31.2392238,
  211. // // height: 0,
  212. // // rx: 0,
  213. // // ry: 0,
  214. // // rz: 0,
  215. // // });
  216. // // // 偏移
  217. // // //笛卡尔转换为弧度
  218. // // var cartographic = Cesium.Cartographic.fromCartesian(
  219. // // tileset.boundingSphere.center
  220. // // );
  221. // // var lng = Cesium.Math.toDegrees(cartographic.longitude); //使用经纬度和弧度的转换,将WGS84弧度坐标系转换到目标值,弧度转度
  222. // // var lat = Cesium.Math.toDegrees(cartographic.latitude);
  223. // // var height = cartographic.height;
  224. // // //计算中心点位置的地表坐标
  225. // // var surface = Cesium.Cartesian3.fromDegrees(lng, lat, height);
  226. // // const m = Cesium.Transforms.eastNorthUpToFixedFrame(surface);
  227. // // const tempTranslation = new Cesium.Cartesian3(2000, 2000, 0);
  228. // // const offset = Cesium.Matrix4.multiplyByPoint(
  229. // // m,
  230. // // tempTranslation,
  231. // // new Cesium.Cartesian3(0, 0, 0)
  232. // // );
  233. // // const translation = Cesium.Cartesian3.subtract(
  234. // // offset,
  235. // // surface,
  236. // // new Cesium.Cartesian3()
  237. // // );
  238. // // tileset.modelMatrix = Cesium.Matrix4.fromTranslation(translation);
  239. // // //偏移后的坐标
  240. // // // var offset = Cesium.Cartesian3.fromDegrees(lng + 0.0045, lat - 0.002, 0);
  241. // // // var offset = Cesium.Cartesian3.fromDegrees(
  242. // // // 121.4983784, // + 0.0045,
  243. // // // 31.2392238, // - 0.002,
  244. // // // 0
  245. // // // );
  246. // // // var translation = Cesium.Cartesian3.subtract(
  247. // // // offset,
  248. // // // surface,
  249. // // // new Cesium.Cartesian3()
  250. // // // );
  251. // // // tileset.modelMatrix = Cesium.Matrix4.fromTranslation(translation);
  252. // // return;
  253. // var transformPosition = Cesium.Cartesian3.fromDegrees(
  254. // 121.4983784 + 0.0045,
  255. // 31.2392238 - 0.002,
  256. // 0
  257. // );
  258. // var matrix = Cesium.Transforms.eastNorthUpToFixedFrame(transformPosition);
  259. // var scale = Cesium.Matrix4.fromUniformScale(1);
  260. // Cesium.Matrix4.multiply(matrix, scale, matrix);
  261. // var rotationX = Cesium.Matrix3.fromRotationX(Cesium.Math.toRadians(0));
  262. // var rotationY = Cesium.Matrix3.fromRotationY(Cesium.Math.toRadians(0));
  263. // var rotationZ = Cesium.Matrix3.fromRotationZ(Cesium.Math.toRadians(8));
  264. // var rotationTranslationX =
  265. // Cesium.Matrix4.fromRotationTranslation(rotationX);
  266. // var rotationTranslationY =
  267. // Cesium.Matrix4.fromRotationTranslation(rotationY);
  268. // var rotationTranslationZ =
  269. // Cesium.Matrix4.fromRotationTranslation(rotationZ);
  270. // Cesium.Matrix4.multiply(matrix, rotationTranslationX, matrix);
  271. // Cesium.Matrix4.multiply(matrix, rotationTranslationY, matrix);
  272. // Cesium.Matrix4.multiply(matrix, rotationTranslationZ, matrix);
  273. // tileset._root.transform = matrix;
  274. // // viewer.zoomTo(mainBuildTileset);
  275. // });
  276. // BIM 建模
  277. let bimTileset = this.add3DTiles(viewer, systemConfig.server.bim, false);
  278. this.bimTileset = bimTileset;
  279. bimTileset.readyPromise.then(function (tileset) {
  280. bimTileset.show = false;
  281. // 偏移
  282. //笛卡尔转换为弧度
  283. var cartographic = Cesium.Cartographic.fromCartesian(
  284. tileset.boundingSphere.center
  285. );
  286. var lng = Cesium.Math.toDegrees(cartographic.longitude); //使用经纬度和弧度的转换,将WGS84弧度坐标系转换到目标值,弧度转度
  287. var lat = Cesium.Math.toDegrees(cartographic.latitude);
  288. var height = cartographic.height;
  289. //计算中心点位置的地表坐标
  290. var surface = Cesium.Cartesian3.fromDegrees(lng, lat, height);
  291. //偏移后的坐标
  292. var offset = Cesium.Cartesian3.fromDegrees(
  293. lng + 0.0039,
  294. lat - 0.0021,
  295. height
  296. );
  297. // m = Cesium.Transforms.eastNorthUpToFixedFrame(offset);
  298. var translation = Cesium.Cartesian3.subtract(
  299. offset,
  300. surface,
  301. new Cesium.Cartesian3()
  302. );
  303. let m = Cesium.Matrix4.fromTranslation(translation);
  304. tileset.modelMatrix = m;
  305. // viewer.zoomTo(bimTileset);
  306. });
  307. // // 上海中心大厦
  308. // this.shZxTileset = this.add3DTiles(viewer, systemConfig.server.shzx, false);
  309. // shZxTileset.readyPromise.then(function (tileset) {
  310. // that.panyi(tileset);
  311. // });
  312. // // 自定义光源
  313. // let customShaderAAA = new Cesium.CustomShader({
  314. // lightingModel: Cesium.LightingModel.UNLIT,
  315. // uniforms: {
  316. // u_cameraDirectionWC: {
  317. // type: Cesium.UniformType.VEC3,
  318. // value: viewer.scene.camera.positionWC,
  319. // },
  320. // u_lightColor1: {
  321. // type: Cesium.UniformType.VEC4,
  322. // value: new Cesium.Cartesian4(248/255, 0/255, 0/255, 0),
  323. // },
  324. // u_lightPos1: {
  325. // type: Cesium.UniformType.VEC3,
  326. // // 大门头顶
  327. // value: Cesium.Cartesian3.fromRadians(
  328. // 2.120596229847432,
  329. // 0.5451633778904422,
  330. // 500,
  331. // ),
  332. // // 一楼门厅
  333. // // value: Cesium.Cartesian3.fromRadians(
  334. // // 2.113987467160011,
  335. // // 0.5437379383404595,
  336. // // 2,
  337. // // ),
  338. // // 门口室外
  339. // // value: Cesium.Cartesian3.fromDegrees(
  340. // // 121.122485613095,
  341. // // 31.1542436101541,
  342. // // 10.649243861995
  343. // // ),
  344. // },
  345. // // u_lightColor2: {
  346. // // type: Cesium.UniformType.VEC4,
  347. // // value: new Cesium.Cartesian4(0.2, 0.8, 0.2, 0.2),
  348. // // },
  349. // // u_lightPos2: {
  350. // // type: Cesium.UniformType.VEC3,
  351. // // value: Cesium.Cartesian3.fromRadians(
  352. // // 3.1001573234522195,
  353. // // 0.5437380338095784,
  354. // // 2.1
  355. // // ),
  356. // // },
  357. // // u_lightColor3: {
  358. // // type: Cesium.UniformType.VEC4,
  359. // // value: lightPoint3.color,
  360. // // },
  361. // // u_lightPos3: {
  362. // // type: Cesium.UniformType.VEC3,
  363. // // value: lightPoint3.postion,
  364. // // },
  365. // },
  366. // fragmentShaderText: `
  367. // vec4 makeLight(vec4 lightColorHdr,vec3 lightPos,
  368. // vec3 positionWC,vec3 positionEC,vec3 normalEC,czm_pbrParameters pbrParameters)
  369. // {
  370. // vec3 color = vec3(0.0);
  371. // float mx1 = 1.0;
  372. // vec3 light1Dir = positionWC - lightPos;
  373. // float distance1 = length(light1Dir);
  374. // if(distance1 < 300.0){
  375. // vec4 l1 = czm_view * vec4(lightPos, 1.0);
  376. // vec3 lightDirectionEC = l1.xyz - positionEC;
  377. // mx1 = 1.0 - distance1 / 300.0;
  378. // color = czm_pbrLighting(
  379. // positionEC,
  380. // normalEC,
  381. // lightDirectionEC,
  382. // lightColorHdr.xyz,
  383. // pbrParameters
  384. // ).xyz;
  385. // }
  386. // mx1 = max(color.r,max(color.g,color.b)) * pow(mx1,1.0) * 10.0;
  387. // return vec4(color,mx1);
  388. // }
  389. // void fragmentMain(FragmentInput fsInput, inout czm_modelMaterial material)
  390. // {
  391. // // material.diffuse = vec3(1.0);
  392. // vec3 positionWC = fsInput.attributes.positionWC;
  393. // vec3 normalEC = fsInput.attributes.normalEC;
  394. // vec3 positionEC = fsInput.attributes.positionEC;
  395. // vec3 lightColorHdr = czm_lightColorHdr;
  396. // vec3 lightDirectionEC = czm_lightDirectionEC;
  397. // lightDirectionEC = (czm_view * vec4(u_cameraDirectionWC,1.0)).xyz - positionEC;
  398. // czm_pbrParameters pbrParameters;
  399. // pbrParameters.diffuseColor = material.diffuse;
  400. // pbrParameters.f0 = vec3(0.5);
  401. // pbrParameters.roughness = 1.0;
  402. // vec3 ligth1Color0 = czm_pbrLighting(
  403. // positionEC,
  404. // normalEC,
  405. // lightDirectionEC,
  406. // lightColorHdr,
  407. // pbrParameters
  408. // );
  409. // vec4 ligth1ColorR = makeLight(u_lightColor1,u_lightPos1,positionWC,positionEC,normalEC,pbrParameters);
  410. // // vec4 ligth1ColorG = makeLight(u_lightColor2,u_lightPos2,positionWC,positionEC,normalEC,pbrParameters);
  411. // vec3 finalColor = mix(material.diffuse.rgb, ligth1ColorR.rgb, ligth1ColorR.a);
  412. // // finalColor = mix(finalColor, ligth1ColorG.rgb, ligth1ColorG.a);
  413. // material.diffuse = finalColor;
  414. // // material.ambient = finalColor;
  415. // }
  416. // `,
  417. // });
  418. // shZxTileset.customShader = customShaderAAA;
  419. this.singleClick();
  420. // this.addFlyLine();
  421. // // 正多边形扩散
  422. // WallRegularDiffuse(viewer, systemConfig.WallRegularDiffuseObj);
  423. // 随机竖直飞线
  424. lineFlowInit(viewer, systemConfig.lineFlowObj);
  425. // 中心扩散
  426. this.addCircle(viewer);
  427. },
  428. methods: {
  429. changeRadio(label) {
  430. switch (label) {
  431. case 0:
  432. this.rain.show(false);
  433. this.snow.show(false);
  434. this.fog.show(false);
  435. break;
  436. case 1:
  437. this.rain.show(true);
  438. this.snow.show(false);
  439. this.fog.show(false);
  440. break;
  441. case 2:
  442. this.rain.show(false);
  443. this.snow.show(true);
  444. this.fog.show(false);
  445. break;
  446. case 3:
  447. this.rain.show(false);
  448. this.snow.show(false);
  449. this.fog.show(true);
  450. break;
  451. default:
  452. break;
  453. }
  454. },
  455. changeSwitch(val) {
  456. // this.mainBuildTileset.show = val;
  457. this.shzxZJYTileset_N.show = val
  458. this.shzxZJYTileset_W.show = val
  459. this.bimTileset.show = !val;
  460. },
  461. initMap(viewer) {
  462. // // 加载天地图影像
  463. // viewer.imageryLayers.addImageryProvider(
  464. // new Cesium.WebMapTileServiceImageryProvider({
  465. // url: "http://t{s}.tianditu.gov.cn/img_w/wmts?service=wmts&request=GetTile&version=1.0.0&LAYER=img&tileMatrixSet=w&TileMatrix={TileMatrix}&TileRow={TileRow}&TileCol={TileCol}&style=default&format=tiles&tk=" +
  466. // systemConfig.tdt_tk,
  467. // layer: "img",
  468. // style: "default",
  469. // tileMatrixSetID: "w",
  470. // format: "image/jpeg",
  471. // subdomains: ["0", "1", "2", "3", "4", "5", "6", "7"],
  472. // tileMatrixSetID: "GoogleMapsCompatible",
  473. // show: true,
  474. // minimumLevel: 1,
  475. // maximumLevel: 18,
  476. // })
  477. // );
  478. // //加载影像注记
  479. // viewer.imageryLayers.addImageryProvider(
  480. // new Cesium.WebMapTileServiceImageryProvider({
  481. // url: "http://t{s}.tianditu.gov.cn/cia_w/wmts?tk=" + systemConfig.tdt_tk,
  482. // layer: "cia",
  483. // style: "default",
  484. // tileMatrixSetID: "w",
  485. // format: "tiles",
  486. // subdomains: ["0", "1", "2", "3", "4", "5", "6", "7"],
  487. // maximumLevel: 20,
  488. // })
  489. // );
  490. // 加载黑夜底图
  491. viewer.imageryLayers.addImageryProvider(
  492. new Cesium.ArcGisMapServerImageryProvider({
  493. // url: "https://map.geoq.cn/ArcGIS/rest/services/ChinaOnlineStreetPurplishBlue/MapServer",
  494. url: "http://cache1.arcgisonline.cn/arcgis/rest/services/ChinaOnlineStreetPurplishBlue/MapServer",
  495. })
  496. );
  497. // viewer.imageryLayers.addImageryProvider(
  498. // new Cesium.ArcGisMapServerImageryProvider({
  499. // // url: "https://map.geoq.cn/ArcGIS/rest/services/ChinaOnlineStreetPurplishBlue/MapServer",
  500. // url: "http://121.43.55.7:10011/proxy/?servertype=World_Imagery&token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlSWQiOiIyLDIwLDEyLDQsMCIsImV4cCI6MTY2NjMzMzcwNywidXNlcklkIjoyMiwidXNlcm5hbWUiOiJ1c2VyX3Rlc3QxIn0.-wYyW-HiEfZGqrVn8X4LC7rH8DFLSVjhcIIKWX-Kriw",
  501. // })
  502. // );
  503. },
  504. addEffect(viewer) {
  505. this.rain = new Cesium.RainEffect(viewer, {
  506. speed: 5,
  507. size: 40,
  508. direction: 0,
  509. enabled: false,
  510. });
  511. this.snow = new Cesium.SnowEffect(viewer, {
  512. speed: 15,
  513. size: 1000,
  514. direction: 0,
  515. enabled: false,
  516. });
  517. this.fog = new Cesium.FogEffect(viewer, {
  518. fogByDistance: new Cesium.Cartesian4(10, 0.0, 1000, 0.5),
  519. maxHeight: 9000,
  520. color: Cesium.Color.WHITE,
  521. enabled: false,
  522. });
  523. },
  524. add3DTiles(viewer, url, flyto) {
  525. let tileset = new Cesium.Cesium3DTileset({
  526. url: url + "/tileset.json",
  527. skipLevelOfDetail: true, //开启跳级加载
  528. maximumScreenSpaceError: 16,
  529. maximumNumberOfLoadedTiles: 2000,
  530. maximumMemoryUsage: 512, //tileset可以使用的最大内存
  531. show: true,
  532. immediatelyLoadDesiredLevelOfDetail: true,
  533. // showOutLine : true, // 是否使用 CESIUM_primitive_outline 扩展显示模型的轮廓。为 true 时,将显示轮廓。如果为 false,则不显示轮廓。
  534. // debugColorizeTiles : true, // 仅用于调试。如果为 true,则为每个图块分配随机颜色。
  535. // debugShowBoundingVolume : true, // 仅用于调试。如果为 true,则为每个图块渲染边界体积。
  536. // debugShowContentBoundingVolume : true, // 仅用于调试。如果为 true,则为每个图块的内容渲染边界体积。
  537. // lightColor : new Cesium.Cartesian3(100.0,100.0, 100.0), // 调整模型亮度
  538. });
  539. viewer.scene.primitives.add(tileset);
  540. // tileset.readyPromise.then(function () {
  541. // if (flyto) viewer.zoomTo(tileset);
  542. // });
  543. return tileset;
  544. },
  545. createMatrix4(matrixParam, defaultModelMatrix) {
  546. let tileModelTool = matrixParam;
  547. var mx = Cesium.Matrix3.fromRotationX(
  548. Cesium.Math.toRadians(tileModelTool.rx)
  549. );
  550. var my = Cesium.Matrix3.fromRotationY(
  551. Cesium.Math.toRadians(tileModelTool.ry)
  552. );
  553. var mz = Cesium.Matrix3.fromRotationZ(
  554. Cesium.Math.toRadians(tileModelTool.rz)
  555. );
  556. var rotationX = Cesium.Matrix4.fromRotationTranslation(mx);
  557. var rotationY = Cesium.Matrix4.fromRotationTranslation(my);
  558. var rotationZ = Cesium.Matrix4.fromRotationTranslation(mz);
  559. var m;
  560. if (defaultModelMatrix) {
  561. m = defaultModelMatrix;
  562. } else {
  563. //平移 修改经纬度
  564. var position = Cesium.Cartesian3.fromDegrees(
  565. tileModelTool.longitude,
  566. tileModelTool.latitude,
  567. tileModelTool.height
  568. );
  569. m = Cesium.Transforms.eastNorthUpToFixedFrame(position);
  570. }
  571. //旋转、平移矩阵相乘
  572. Cesium.Matrix4.multiply(m, rotationX, m);
  573. Cesium.Matrix4.multiply(m, rotationY, m);
  574. Cesium.Matrix4.multiply(m, rotationZ, m);
  575. //缩放 修改缩放比例
  576. var scale = Cesium.Matrix4.fromUniformScale(tileModelTool.scale);
  577. Cesium.Matrix4.multiply(m, scale, m);
  578. return m;
  579. },
  580. panyi(tileset) {
  581. // 偏移
  582. //笛卡尔转换为弧度
  583. var cartographic = Cesium.Cartographic.fromCartesian(
  584. tileset.boundingSphere.center
  585. );
  586. var lng = Cesium.Math.toDegrees(cartographic.longitude); //使用经纬度和弧度的转换,将WGS84弧度坐标系转换到目标值,弧度转度
  587. var lat = Cesium.Math.toDegrees(cartographic.latitude);
  588. //计算中心点位置的地表坐标
  589. var surface = Cesium.Cartesian3.fromDegrees(lng, lat, 0.0);
  590. //偏移后的坐标
  591. var offset = Cesium.Cartesian3.fromDegrees(lng + 0.0045, lat - 0.002, 0);
  592. var translation = Cesium.Cartesian3.subtract(
  593. offset,
  594. surface,
  595. new Cesium.Cartesian3()
  596. );
  597. tileset.modelMatrix = Cesium.Matrix4.fromTranslation(translation);
  598. },
  599. addCircle(viewer) {
  600. let that = this;
  601. let multiS = 1;
  602. let circleFirst3 = viewer.entities.add({
  603. position: Cesium.Cartesian3.fromDegrees(
  604. 121.50564342780112,
  605. 31.23360579506302,
  606. 0
  607. ),
  608. // height: 0.0,
  609. ellipse: {
  610. show: true,
  611. semiMinorAxis: new Cesium.CallbackProperty(function () {
  612. if (!Cesium.defined(circleFirst3.ellipse._semiMinorAxis2)) {
  613. circleFirst3.ellipse._semiMinorAxis2 = 0;
  614. }
  615. // if (that.moveMode) {
  616. //往返
  617. if (circleFirst3.ellipse._semiMinorAxis2 > that.radius) {
  618. multiS = -1;
  619. } else if (circleFirst3.ellipse._semiMinorAxis2 < 0) {
  620. //单一
  621. multiS = 1;
  622. }
  623. // } else {
  624. // //单一
  625. // if (circleFirst3.ellipse._semiMinorAxis2 > that.radius) {
  626. // // circleFirst3.ellipse._semiMinorAxis2 = 0;
  627. // multiS = 1;
  628. // circleFirst3.ellipse._semiMinorAxis2 = 0;
  629. // } else if (circleFirst3.ellipse._semiMinorAxis2 < 0) {
  630. // multiS = 1;
  631. // }
  632. // }
  633. circleFirst3.ellipse._semiMinorAxis2 += multiS * 15;
  634. return circleFirst3.ellipse._semiMinorAxis2;
  635. }, false),
  636. semiMajorAxis: new Cesium.CallbackProperty(function () {
  637. if (!Cesium.defined(circleFirst3.ellipse._semiMajorAxis2)) {
  638. circleFirst3.ellipse._semiMajorAxis2 = 0;
  639. }
  640. // if (that.moveMode) {
  641. //往返
  642. if (circleFirst3.ellipse._semiMajorAxis2 > that.radius) {
  643. multiS = -1;
  644. } else if (circleFirst3.ellipse._semiMajorAxis2 < 0) {
  645. //单一
  646. multiS = 1;
  647. }
  648. // } else {
  649. // //单一
  650. // if (circleFirst3.ellipse._semiMajorAxis2 > that.radius) {
  651. // multiS = 1;
  652. // circleFirst3.ellipse._semiMajorAxis2 = 0;
  653. // } else if (circleFirst3.ellipse._semiMajorAxis2 < 0) {
  654. // multiS = 1;
  655. // }
  656. // }
  657. circleFirst3.ellipse._semiMajorAxis2 += multiS * 15;
  658. return circleFirst3.ellipse._semiMajorAxis2;
  659. }, false),
  660. // stRotation: new Cesium.CallbackProperty(function () {
  661. // if (!Cesium.defined(circleFirst3.ellipse._semiMajorAxis2)) {
  662. // circleFirst3.ellipse._semiMajorAxis2 = 0;
  663. // }
  664. // circleFirst3.ellipse._semiMajorAxis2 += multiS * 15;
  665. // return circleFirst3.ellipse._semiMajorAxis2;
  666. // }, false),
  667. material: new Cesium.ImageMaterialProperty({
  668. image: "./static/images/circle.png",
  669. transparent: true,
  670. }),
  671. classificationType: Cesium.ClassificationType.TERRAIN,
  672. outline: false,
  673. },
  674. });
  675. window.circleFirst3 = circleFirst3;
  676. },
  677. // 加载飞线
  678. addFlyLine() {
  679. let that = this;
  680. this.topK.map(function (item) {
  681. let startPoint = item;
  682. let endPoint = Object.assign({}, startPoint);
  683. endPoint.h = item.h;
  684. let positions = [
  685. startPoint.lon,
  686. startPoint.lat,
  687. 0,
  688. endPoint.lon,
  689. endPoint.lat,
  690. endPoint.h,
  691. ];
  692. addLine(positions);
  693. });
  694. // for (var j = 0; j < 50; ++j) {
  695. // let startPoint = randomPoint();
  696. // let endPoint = Object.assign({}, startPoint);
  697. // endPoint.h = getRandom(199, 200);
  698. // // this.addFlyingLineByEntity(
  699. // // Cesium.Cartesian3.fromDegreesArrayHeights([
  700. // // startPoint.lon,
  701. // // startPoint.lat,
  702. // // startPoint.h,
  703. // // endPoint.lon,
  704. // // endPoint.lat,
  705. // // endPoint.h,
  706. // // ])
  707. // // );
  708. // // continue;
  709. // }
  710. function addLine(positions) {
  711. // 创建长方体对象
  712. const PolylineGeometry = new Cesium.PolylineGeometry({
  713. positions: Cesium.Cartesian3.fromDegreesArrayHeights(positions),
  714. width: 2,
  715. });
  716. const instance = new Cesium.GeometryInstance({
  717. geometry: PolylineGeometry,
  718. });
  719. // this.flylineObj.push(
  720. globalVariable.viewer.scene.primitives.add(
  721. new Cesium.Primitive({
  722. geometryInstances: [instance],
  723. appearance: that.getFlylineMaterial(1),
  724. depthFailAppearance: that.getFlylineMaterial(1),
  725. releaseGeometryInstances: false,
  726. compressVertices: false,
  727. })
  728. );
  729. // );
  730. }
  731. function randomPoint() {
  732. var jingd = 1000000;
  733. var jd =
  734. getRandom(
  735. systemConfig.mapDefault.bbox.west * jingd,
  736. systemConfig.mapDefault.bbox.east * jingd
  737. ) / jingd;
  738. var wd =
  739. getRandom(
  740. systemConfig.mapDefault.bbox.south * jingd,
  741. systemConfig.mapDefault.bbox.north * jingd
  742. ) / jingd;
  743. return {
  744. lon: jd,
  745. lat: wd,
  746. h: 0,
  747. };
  748. }
  749. function getRandom(t, e) {
  750. return Math.floor(Math.random() * (e - t + 1) + t);
  751. }
  752. },
  753. // 创建飞线材质 1
  754. getFlylineMaterial(index) {
  755. // 创建材质,在MaterialAppearance中若不添加基础材质,模型将会透明
  756. let material = new Cesium.Material.fromType("Color");
  757. material.uniforms.color = Cesium.Color.ORANGE;
  758. let fragmentShaderSource;
  759. if (index === 1) {
  760. // 飞线效果-飞线间隔,宽度2
  761. fragmentShaderSource = `
  762. varying vec2 v_st;
  763. varying float v_width;
  764. varying float v_polylineAngle;
  765. varying vec4 v_positionEC;
  766. varying vec3 v_normalEC;
  767. void main()
  768. {
  769. vec2 st = v_st;
  770. float xx = fract(st.s*2.0 - czm_frameNumber/60.0);
  771. float r = xx;
  772. float g = 200.0;
  773. float b = 200.0;
  774. float a = xx;
  775. gl_FragColor = vec4(r,g,b,a);
  776. }
  777. `;
  778. } else if (index === 2) {
  779. fragmentShaderSource = `
  780. varying vec2 v_st;
  781. varying float v_width;
  782. varying float v_polylineAngle;
  783. varying vec4 v_positionEC;
  784. varying vec3 v_normalEC;
  785. void main()
  786. {
  787. vec2 st = v_st;
  788. float xx = fract(st.s*2.0 - czm_frameNumber/60.0);
  789. float r = xx;
  790. float g = sin(czm_frameNumber/30.0);
  791. float b = cos(czm_frameNumber/30.0);
  792. float a = xx;
  793. gl_FragColor = vec4(r,g,b,a);
  794. }
  795. `;
  796. } else if (index === 3) {
  797. fragmentShaderSource = `
  798. varying vec2 v_st;
  799. varying float v_width;
  800. varying float v_polylineAngle;
  801. varying vec4 v_positionEC;
  802. varying vec3 v_normalEC;
  803. void main()
  804. {
  805. vec2 st = v_st;
  806. float xx = sin(st.s*6.0 -czm_frameNumber/5.0) - cos(st.t*6.0);
  807. float r = 0.0;
  808. float g = xx;
  809. float b = xx;
  810. float a = xx;
  811. gl_FragColor = vec4(r,g,b,a);
  812. }
  813. `;
  814. } else if (index === 4) {
  815. fragmentShaderSource = `
  816. varying vec2 v_st;
  817. varying float v_width;
  818. varying float v_polylineAngle;
  819. varying vec4 v_positionEC;
  820. varying vec3 v_normalEC;
  821. void main()
  822. {
  823. vec2 st = v_st;
  824. float xx = fract(st.s*10.0 + st.t - czm_frameNumber/60.0);
  825. if (st.t<0.5) {
  826. xx = fract(st.s*10.0 - st.t - czm_frameNumber/60.0);
  827. }
  828. float r = 0.0;
  829. float g = xx;
  830. float b = xx;
  831. float a = xx;
  832. if (st.t>0.8||st.t<0.2) {
  833. g = 1.0;
  834. b = 1.0;
  835. a = 0.4;
  836. }
  837. gl_FragColor = vec4(r,g,b,a);
  838. }
  839. `;
  840. }
  841. // 自定义材质
  842. const aper = new Cesium.PolylineMaterialAppearance({
  843. material: material,
  844. translucent: true,
  845. vertexShaderSource: `
  846. #define CLIP_POLYLINE
  847. void clipLineSegmentToNearPlane(
  848. vec3 p0,
  849. vec3 p1,
  850. out vec4 positionWC,
  851. out bool clipped,
  852. out bool culledByNearPlane,
  853. out vec4 clippedPositionEC)
  854. {
  855. culledByNearPlane = false;
  856. clipped = false;
  857. vec3 p0ToP1 = p1 - p0;
  858. float magnitude = length(p0ToP1);
  859. vec3 direction = normalize(p0ToP1);
  860. float endPoint0Distance = czm_currentFrustum.x + p0.z;
  861. float denominator = -direction.z;
  862. if (endPoint0Distance > 0.0 && abs(denominator) < czm_epsilon7)
  863. {
  864. culledByNearPlane = true;
  865. }
  866. else if (endPoint0Distance > 0.0)
  867. {
  868. float t = endPoint0Distance / denominator;
  869. if (t < 0.0 || t > magnitude)
  870. {
  871. culledByNearPlane = true;
  872. }
  873. else
  874. {
  875. p0 = p0 + t * direction;
  876. p0.z = min(p0.z, -czm_currentFrustum.x);
  877. clipped = true;
  878. }
  879. }
  880. clippedPositionEC = vec4(p0, 1.0);
  881. positionWC = czm_eyeToWindowCoordinates(clippedPositionEC);
  882. }
  883. vec4 getPolylineWindowCoordinatesEC(vec4 positionEC, vec4 prevEC, vec4 nextEC, float expandDirection, float width, bool usePrevious, out float angle)
  884. {
  885. #ifdef POLYLINE_DASH
  886. vec4 positionWindow = czm_eyeToWindowCoordinates(positionEC);
  887. vec4 previousWindow = czm_eyeToWindowCoordinates(prevEC);
  888. vec4 nextWindow = czm_eyeToWindowCoordinates(nextEC);
  889. vec2 lineDir;
  890. if (usePrevious) {
  891. lineDir = normalize(positionWindow.xy - previousWindow.xy);
  892. }
  893. else {
  894. lineDir = normalize(nextWindow.xy - positionWindow.xy);
  895. }
  896. angle = atan(lineDir.x, lineDir.y) - 1.570796327;
  897. angle = floor(angle / czm_piOverFour + 0.5) * czm_piOverFour;
  898. #endif
  899. vec4 clippedPrevWC, clippedPrevEC;
  900. bool prevSegmentClipped, prevSegmentCulled;
  901. clipLineSegmentToNearPlane(prevEC.xyz, positionEC.xyz, clippedPrevWC, prevSegmentClipped, prevSegmentCulled, clippedPrevEC);
  902. vec4 clippedNextWC, clippedNextEC;
  903. bool nextSegmentClipped, nextSegmentCulled;
  904. clipLineSegmentToNearPlane(nextEC.xyz, positionEC.xyz, clippedNextWC, nextSegmentClipped, nextSegmentCulled, clippedNextEC);
  905. bool segmentClipped, segmentCulled;
  906. vec4 clippedPositionWC, clippedPositionEC;
  907. clipLineSegmentToNearPlane(positionEC.xyz, usePrevious ? prevEC.xyz : nextEC.xyz, clippedPositionWC, segmentClipped, segmentCulled, clippedPositionEC);
  908. if (segmentCulled)
  909. {
  910. return vec4(0.0, 0.0, 0.0, 1.0);
  911. }
  912. vec2 directionToPrevWC = normalize(clippedPrevWC.xy - clippedPositionWC.xy);
  913. vec2 directionToNextWC = normalize(clippedNextWC.xy - clippedPositionWC.xy);
  914. if (prevSegmentCulled)
  915. {
  916. directionToPrevWC = -directionToNextWC;
  917. }
  918. else if (nextSegmentCulled)
  919. {
  920. directionToNextWC = -directionToPrevWC;
  921. }
  922. vec2 thisSegmentForwardWC, otherSegmentForwardWC;
  923. if (usePrevious)
  924. {
  925. thisSegmentForwardWC = -directionToPrevWC;
  926. otherSegmentForwardWC = directionToNextWC;
  927. }
  928. else
  929. {
  930. thisSegmentForwardWC = directionToNextWC;
  931. otherSegmentForwardWC = -directionToPrevWC;
  932. }
  933. vec2 thisSegmentLeftWC = vec2(-thisSegmentForwardWC.y, thisSegmentForwardWC.x);
  934. vec2 leftWC = thisSegmentLeftWC;
  935. float expandWidth = width * 0.5;
  936. if (!czm_equalsEpsilon(prevEC.xyz - positionEC.xyz, vec3(0.0), czm_epsilon1) && !czm_equalsEpsilon(nextEC.xyz - positionEC.xyz, vec3(0.0), czm_epsilon1))
  937. {
  938. vec2 otherSegmentLeftWC = vec2(-otherSegmentForwardWC.y, otherSegmentForwardWC.x);
  939. vec2 leftSumWC = thisSegmentLeftWC + otherSegmentLeftWC;
  940. float leftSumLength = length(leftSumWC);
  941. leftWC = leftSumLength < czm_epsilon6 ? thisSegmentLeftWC : (leftSumWC / leftSumLength);
  942. vec2 u = -thisSegmentForwardWC;
  943. vec2 v = leftWC;
  944. float sinAngle = abs(u.x * v.y - u.y * v.x);
  945. expandWidth = clamp(expandWidth / sinAngle, 0.0, width * 2.0);
  946. }
  947. vec2 offset = leftWC * expandDirection * expandWidth * czm_pixelRatio;
  948. return vec4(clippedPositionWC.xy + offset, -clippedPositionWC.z, 1.0) * (czm_projection * clippedPositionEC).w;
  949. }
  950. vec4 getPolylineWindowCoordinates(vec4 position, vec4 previous, vec4 next, float expandDirection, float width, bool usePrevious, out float angle)
  951. {
  952. vec4 positionEC = czm_modelViewRelativeToEye * position;
  953. vec4 prevEC = czm_modelViewRelativeToEye * previous;
  954. vec4 nextEC = czm_modelViewRelativeToEye * next;
  955. return getPolylineWindowCoordinatesEC(positionEC, prevEC, nextEC, expandDirection, width, usePrevious, angle);
  956. }
  957. attribute vec3 position3DHigh;
  958. attribute vec3 position3DLow;
  959. attribute vec3 prevPosition3DHigh;
  960. attribute vec3 prevPosition3DLow;
  961. attribute vec3 nextPosition3DHigh;
  962. attribute vec3 nextPosition3DLow;
  963. attribute vec2 expandAndWidth;
  964. attribute vec2 st;
  965. attribute float batchId;
  966. varying float v_width;
  967. varying vec2 v_st;
  968. varying float v_polylineAngle;
  969. varying vec4 v_positionEC;
  970. varying vec3 v_normalEC;
  971. void main()
  972. {
  973. float expandDir = expandAndWidth.x;
  974. float width = abs(expandAndWidth.y) + 0.5;
  975. bool usePrev = expandAndWidth.y < 0.0;
  976. vec4 p = czm_computePosition();
  977. vec4 prev = czm_computePrevPosition();
  978. vec4 next = czm_computeNextPosition();
  979. float angle;
  980. vec4 positionWC = getPolylineWindowCoordinates(p, prev, next, expandDir, width, usePrev, angle);
  981. gl_Position = czm_viewportOrthographic * positionWC;
  982. v_width = width;
  983. v_st.s = st.s;
  984. v_st.t = st.t;
  985. // v_st.t = czm_writeNonPerspective(st.t, gl_Position.w);
  986. v_polylineAngle = angle;
  987. vec4 eyePosition = czm_modelViewRelativeToEye * p;
  988. v_positionEC = czm_inverseModelView * eyePosition; // position in eye coordinates
  989. //v_normalEC = czm_normal * normal; // normal in eye coordinates
  990. }
  991. `,
  992. fragmentShaderSource: fragmentShaderSource,
  993. });
  994. return aper;
  995. },
  996. // 地图(地球表面,无地形)左击事件
  997. singleClick() {
  998. var handler = new Cesium.ScreenSpaceEventHandler(
  999. globalVariable.viewer.scene.canvas
  1000. );
  1001. handler.setInputAction(function (event) {
  1002. var earthPosition = globalVariable.viewer.camera.pickEllipsoid(
  1003. event.position,
  1004. globalVariable.viewer.scene.globe.ellipsoid
  1005. );
  1006. var cartographic = Cesium.Cartographic.fromCartesian(
  1007. earthPosition,
  1008. globalVariable.viewer.scene.globe.ellipsoid,
  1009. new Cesium.Cartographic()
  1010. );
  1011. var lat = Cesium.Math.toDegrees(cartographic.latitude);
  1012. var lng = Cesium.Math.toDegrees(cartographic.longitude);
  1013. var height = cartographic.height;
  1014. console.log(lng + "," + lat);
  1015. }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
  1016. },
  1017. },
  1018. };
  1019. </script>
  1020. <!-- Add "scoped" attribute to limit CSS to this component only -->
  1021. <style scoped>
  1022. #cesium_id {
  1023. width: 100%;
  1024. height: 100%;
  1025. }
  1026. .choose {
  1027. position: absolute;
  1028. z-index: 1;
  1029. top: 20px;
  1030. left: 20px;
  1031. background: #ffffff;
  1032. padding: 0px 20px;
  1033. border-radius: 5px;
  1034. }
  1035. .switch {
  1036. position: absolute;
  1037. z-index: 1;
  1038. top: 20px;
  1039. right: 20px;
  1040. background: #ffffff;
  1041. padding: 0px 20px;
  1042. border-radius: 5px;
  1043. }
  1044. </style>