toolBar.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <template>
  2. <!-- 暂时隐藏工具栏 -->
  3. <div v-show="ToolBarShow">
  4. <!-- <div v-if="true"> -->
  5. <!-- <div class="resourceTree" @click="choose(0)"></div> -->
  6. <div class="toolBar">
  7. <el-cascader size="mini" :show-all-levels="false" :options="xzqTreeData" placeholder="行政区"
  8. :props="{ checkStrictly: true, expandTrigger: 'hover' }" clearable v-model="xzqTreeValue"></el-cascader>
  9. <el-select size="mini" v-model="Skybox" placeholder="天空盒">
  10. <el-option v-for="item in SkyboxList" :key="item.value" :label="item.label" :value="item.value">
  11. </el-option>
  12. </el-select>
  13. <li class="sm-btn sm-tool-btn" :title="Resource.Resource" @click="choose(0)">
  14. <span class="iconfont icontuceng"></span>
  15. </li>
  16. <!-- <ul v-if="show"> -->
  17. <li class="sm-btn sm-tool-btn" :title="Resource.PoinyQuery" @click="choose(9)">
  18. <i class="el-icon-thumb"></i>
  19. </li>
  20. <li class="sm-btn sm-tool-btn" :title="Resource.PlacenameLocation" @click="choose(10)">
  21. <i class="el-icon-place"></i>
  22. </li>
  23. <li class="sm-btn sm-tool-btn" :title="Resource.BookMark" @click="choose(11)">
  24. <i class="el-icon-notebook-2"></i>
  25. </li>
  26. <li class="sm-btn sm-tool-btn" :title="Resource.measure" @click="choose(7)">
  27. <span class="iconfont iconliangsuan"></span>
  28. </li>
  29. <!-- <li class="sm-btn sm-tool-btn" :title="Resource.clip" @click="choose(4)">
  30. <span class="iconfont iconiEarth-R8-xiugai_caijian"></span>
  31. </li> -->
  32. <li class="sm-btn sm-tool-btn" :title="Resource.terrain" @click="choose(5)">
  33. <span class="iconfont icondixing"></span>
  34. </li>
  35. <li class="sm-btn sm-tool-btn" :title="Resource.onlineEditing" @click="choose(8)">
  36. <span class="iconfont iconzaixianbianji"></span>
  37. </li>
  38. <li class="sm-btn sm-tool-btn" :title="Resource.analysis" @click="choose(6)">
  39. <span class="iconfont iconsanweifenxi"></span>
  40. </li>
  41. <!-- <li class="sm-btn sm-tool-btn" :title="Resource.fly" @click="choose(12)">
  42. <i class="el-icon-guide"></i>
  43. </li> -->
  44. <li class="sm-btn sm-tool-btn" :title="Resource.sceneOptions" @click="choose(3)">
  45. <i class="el-icon-setting"></i>
  46. </li>
  47. <!-- </ul> -->
  48. <div style="display: none" class="sm-tool-btn" @click="toggleVisibility" :class="{ 'sm-tool-btn-only': !show }">
  49. <span class="iconfont" :class="!show
  50. ? 'iconiEarth-R8-xiugai_shouqi'
  51. : 'iconiEarth-R8-xiugai_zhankai'
  52. "></span>
  53. </div>
  54. </div>
  55. <!-- 调用子组件-->
  56. <Bookmark></Bookmark>
  57. <layer-manage></layer-manage>
  58. <add-layers></add-layers>
  59. <add-base-layer></add-base-layer>
  60. <scene-atttribute></scene-atttribute>
  61. <terrain-analysis></terrain-analysis>
  62. <clip-analysis></clip-analysis>
  63. <sm3d-measure></sm3d-measure>
  64. <sm3d-analysis></sm3d-analysis>
  65. <online-edit></online-edit>
  66. <!-- <scene-camera></scene-camera> -->
  67. <!-- <city-plan></city-plan> -->
  68. <!-- 图层属性 -->
  69. <layer-attribute></layer-attribute>
  70. <!-- 特效 -->
  71. <air-lines-trail-lines></air-lines-trail-lines>
  72. <scan-effect></scan-effect>
  73. <wind-particle></wind-particle>
  74. <placename-location style="width: 400px; height: 400px; z-index: 999999"></placename-location>
  75. <click-query style="width: 400px; height: 700px; z-index: 999999"></click-query>
  76. </div>
  77. </template>
  78. <script>
  79. import clickQuery from "../../Query/clickQuery/clickQuery.vue";
  80. import { GetXzqhTree, GetXzqhGeom } from "@/api/map";
  81. import Bookmark from "../../Bookmark/Bookmark.vue";
  82. export default {
  83. components: { clickQuery, Bookmark },
  84. name: "ToolBar",
  85. props: {},
  86. data() {
  87. return {
  88. last: false,
  89. sharedState: store.state,
  90. show: true,
  91. clickShow: false,
  92. plan: false,
  93. xzqTreeData: [],
  94. xzqTreeValue: "",
  95. curXzqCode: "",
  96. Skybox: "",
  97. skyListener: null,
  98. defaultSkyBox: null,
  99. ViewerSkyBox: {},
  100. SkyboxList: [{
  101. value: 'lantian',
  102. label: '蓝天'
  103. }, {
  104. value: 'qingtian',
  105. label: '晴天'
  106. }, {
  107. value: 'wanxia',
  108. label: '晚霞'
  109. }, {
  110. value: 'cloudy',
  111. label: '多云'
  112. }, {
  113. value: 'partly_cloudy_puresky',
  114. label: '晴间多云'
  115. }, {
  116. value: 'yewan',
  117. label: '夜晚'
  118. }]
  119. };
  120. },
  121. created() {
  122. this.getXzqTreeData();
  123. this.initSkyBox();
  124. },
  125. computed: {
  126. ToolBarShow: function () {
  127. return this.sharedState.ToolBarShow;
  128. },
  129. },
  130. methods: {
  131. initSkyBox() {
  132. for (let i = 0; i < this.SkyboxList.length; i++) {
  133. let c = new Cesium.SkyBox({
  134. sources: {
  135. positiveX: "/static/Cesium/Assets/Textures/SkyBox/" + this.SkyboxList[i].value + "/Right.jpg",
  136. negativeX: "/static/Cesium/Assets/Textures/SkyBox/" + this.SkyboxList[i].value + "/Left.jpg",
  137. positiveY: "/static/Cesium/Assets/Textures/SkyBox/" + this.SkyboxList[i].value + "/Front.jpg",
  138. negativeY: "/static/Cesium/Assets/Textures/SkyBox/" + this.SkyboxList[i].value + "/Back.jpg",
  139. positiveZ: "/static/Cesium/Assets/Textures/SkyBox/" + this.SkyboxList[i].value + "/Up.jpg",
  140. negativeZ: "/static/Cesium/Assets/Textures/SkyBox/" + this.SkyboxList[i].value + "/Down.jpg",
  141. },
  142. })
  143. c.WSpeed = 0.5;
  144. this.ViewerSkyBox[this.SkyboxList[i].value] = c;
  145. }
  146. },
  147. setSkyBox() {
  148. let scene = window.viewer.scene;
  149. scene.cloudBox = null;
  150. this.currentSkyBox = this.ViewerSkyBox[this.Skybox];
  151. if (!this.last) {
  152. this.defaultSkyBox = window.scene.skyBox;
  153. this.last = !this.last;
  154. for (let attr in this.ViewerSkyBox) {
  155. this.ViewerSkyBox[attr].update(scene.frameState, true);
  156. }
  157. let that = this;
  158. this.skyListener = function () {
  159. let cameraHeight = scene.camera.positionCartographic.height;
  160. let skyAtmosphereH1 = 22e10; // 大气开始渐变的最大高度
  161. let skyBoxH1 = 15e4; // 天空开始渐变的最大高度
  162. let skyBoxH2 = 12e4; // 天空开始渐变的最小高度
  163. let bufferHeight = 1e4;
  164. if (cameraHeight < skyAtmosphereH1 && Cesium.defined(that.currentSkyBox)) {
  165. let skyAtmosphereT = (cameraHeight - skyBoxH2) / (skyAtmosphereH1 - skyBoxH2);
  166. if (skyAtmosphereT > 1.0) {
  167. skyAtmosphereT = 1.0;
  168. } else if (skyAtmosphereT < 0.0) {
  169. skyAtmosphereT = 0.0;
  170. }
  171. let skyBoxT = (cameraHeight - skyBoxH2) / (skyBoxH1 - skyBoxH2);
  172. if (skyBoxT > 1.0) {
  173. skyBoxT = 1.0;
  174. } else if (skyBoxT < 0.0) {
  175. skyBoxT = 0.0;
  176. }
  177. that.currentSkyBox.alpha = 1.0 - skyBoxT;
  178. // that.currentSkyBox.alpha = 1.0;
  179. scene.skyBox = that.currentSkyBox;
  180. if (cameraHeight > skyBoxH2) {
  181. scene.skyAtmosphere.show = true;
  182. scene.skyAtmosphere.alpha = skyAtmosphereT;
  183. // scene.skyAtmosphere.alpha = 1.0;
  184. // scene.skyBox = that.currentSkyBox;
  185. } else {
  186. scene.skyAtmosphere.show = false;
  187. }
  188. } else {
  189. scene.skyAtmosphere.alpha = 1.0;
  190. scene.skyBox = that.defaultSkyBox;
  191. }
  192. //控制相机 速率
  193. // if (scene.skyBox !== that.defaultSkyBox) {
  194. // if (cameraHeight > (skyBoxH2 - 2 * bufferHeight) && cameraHeight < skyBoxH1 + 3 * bufferHeight) {
  195. // scene.screenSpaceCameraController.zoomFactor = 0.4;
  196. // } else {
  197. // scene.screenSpaceCameraController.zoomFactor = 5.0;
  198. // }
  199. // } else {
  200. // scene.skyBox.alpha = 1.0;
  201. // scene.skyAtmosphere.alpha = 1.0;
  202. // scene.screenSpaceCameraController.zoomFactor = 5.0;
  203. // }
  204. };
  205. window.scene.postRender.addEventListener(this.skyListener);
  206. }
  207. },
  208. getXzqGeom() {
  209. GetXzqhGeom(this.curXzqCode).then((res) => {
  210. viewer.entities.removeAll();
  211. let geoms = res.data
  212. .substring(res.data.indexOf("(((") + 3, res.data.length - 3)
  213. .split(")),((");
  214. for (let i = 0; i < geoms.length; i++) {
  215. let geom = geoms[i].split(",");
  216. let points = [];
  217. for (let j = 0; j < geom.length; j++) {
  218. points.push(parseFloat(geom[j].split(" ")[0]));
  219. points.push(parseFloat(geom[j].split(" ")[1]));
  220. }
  221. points.push(parseFloat(geom[0].split(" ")[0]));
  222. points.push(parseFloat(geom[0].split(" ")[1]));
  223. viewer.entities.add({
  224. polyline: new Cesium.PolylineGraphics({
  225. positions: Cesium.Cartesian3.fromDegreesArray(points),
  226. width: 3,
  227. material: Cesium.Color.BLUE.withAlpha(0.9),
  228. clampToGround: true,
  229. }),
  230. });
  231. }
  232. viewer.flyTo(viewer.entities);
  233. });
  234. },
  235. getXzqTreeData() {
  236. GetXzqhTree().then((res) => {
  237. this.xzqTreeData = res.data;
  238. });
  239. },
  240. toggleVisibility() {
  241. //控制组件界面显隐
  242. this.show = !this.show;
  243. },
  244. choose(i) {
  245. store.setToolBarAction(i);
  246. },
  247. },
  248. watch: {
  249. xzqTreeValue(val) {
  250. viewer.entities.removeAll();
  251. this.curXzqCode = val[val.length - 1];
  252. store.setXzqdm(this.curXzqCode);
  253. if (this.curXzqCode) {
  254. this.getXzqGeom();
  255. }
  256. },
  257. Skybox() {
  258. this.setSkyBox();
  259. }
  260. },
  261. };
  262. </script>
  263. <style lang="scss" scoped>
  264. @import "toolBar";
  265. </style>