supermap-2.5d.vue 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223
  1. <template>
  2. <div id="cesiumContainer" style="width: 100%; height: 100%;background: none;">
  3. </div>
  4. </template>
  5. <script>
  6. import {iconList,queryMap} from '@/api/components/supermap.js'
  7. import {getConfigKey} from '@/api/system/config'
  8. import Cookies from "js-cookie";
  9. export default {
  10. name: 'supermap-camera-2.5d',
  11. data() {
  12. return {
  13. chooseMode: [
  14. Cesium.DrawMode.Line,
  15. Cesium.DrawMode.Polygon,
  16. ],
  17. markerList: [],
  18. bindPopupHtml: null,
  19. mapshow: false,
  20. superMapRootUrl: null,
  21. layerList: [],
  22. viewer: null,
  23. scene: null,
  24. handler: null,
  25. pick: null,
  26. back_position: null,
  27. type: null,
  28. content: null,
  29. mvtMap0: null,
  30. shuixi_name: null,
  31. mvtMap1: null,
  32. mvtMap2: null,
  33. mvtMap3: null,
  34. road_name: null,
  35. layer_xiangzhenjie_name: null,
  36. markerboxEntity: [],//地图落点实体
  37. connectBoxEntity: null,//地图线实体
  38. graphicsBoxEntity: null,//地图面实体
  39. markerboxEntityRadius: [],//地图落点实体
  40. connectBoxEntityTwo: null,//地图线实体
  41. /*************************原地图属性*********************/
  42. isEditableLayers: false, //绘图控件
  43. /*************************原地图属性*********************/
  44. aac: null,
  45. dataMap: {},
  46. queryParams: {
  47. name: null,
  48. mapData: null,
  49. mapName: null
  50. },
  51. deptId: Cookies.get('deptId'),
  52. }
  53. },
  54. watch: {},
  55. created() {
  56. },
  57. mounted() {
  58. },
  59. props: {
  60. putSmUserID_layer: null,
  61. },
  62. methods: {
  63. superMapInfo(type, obj,NB,state,map3dType) {//map3dType用于区分是多个区域还是单个区域:1等于多个区域其他为单个区域
  64. getConfigKey('superMap.iServer').then(response => {
  65. this.superMapRootUrl = response.msg;
  66. })
  67. if (state==undefined){
  68. state = 12; //监控中心
  69. }
  70. queryMap(state,this.deptId).then(req => {
  71. req = req.sort(function(a, b) {
  72. return a.sort - b.sort
  73. })
  74. this.onload(req,type, obj,NB,map3dType)
  75. }
  76. )
  77. },
  78. //清除所有
  79. clearAll() {
  80. this.viewer.entities.removeAll();
  81. },
  82. clearAllByQin(val) {
  83. this.viewer.entities.removeAll();
  84. this.entityHandler(val-2)
  85. },
  86. //移除之前添加的点
  87. clearMRadius() {
  88. if (this.markerboxEntityRadius != null && this.markerboxEntityRadius.length > 0) {
  89. for (let i = 0; i < this.markerboxEntityRadius.length; i++) {
  90. this.viewer.entities.remove(this.markerboxEntityRadius[i])
  91. }
  92. this.markerboxEntityRadius = []
  93. }
  94. },
  95. //移除之前添加的线
  96. clearTwoC() {
  97. if (this.connectBoxEntityTwo != null) {
  98. this.viewer.entities.remove(this.connectBoxEntityTwo)
  99. this.connectBoxEntityTwo = null
  100. }
  101. },
  102. /**
  103. * 地图落点-覆盖范围
  104. */
  105. setMarkersRadius(makerList) {
  106. let that = this
  107. that.handler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas)
  108. for (let i in makerList) {
  109. let longitude = makerList[i].lng;
  110. let latitude = makerList[i].lat;
  111. let marker = that.viewer.entities.add({
  112. name: "",
  113. position: Cesium.Cartesian3.fromDegrees(longitude, latitude),
  114. billboard: {
  115. image: iconList[makerList[i].icon],
  116. width: 48,
  117. height: 48,
  118. heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
  119. disableDepthTestDistance: Number.POSITIVE_INFINITY
  120. },
  121. description: makerList[i].bindPopupHtml,
  122. click: makerList[i].click,
  123. parameter: makerList[i].parameter
  124. })
  125. that.markerboxEntityRadius.push(marker)
  126. //绘制摄像头的圈(覆盖范围)
  127. let markerRadius = that.viewer.entities.add({
  128. position: Cesium.Cartesian3.fromDegrees(makerList[i].lng, makerList[i].lat, 2),
  129. ellipse: {
  130. semiMinorAxis: makerList[i].radius,
  131. semiMajorAxis: makerList[i].radius,
  132. height: 0.0,
  133. material: Cesium.Color.DODGERBLUE.withAlpha(0.4),
  134. outline: true,
  135. outlineColor: Cesium.Color.DEEPSKYBLUE.withAlpha(1),
  136. outlineWidth: 1,
  137. },
  138. });
  139. that.markerboxEntityRadius.push(markerRadius)
  140. }
  141. that.viewer.scene.globe.depthTestAgainstTerrain = false
  142. that.createLeftClickDescription()
  143. that.createRightClickDescription()
  144. },
  145. /**
  146. * 地图画线(贴地)
  147. */
  148. setConnectTwoList(connectList, color, withAlpha) {
  149. let that = this
  150. //Cesium.Color.fromCssColorString('#67ADDF') 16进制颜色设置
  151. let material = Cesium.Color.fromCssColorString(color).withAlpha(withAlpha);
  152. that.connectBoxEntityTwo = that.viewer.entities.add({
  153. Type: 'Polyline',
  154. polyline: {
  155. positions: Cesium.Cartesian3.fromDegreesArray(connectList),
  156. clampToGround: true,//贴地 true,不贴地 false
  157. width: 5,
  158. material: material
  159. }
  160. })
  161. },
  162. //移除之前添加的点
  163. clearM() {
  164. if (this.markerboxEntity != null && this.markerboxEntity.length > 0) {
  165. for (let i = 0; i < this.markerboxEntity.length; i++) {
  166. this.viewer.entities.remove(this.markerboxEntity[i])
  167. }
  168. this.markerboxEntity = []
  169. }
  170. },
  171. //移除之前添加的线
  172. clearC() {
  173. if (this.connectBoxEntity != null) {
  174. this.viewer.entities.remove(this.connectBoxEntity)
  175. this.connectBoxEntity = null
  176. }
  177. },
  178. //移除之前添加的面
  179. clearG() {
  180. if (this.graphicsBoxEntity != null) {
  181. this.viewer.entities.remove(this.graphicsBoxEntity)
  182. this.graphicsBoxEntity = null
  183. }
  184. },
  185. reload(list) {
  186. this.removeAll();
  187. this.layerList = list;
  188. for (let i = 0; i < this.layerList.length; i++) {
  189. if (this.layerList[i] == "lindi") {
  190. this.loadLindi();
  191. } else if (this.layerList[i] == "shuixi") {
  192. this.loadShuixi();
  193. } else if (this.layerList[i] == "road") {
  194. this.loadRoad();
  195. } else if (this.layerList[i] == "nongtian") {
  196. this.loadNongtian();
  197. }
  198. }
  199. },
  200. loadShuixi() {//水系
  201. let that = this;
  202. if (that.mvtMap0 != null) {
  203. that.mvtMap0.show = true;
  204. that.shuixi_name.then(function (layers) {
  205. let textlayer = that.viewer.scene.layers.find('ShuiXi@SiPing#1');//文字图层
  206. textlayer.visible = true;
  207. });
  208. }
  209. },
  210. loadLindi() {//林地
  211. if (this.mvtMap1 != null) {
  212. this.mvtMap1.show = true;
  213. }
  214. },
  215. loadNongtian() {//农田
  216. if (this.mvtMap2 != null) {
  217. this.mvtMap2.show = true;
  218. }
  219. },
  220. loadRoad() {//路网
  221. let that = this;
  222. if (that.mvtMap3 != null) {
  223. that.mvtMap3.show = true;
  224. that.road_name.then(function (layers) {
  225. let provinceRoad_textLayer = that.viewer.scene.layers.find('ProvinceRoad_L@SiPing#1');//文字图层
  226. let countyRoad_textLayer = that.viewer.scene.layers.find('CountyRoad_L@SiPing#1');//文字图层
  227. let stateRoad_textLayer = that.viewer.scene.layers.find('StateRoad_L@SiPing#1');//文字图层
  228. provinceRoad_textLayer.visible = true;
  229. countyRoad_textLayer.visible = true;
  230. stateRoad_textLayer.visible = true;
  231. });
  232. }
  233. },
  234. removeAll() {
  235. let that = this;
  236. // 移除方法,暂存:this.viewer.scene.removeVectorTilesMap(this.mvtMap3.name);
  237. if (that.mvtMap0 != null) {
  238. that.mvtMap0.show = false;
  239. //that
  240. that.shuixi_name.then(function (layers) {
  241. let textlayer = that.viewer.scene.layers.find('ShuiXi@SiPing#1');//文字图层
  242. textlayer.visible = false;
  243. });
  244. }
  245. if (that.mvtMap1 != null) {
  246. that.mvtMap1.show = false
  247. }
  248. if (that.mvtMap2 != null) {
  249. that.mvtMap2.show = false
  250. }
  251. if (that.mvtMap3 != null) {
  252. that.mvtMap3.show = false
  253. //NAME隐藏
  254. that.road_name.then(function (layers) {
  255. let provinceRoad_textLayer = that.viewer.scene.layers.find('ProvinceRoad_L@SiPing#1');//文字图层
  256. let countyRoad_textLayer = that.viewer.scene.layers.find('CountyRoad_L@SiPing#1');//文字图层
  257. let stateRoad_textLayer = that.viewer.scene.layers.find('StateRoad_L@SiPing#1');//文字图层
  258. provinceRoad_textLayer.visible = false;
  259. countyRoad_textLayer.visible = false;
  260. stateRoad_textLayer.visible = false;
  261. });
  262. }
  263. },
  264. addImageryProvider(uri) {
  265. let that = this
  266. that.viewer.imageryLayers.addImageryProvider(new Cesium.SuperMapImageryProvider({
  267. url: that.superMapRootUrl + uri
  268. }))
  269. },
  270. addVectorTilesMap(uri) {
  271. let that = this
  272. that.scene.addVectorTilesMap({
  273. url: that.superMapRootUrl + uri,
  274. canvasWidth: 512,
  275. name: 'mvt_map3',
  276. viewer: that.viewer,
  277. show: true
  278. })
  279. },
  280. addOpen(sort, uri) {
  281. let that = this
  282. that.dataMap[sort] = that.scene.open(that.superMapRootUrl + uri)
  283. },
  284. addOpen_model(sort, uri) {
  285. let that = this
  286. that.dataMap[sort] = that.scene.open(that.superMapRootUrl + uri)
  287. //开始加载专题图等数据,8秒后开始执行
  288. setTimeout(function () {
  289. /**
  290. * @param dom ScreenSpaceEventHandler操作的dom节点,画的框会成为其子节点
  291. */
  292. function DrawRectHandler(dom) {
  293. let startPoint,
  294. self = this,
  295. isShiftAndLeftDown = false,
  296. handler = new Cesium.ScreenSpaceEventHandler(dom),
  297. removalFunctions = [],
  298. rect = new Rect(dom)
  299. this.isDestroyed = false
  300. this.activeEvt = new Cesium.Event()
  301. this.cancelEvt = new Cesium.Event()
  302. this.movingEvt = new Cesium.Event()
  303. this.drawEvt = new Cesium.Event()
  304. // div框
  305. function Rect(parentDom) {
  306. this.rect = document.createElement('div')
  307. this.rect.style.visibility = 'hidden'
  308. parentDom.appendChild(this.rect)
  309. this.leftTopPoint = new Cesium.Cartesian2()
  310. this.rightBottomPoint = new Cesium.Cartesian2()
  311. Rect.prototype.setPosition = function (startPoint, endPosition) {
  312. let w = endPosition.x - startPoint.x
  313. let h = endPosition.y - startPoint.y
  314. let left, top, width, height
  315. if (w < 0) {
  316. left = endPosition.x
  317. width = -w
  318. } else {
  319. left = startPoint.x
  320. width = w
  321. }
  322. if (h < 0) {
  323. top = endPosition.y
  324. height = -h
  325. } else {
  326. top = startPoint.y
  327. height = h
  328. }
  329. this.leftTopPoint = new Cesium.Cartesian2(left, top)
  330. this.rightBottomPoint = new Cesium.Cartesian2(left + width, top + height)
  331. this.rect.style = `position:fixed;top:${top}px;left:${left}px;width:${width}px;height:${height}px;border:2px dashed #333;`
  332. this.setVisible(true)
  333. }
  334. Rect.prototype.setVisible = function (isVisible) {
  335. this.rect.style.visibility = isVisible ? 'visible' : 'hidden'
  336. }
  337. Rect.prototype.getRectPoint = function () {
  338. return {
  339. leftTopPoint: this.leftTopPoint,
  340. rightBottomPoint: this.rightBottomPoint
  341. }
  342. }
  343. Rect.prototype.destroy = function () {
  344. dom.removeChild(rect)
  345. this.rect = null
  346. }
  347. }
  348. // canvas框
  349. function RectCanvas(parentDom) {
  350. let canvas = document.createElement('canvas'),
  351. ctx = canvas.getContext('2d')
  352. this.canvas = canvas
  353. canvas.width = parentDom.clientWidth
  354. canvas.height = parentDom.clientHeight
  355. canvas.style = 'position:fixed;top:0;left:0;z-index:-1'
  356. parentDom.appendChild(canvas)
  357. this.leftTopPoint = new Cesium.Cartesian2()
  358. this.rightBottomPoint = new Cesium.Cartesian2()
  359. RectCanvas.prototype.setPosition = function (startPoint, endPosition) {
  360. let w = endPosition.x - startPoint.x
  361. let h = endPosition.y - startPoint.y
  362. let left, top, width, height
  363. if (w < 0) {
  364. left = endPosition.x
  365. width = -w
  366. } else {
  367. left = startPoint.x
  368. width = w
  369. }
  370. if (h < 0) {
  371. top = endPosition.y
  372. height = -h
  373. } else {
  374. top = startPoint.y
  375. height = h
  376. }
  377. this.leftTopPoint = new Cesium.Cartesian2(left, top)
  378. this.rightBottomPoint = new Cesium.Cartesian2(left + width, top + height)
  379. ctx.clearRect(0, 0, canvas.width, canvas.height)
  380. ctx.strokeRect(left, top, width, height)
  381. }
  382. RectCanvas.prototype.setVisible = function (isVisible) {
  383. if (isVisible) {
  384. canvas.style.zIndex = '999'
  385. } else {
  386. canvas.style.zIndex = '-1'
  387. }
  388. }
  389. RectCanvas.prototype.getRectPoint = function () {
  390. return {
  391. leftTopPoint: this.leftTopPoint,
  392. rightBottomPoint: this.rightBottomPoint
  393. }
  394. }
  395. RectCanvas.prototype.destroy = function () {
  396. dom.removeChild(canvas)
  397. ctx = null
  398. this.canvas = null
  399. }
  400. }
  401. // 开关相机控制
  402. function setCameraCtrl(isActive) {
  403. let cameraCtrl = that.scene.screenSpaceCameraController
  404. cameraCtrl.enableRotate = isActive
  405. cameraCtrl.enableTranslate = isActive
  406. cameraCtrl.enableZoom = isActive
  407. cameraCtrl.enableTilt = isActive
  408. cameraCtrl.enableLook = isActive
  409. }
  410. // 鼠标cursor控制
  411. function toggleCursorStyle(isActive) {
  412. if (isActive) {
  413. that.viewer.enableCursorStyle = false
  414. that.viewer._element.style.cursor = ''
  415. dom.style.cursor = 'default'
  416. } else {
  417. that.viewer.enableCursorStyle = true
  418. }
  419. }
  420. // 初始化事件处理
  421. function initEvent() {
  422. handler.setInputAction(function (e) {
  423. isShiftAndLeftDown = true
  424. startPoint = new Cesium.Cartesian2(e.position.x, e.position.y)
  425. }, Cesium.ScreenSpaceEventType.LEFT_DOWN, Cesium.KeyboardEventModifier.SHIFT)
  426. // shift松开时,始终将rect隐藏
  427. let keyUpFunction = function (e) {
  428. self.cancelEvt.raiseEvent()
  429. if (e.key == 'Shift' && isShiftAndLeftDown && !self.isDestroyed) {
  430. isShiftAndLeftDown = false
  431. rect.setVisible(false)
  432. }
  433. }
  434. document.addEventListener('keyup', keyUpFunction)
  435. removalFunctions.push(function () {
  436. document.removeEventListener('keyup', keyUpFunction)
  437. })
  438. handler.setInputAction(function (e) {
  439. let endPosition = e.endPosition
  440. self.activeEvt.raiseEvent(endPosition)
  441. if (!isShiftAndLeftDown) return
  442. rect.setPosition(startPoint, endPosition)
  443. rect.setVisible(true)
  444. self.movingEvt.raiseEvent(rect.getRectPoint())
  445. }, Cesium.ScreenSpaceEventType.MOUSE_MOVE, Cesium.KeyboardEventModifier.SHIFT)
  446. handler.setInputAction(function (e) {
  447. isShiftAndLeftDown = false
  448. rect.setVisible(false)
  449. self.drawEvt.raiseEvent(rect.getRectPoint())
  450. }, Cesium.ScreenSpaceEventType.LEFT_UP, Cesium.KeyboardEventModifier.SHIFT)
  451. handler.setInputAction(function (e) {
  452. isShiftAndLeftDown = false
  453. rect.setVisible(false)
  454. }, Cesium.ScreenSpaceEventType.LEFT_UP)
  455. }
  456. // 移除事件监听
  457. function removeEvent() {
  458. handler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_DOWN, Cesium.KeyboardEventModifier.SHIFT)
  459. handler.removeInputAction(Cesium.ScreenSpaceEventType.MOUSE_MOVE, Cesium.KeyboardEventModifier.SHIFT)
  460. handler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_UP, Cesium.KeyboardEventModifier.SHIFT)
  461. handler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_UP)
  462. }
  463. DrawRectHandler.prototype.destroy = function () {
  464. if (this.isDestroyed) return
  465. setCameraCtrl(true)
  466. removeEvent()
  467. for (let i = 0, j = removalFunctions.length; i < j; i++) {
  468. removalFunctions[i]()
  469. }
  470. handler.destroy()
  471. rect.destroy()
  472. rect = null
  473. this.isDestroyed = true
  474. }
  475. DrawRectHandler.prototype.activate = function () {
  476. if (this.isDestroyed) return
  477. setCameraCtrl(false)
  478. toggleCursorStyle(true)
  479. initEvent()
  480. }
  481. DrawRectHandler.prototype.deactivate = function () {
  482. if (this.isDestroyed) return
  483. setCameraCtrl(true)
  484. toggleCursorStyle(false)
  485. removeEvent()
  486. }
  487. }
  488. new Cesium.when(that.dataMap[sort], function (layers) {
  489. for (let layer of layers) {
  490. layer.selectColorType = 1
  491. that.selectedObjs[layer.name] = []
  492. that.resetIds[layer.name] = []
  493. }
  494. let drawRect = that.drawRect = new DrawRectHandler(document.body)
  495. // res为框的左上点与右下点的相对于给定dom节点的坐标
  496. drawRect.drawEvt.addEventListener(function (res) {
  497. for (let layer of layers) {
  498. layer.selectColorType = 1
  499. }
  500. that.tooltip = false
  501. let selectedColor = new Cesium.Color(1, 0, 0, 1)
  502. that.scene.pickRect(res.leftTopPoint, res.rightBottomPoint)
  503. let objs = that.scene.getPickRectIDs()
  504. let selectedObjs = that.selectedObjs
  505. let resetIds = that.resetIds
  506. for (let k in selectedObjs) {
  507. if (selectedObjs[k].length > 0) {
  508. that.scene.layers.find(k).removeObjsColor(selectedObjs[k])
  509. }
  510. }
  511. if (that.kuangxuan) {
  512. for (let layer of layers) {
  513. let layerName = layer.name
  514. if (layerName === undefined) break
  515. let layerSlt = objs.find(e => e.layerName === layerName)
  516. let sltIds = (layerSlt && layerSlt.ids) || []
  517. resetIds[layerName] = selectedObjs[layerName]
  518. selectedObjs[layerName] = sltIds
  519. console.log('框选结束', sltIds)
  520. that.$parent.$refs.ldTk.FrameSelectedData(sltIds)
  521. that.$parent.$refs.ldTk.allLouDongDialog = true
  522. layer.setObjsColor(selectedObjs[layerName], selectedColor)
  523. }
  524. }
  525. })
  526. drawRect.movingEvt.addEventListener(function (res) {
  527. that.tooltip = true
  528. if (that.kuangxuan) {
  529. that.tooltipText = "松开鼠标左键以结束选择区域"
  530. for (let layer of layers) {
  531. layer.selectColorType = 1
  532. }
  533. that.scene.pickRect(res.leftTopPoint, res.rightBottomPoint)
  534. } else {
  535. that.tooltipText = "请点击框选"
  536. }
  537. })
  538. drawRect.activeEvt.addEventListener(function (position) {
  539. that.tooltip = true
  540. if (that.kuangxuan) {
  541. that.tooltipText = "松开鼠标左键以结束选择区域"
  542. } else {
  543. that.tooltipText = "请点击框选"
  544. }
  545. })
  546. drawRect.cancelEvt.addEventListener(function () {
  547. that.tooltip = false
  548. })
  549. let canvas = document.querySelector('div.cesium-widget canvas')
  550. canvas.setAttribute('tabindex', '0') // needed to put focus on the canvas
  551. canvas.focus()
  552. document.addEventListener('keydown', function (e) {
  553. if (e.key === 'Shift') {
  554. drawRect.activate()
  555. }
  556. })
  557. document.addEventListener('keyup', function (e) {
  558. if (e.key === 'Shift') {
  559. drawRect.deactivate()
  560. }
  561. })
  562. }, function () {
  563. // let title = '加载SCP失败,请检查网络连接状态或者url地址是否正确?'
  564. // widget.showErrorPanel(title, undefined, e)
  565. }).then(function () {
  566. }, function (e) {
  567. console.log(e)
  568. })
  569. }, 3000);
  570. },
  571. addFind(parentId, uri) {
  572. let that = this
  573. that.dataMap[parentId].then(function(layers) {
  574. let dat = that.scene.layers.find(uri) //区县文字图层
  575. //关闭避让
  576. dat.isOverlapDisplayed = true
  577. })
  578. },
  579. flyTo(longitude, latitude, height) {
  580. let that = this
  581. setTimeout(function() {
  582. that.viewer.camera.flyTo({
  583. destination: Cesium.Cartesian3.fromDegrees(longitude, latitude, height),
  584. orientation: {}
  585. })
  586. }, 3000)
  587. },
  588. onload(supermapUrls,type, obj,NB,map3dType) {
  589. let that = this
  590. const withinData = supermapUrls
  591. //1.添加地形数据
  592. that.viewer = new Cesium.Viewer('cesiumContainer', {
  593. //创建地形服务提供者的实例,url为SuperMap iServer发布的TIN地形服务
  594. terrainProvider: new Cesium.CesiumTerrainProvider({
  595. url: that.superMapRootUrl + '/3D-sipingchangjing/rest/realspace/datas/dem@spyx4326',
  596. //isSct : false,//地形服务源自SuperMap iServer发布时需设置isSct为true
  597. invisibility: true
  598. }),
  599. infoBox: false,
  600. navigation: false
  601. }, {
  602. contextOptions: {
  603. msaaLevel: 4,
  604. requestWebgl2: true
  605. },
  606. orderIndependentTranslucency: false
  607. })
  608. that.scene = that.viewer.scene
  609. that.viewer.cesiumWidget.creditContainer.style.display = 'none' // 去掉超图logo水印
  610. //2.添加SuperMap iServer发布的影像服务
  611. that.addImageryProvider(withinData[0].path)
  612. let longitude = withinData[0].coordinate.split(',')[0]
  613. let latitude = withinData[0].coordinate.split(',')[1]
  614. let height = withinData[0].scale
  615. that.flyTo(longitude, latitude, height)
  616. setTimeout(function() {
  617. for (let i = 1; i < withinData.length; i++) {
  618. setTimeout(() => {
  619. if (withinData[i].type == 'addImagery') {
  620. that.addImageryProvider(withinData[i].path)
  621. } else if (withinData[i].type == 'addVectorTilesMap') {
  622. that.addVectorTilesMap(withinData[i].path)
  623. } else if (withinData[i].type == 'open') {
  624. that.addOpen(withinData[i].sort, withinData[i].path)
  625. }else if (withinData[i].type == 'open_model') {
  626. that.addOpen_model(withinData[i].sort, withinData[i].path)
  627. } else if (withinData[i].type == 'find') {
  628. that.addFind(withinData[i].parentId, withinData[i].path)
  629. }
  630. }, 100 * i)
  631. }
  632. }, 3000)
  633. /*//1.添加地形数据
  634. that.viewer = new Cesium.Viewer('cesiumContainer', {
  635. //创建地形服务提供者的实例,url为SuperMap iServer发布的TIN地形服务
  636. terrainProvider: new Cesium.CesiumTerrainProvider({
  637. url: that.superMapRootUrl + "/3D-sipingchangjing/rest/realspace/datas/dem@spyx4326",
  638. //isSct : false,//地形服务源自SuperMap iServer发布时需设置isSct为true
  639. invisibility: true
  640. }),
  641. infoBox: false,
  642. navigation: false
  643. }, {
  644. contextOptions: {
  645. msaaLevel: 4,
  646. requestWebgl2: true
  647. },
  648. orderIndependentTranslucency: false
  649. });
  650. let scene = that.viewer.scene;
  651. that.viewer.cesiumWidget.creditContainer.style.display = "none" // 去掉超图logo水印
  652. //2.添加SuperMap iServer发布的影像服务
  653. let layer = that.viewer.imageryLayers.addImageryProvider(new Cesium.SuperMapImageryProvider({
  654. url: that.superMapRootUrl + "/3D-sipingchangjing/rest/realspace/datas/siping_2m@spyx4326",
  655. }));
  656. //3.添加SuperMap 建筑场景
  657. let aaaa = that.superMapRootUrl + "/3D-local3DCache-Data3/rest/realspace";
  658. scene.open(aaaa);*/
  659. //飞行值坐标点,每3秒推进一级
  660. //heading-代表镜头左右方向,正值为右,负值为左
  661. //pitch-代表镜头上下方向,正值为上,负值为下.
  662. //roll-代表镜头左右倾斜,正值,向右倾斜,负值向左倾斜
  663. /*setTimeout(function () {
  664. that.viewer.camera.flyTo({
  665. destination: Cesium.Cartesian3.fromDegrees(124.49980650138238, 43.428263986216815, 950000),
  666. orientation: {
  667. // heading : Cesium.Math.toRadians(346.4202942851978),
  668. // pitch : Cesium.Math.toRadians(-56.74026687972041),
  669. // roll : Cesium.Math.toRadians(0)
  670. }
  671. });
  672. }, 3000);
  673. setTimeout(function () {
  674. that.viewer.camera.flyTo({
  675. destination: Cesium.Cartesian3.fromDegrees(124.49980650138238, 43.428263986216815, 650000),
  676. orientation: {
  677. // heading : Cesium.Math.toRadians(346.4202942851978),
  678. // pitch : Cesium.Math.toRadians(-56.74026687972041),
  679. // roll : Cesium.Math.toRadians(0)
  680. }
  681. });
  682. }, 3000);
  683. setTimeout(function () {
  684. that.viewer.camera.flyTo({
  685. destination: Cesium.Cartesian3.fromDegrees(124.49980650138238, 43.428263986216815, 350000),
  686. orientation: {
  687. // heading : Cesium.Math.toRadians(346.4202942851978),
  688. // pitch : Cesium.Math.toRadians(-56.74026687972041),
  689. // roll : Cesium.Math.toRadians(0)
  690. }
  691. });
  692. }, 3000);*/
  693. //开始加载专题图等数据,8秒后开始执行
  694. /*setTimeout(function () {
  695. //3.水系
  696. let shuixi = that.superMapRootUrl + "/map-mvt-shuixiMian/restjsr/v1/vectortile/maps/shuixi_Mian";
  697. that.mvtMap0 = scene.addVectorTilesMap({
  698. url: shuixi,
  699. canvasWidth: 512,
  700. name: 'mvt_map0',
  701. viewer: that.viewer
  702. });
  703. that.mvtMap0.selectedColor = new Cesium.Color(6, 169, 254, 0.5);
  704. that.mvtMap0.show = false;
  705. //4.林地
  706. let lindi = that.superMapRootUrl + "/map-mvt-lindi/restjsr/v1/vectortile/maps/lindi";
  707. that.mvtMap1 = scene.addVectorTilesMap({
  708. url: lindi,
  709. canvasWidth: 512,
  710. name: 'mvt_map1',
  711. viewer: that.viewer
  712. });
  713. that.mvtMap1.selectedColor = new Cesium.Color(6, 254, 181, 0.5);
  714. that.mvtMap1.show = false;
  715. //5.农田
  716. let nongtian = that.superMapRootUrl + "/map-mvt-nongtian/restjsr/v1/vectortile/maps/nongtian";
  717. that.mvtMap2 = scene.addVectorTilesMap({
  718. url: nongtian,
  719. canvasWidth: 512,
  720. name: 'mvt_map2',
  721. viewer: that.viewer
  722. });
  723. that.mvtMap2.selectedColor = new Cesium.Color(250, 236, 246, 1.0);
  724. that.mvtMap2.show = false;
  725. //6.路网
  726. let road = that.superMapRootUrl + "/map-mvt-roadXian/restjsr/v1/vectortile/maps/road_Xian";
  727. that.mvtMap3 = scene.addVectorTilesMap({
  728. url: road,
  729. canvasWidth: 512,
  730. name: 'mvt_map3',
  731. viewer: that.viewer
  732. });
  733. that.mvtMap3.show = false;
  734. //7.添加路网NAME
  735. let road_name_url = that.superMapRootUrl + '/3D-road_Name_S/rest/realspace';
  736. that.road_name = scene.open(road_name_url);
  737. that.road_name.then(function (layers) {
  738. let provinceRoad_textLayer = scene.layers.find('ProvinceRoad_L@SiPing#1');//文字图层
  739. let countyRoad_textLayer = scene.layers.find('CountyRoad_L@SiPing#1');//文字图层
  740. let stateRoad_textLayer = scene.layers.find('StateRoad_L@SiPing#1');//文字图层
  741. //加载后隐藏
  742. provinceRoad_textLayer.visible = false;
  743. countyRoad_textLayer.visible = false;
  744. stateRoad_textLayer.visible = false;
  745. //关闭避让
  746. provinceRoad_textLayer.isOverlapDisplayed = true;
  747. countyRoad_textLayer.isOverlapDisplayed = true;
  748. stateRoad_textLayer.isOverlapDisplayed = true;
  749. });
  750. // 8.添加水系NAME
  751. let shuixi_name_url = that.superMapRootUrl + '/3D-shuixi_Name/rest/realspace';
  752. that.shuixi_name = scene.open(shuixi_name_url);
  753. that.shuixi_name.then(function (layers) {
  754. let textlayer = scene.layers.find('ShuiXi@SiPing#1');//文字图层
  755. //加载后隐藏
  756. textlayer.visible = false;
  757. //关闭避让
  758. textlayer.isOverlapDisplayed = true;
  759. });
  760. //9.添加县界和乡镇界
  761. let layer_xianjie = that.viewer.imageryLayers.addImageryProvider(new Cesium.SuperMapImageryProvider({
  762. url: that.superMapRootUrl + "/map-SIPING/rest/maps/XianJie_XiangZhenJie",
  763. }));
  764. //10.添加区县乡镇村名称
  765. let layer_xiangzhenjie_name = that.superMapRootUrl + '/3D-Name_he/rest/realspace';
  766. scene.open(layer_xiangzhenjie_name);
  767. that.road_name.then(function (layers) {
  768. let xianJie_textLayer = scene.layers.find('XianJie@SiPing#1');//区县文字图层
  769. let xiangZhenJie_textLayer = scene.layers.find('XiangZhenJie@SiPing#2');//乡镇文字图层
  770. let cun_textLayer = scene.layers.find('Cun@SiPing#1');//村文字图层
  771. //关闭避让
  772. xianJie_textLayer.isOverlapDisplayed = true;
  773. xiangZhenJie_textLayer.isOverlapDisplayed = true;
  774. cun_textLayer.isOverlapDisplayed = true;
  775. });
  776. // //9.添加乡镇界
  777. // let layer_xiangzhenjie = that.viewer.imageryLayers.addImageryProvider(new Cesium.SuperMapImageryProvider({
  778. // url : that.superMapRootUrl+"/map-SIPING/rest/maps/XiangZhenJie",
  779. // }));
  780. //
  781. // //10.添加县界
  782. // let layer_xianjie = that.viewer.imageryLayers.addImageryProvider(new Cesium.SuperMapImageryProvider({
  783. // url : that.superMapRootUrl+"/map-SIPING/rest/maps/XianJie",
  784. // }));
  785. // //11.添加县界名称 此处要先添加县界名称 否则县界名会不显示
  786. // let layer_xianjie_name = that.superMapRootUrl+'/3D-XianJie_Name/rest/realspace';
  787. // scene.open(layer_xianjie_name);
  788. //
  789. // //12.添加乡镇界名称
  790. // let layer_xiangzhenjie_name = that.superMapRootUrl+'/3D-XiangZhenJie_Name/rest/realspace';
  791. // scene.open(layer_xiangzhenjie_name);
  792. }, 3000);*/
  793. if (NB!='NB') {
  794. if (type == 1) {//拾取点位
  795. that.getLeftClickDescription(obj);
  796. }
  797. if (type == 2) {//标线
  798. that.entityHandler(0);
  799. that.setConnectList(obj.graphicsList, obj.color, obj.withAlpha);
  800. }
  801. if (type == 3) {//标面
  802. that.entityHandler(1);
  803. if (map3dType == 1){//多区域
  804. this.setGraphicsList2(obj.graphicsList, obj.color, obj.withAlpha)
  805. }else {//单区域
  806. that.setGraphicsList1(obj.graphicsList, obj.color, obj.withAlpha);
  807. }
  808. }
  809. }
  810. if (NB=='NB' && type == 2){
  811. // console.log(obj)
  812. that.entityHandler(0);
  813. // that.setConnectList(obj.graphicsList, obj.color, obj.withAlpha);
  814. for (let i = 0; i < obj.length; i++) {
  815. let arrayBlue = [];
  816. let arrayRed = [];
  817. // if (Array.isArray(obj[i].params)){
  818. for (let j = 0; j < obj[i].params.length; j++) {
  819. if (obj[i].id===666){
  820. arrayBlue.push(obj[i].params[j].lng);
  821. arrayBlue.push(obj[i].params[j].lat);
  822. }
  823. else {
  824. arrayRed.push(obj[i].params[j].lng);
  825. arrayRed.push(obj[i].params[j].lat);
  826. }
  827. }
  828. that.setConnectTwoList(
  829. Array.isArray(arrayRed) && arrayRed.length > 0 ? arrayRed : [],
  830. "rgba(232,14,14,0)",
  831. 0.8
  832. );
  833. that.setConnectTwoList(
  834. Array.isArray(arrayBlue) && arrayBlue.length > 0 ? arrayBlue : [],
  835. "rgba(14,25,231,0)",
  836. 0.8
  837. );
  838. // }
  839. }
  840. }
  841. that.viewer.selectedEntityChanged.addEventListener(function (entity) {
  842. if (entity != undefined && Reflect.has(entity, 'layerID')) {
  843. that.putSmUserID_layer(entity);
  844. }
  845. });
  846. },
  847. entityHandler(chooseDrawMode) {
  848. let that = this;
  849. that.markerList = [];
  850. that.handler = new Cesium.DrawHandler(that.viewer, that.chooseMode[chooseDrawMode]);
  851. that.handler.activeEvt.addEventListener(function (isActive) {
  852. if (isActive == true) {
  853. that.viewer.enableCursorStyle = false;
  854. that.viewer._element.style.cursor = '';
  855. } else {
  856. that.viewer.enableCursorStyle = true;
  857. }
  858. });
  859. that.viewer.scene.globe.depthTestAgainstTerrain = false
  860. that.handler.activate();
  861. var newhandler = new Cesium.ScreenSpaceEventHandler(that.viewer.scene.canvas);
  862. newhandler.setInputAction(function (event) {
  863. // 屏幕坐标转世界坐标——关键点
  864. var ellipsoid = that.viewer.scene.globe.ellipsoid;
  865. var cartesian = that.viewer.camera.pickEllipsoid(event.position, ellipsoid);
  866. //将笛卡尔坐标转换为地理坐标
  867. var cartographic = Cesium.Cartographic.fromCartesian(cartesian);
  868. //将弧度转为度的十进制度表示
  869. var lon = Cesium.Math.toDegrees(cartographic.longitude);
  870. var lat = Cesium.Math.toDegrees(cartographic.latitude);
  871. let draw = {lng: 0, lat: 0};
  872. draw.lng = lon;
  873. draw.lat = lat;
  874. if (!that.markerList.includes(draw)) {
  875. that.markerList.push(draw);
  876. that.$emit("showLatLng", {markerList: that.markerList});
  877. }
  878. }, Cesium.ScreenSpaceEventType.LEFT_CLICK)
  879. },
  880. getLeftClickDescription(obj) {
  881. let that = this
  882. that.handler = new Cesium.ScreenSpaceEventHandler(that.viewer.scene.canvas);
  883. if (obj.longitude) {
  884. //在点击位置添加对应点
  885. that.viewer.entities.add({
  886. name: '',
  887. position: Cesium.Cartesian3.fromDegrees(obj.longitude, obj.latitude),
  888. billboard: {
  889. image: iconList['marker'],
  890. width: 48,
  891. height: 48,
  892. disableDepthTestDistance: Number.POSITIVE_INFINITY
  893. },
  894. })
  895. }
  896. //设置鼠标左键单击回调事件
  897. that.handler.setInputAction(function (e) {
  898. //首先移除之前添加的点
  899. that.viewer.entities.removeAll();
  900. //获取点击位置笛卡尔坐标
  901. let position = that.viewer.scene.pickPosition(e.position);
  902. //将笛卡尔坐标转化为经纬度坐标
  903. let cartographic = Cesium.Cartographic.fromCartesian(position);
  904. let longitude = Cesium.Math.toDegrees(cartographic.longitude);
  905. let latitude = Cesium.Math.toDegrees(cartographic.latitude);
  906. that.$emit("showLatLng", {latitude: latitude, longitude: longitude})
  907. //在点击位置添加对应点
  908. that.viewer.entities.add({
  909. name: '',
  910. position: Cesium.Cartesian3.fromDegrees(longitude, latitude),
  911. billboard: {
  912. image: iconList['marker'],
  913. width: 48,
  914. height: 48,
  915. heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
  916. disableDepthTestDistance: Number.POSITIVE_INFINITY
  917. },
  918. })
  919. that.markerboxEntity.push(marker)
  920. that.viewer.scene.globe.depthTestAgainstTerrain = false
  921. }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
  922. },
  923. /**
  924. * 地图落点
  925. */
  926. setMarkers(makerList) {
  927. let that = this
  928. that.handler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas)
  929. for (let i in makerList) {
  930. let longitude = makerList[i].lng;
  931. let latitude = makerList[i].lat;
  932. let marker = that.viewer.entities.add({
  933. name: "",
  934. position: Cesium.Cartesian3.fromDegrees(longitude, latitude),
  935. billboard: {
  936. image: iconList[makerList[i].icon],
  937. width: 48,
  938. height: 48,
  939. heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
  940. disableDepthTestDistance: Number.POSITIVE_INFINITY
  941. },
  942. description: makerList[i].bindPopupHtml,
  943. click: makerList[i].click,
  944. parameter: makerList[i].parameter
  945. })
  946. that.markerboxEntity.push(marker)
  947. }
  948. that.viewer.scene.globe.depthTestAgainstTerrain = false
  949. that.createLeftClickDescription()
  950. that.createRightClickDescription()
  951. },
  952. /**
  953. *鼠标左击事件是原来的气泡
  954. */
  955. createLeftClickDescription() {
  956. let that = this;
  957. that.handler.setInputAction(function (movement) {
  958. that.pick = that.viewer.scene.pick(movement.position);
  959. if (that.pick && that.pick) {
  960. let id = Cesium.defaultValue(that.viewer.scene.pick(movement.position).id, that.viewer.scene.pick(
  961. movement.position).primitive.id);
  962. let html = id._description;
  963. if (html != undefined && html._value != null && html._value != '') {
  964. that.bindPopupHtml = html
  965. that.mapshow = true
  966. } else {
  967. that.mapshow = false
  968. }
  969. } else {
  970. that.mapshow = false
  971. }
  972. }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
  973. },
  974. /**
  975. *鼠标右击事件是原来的点击
  976. */
  977. createRightClickDescription() {
  978. let that = this;
  979. that.handler.setInputAction(function (movement) {
  980. that.mapshow = false
  981. // 监听鼠标的当前位置坐标,然后根据当前坐标去动态更新气泡窗口div的显示位置;
  982. that.pick = that.viewer.scene.pick(movement.position);
  983. if (that.pick && that.pick) {
  984. let id = Cesium.defaultValue(that.viewer.scene.pick(movement.position).id, that.viewer.scene.pick(movement.position).primitive.id);
  985. let clickName = id._click;
  986. that.$emit(clickName, id._parameter)
  987. }
  988. }, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
  989. },
  990. /**
  991. * 落点定位
  992. */
  993. dropLocation(lat, lng) {
  994. this.viewer.camera.flyTo({
  995. destination: Cesium.Cartesian3.fromDegrees(lng, lat, 3000),
  996. });
  997. },
  998. /**
  999. * 地图画线(贴地)
  1000. */
  1001. setConnectList(connectList, color, withAlpha) {
  1002. let that = this
  1003. //Cesium.Color.fromCssColorString('#67ADDF') 16进制颜色设置
  1004. let material = Cesium.Color.fromCssColorString(color).withAlpha(withAlpha);
  1005. that.connectBoxEntity = that.viewer.entities.add({
  1006. Type: 'Polyline',
  1007. polyline: {
  1008. positions: Cesium.Cartesian3.fromDegreesArray(connectList),
  1009. clampToGround: true,//贴地 true,不贴地 false
  1010. width: 5,
  1011. material: material
  1012. }
  1013. })
  1014. setTimeout(() => {
  1015. if(connectList!=null&&Array.isArray(connectList)&&connectList.length>0){
  1016. that.viewer.camera.flyTo({
  1017. destination: Cesium.Cartesian3.fromDegrees(connectList[0],connectList[1],6500),
  1018. complete: function () {
  1019. // 飞行结束后设置相机的高度
  1020. var newHeight = 6500;
  1021. var destination = that.viewer.camera.position.clone();
  1022. destination.z = newHeight;
  1023. }
  1024. });
  1025. }
  1026. }, 3000);
  1027. },
  1028. setGraphicsList1(graphicsList, color, withAlpha) {
  1029. let that = this
  1030. //Cesium.Color.fromCssColorString('#67ADDF') 16进制颜色设置
  1031. let material = Cesium.Color.fromCssColorString(color).withAlpha(withAlpha);
  1032. that.graphicsBoxEntity = that.viewer.entities.add({
  1033. polygon: {
  1034. hierarchy: Cesium.Cartesian3.fromDegreesArray(graphicsList),
  1035. clampToGround: true,//贴地 true,不贴地 false
  1036. width: 5,
  1037. material: material
  1038. }
  1039. });
  1040. setTimeout(() => {
  1041. if(graphicsList!=null&&Array.isArray(graphicsList)&&graphicsList.length>0){
  1042. that.viewer.camera.flyTo({
  1043. destination: Cesium.Cartesian3.fromDegrees(graphicsList[0],graphicsList[1],6500),
  1044. complete: function () {
  1045. // 飞行结束后设置相机的高度
  1046. var newHeight = 6500;
  1047. var destination = that.viewer.camera.position.clone();
  1048. destination.z = newHeight;
  1049. }
  1050. });
  1051. }
  1052. }, 3000);
  1053. },
  1054. setGraphicsList2(graphicsList, color, withAlpha) {
  1055. let that = this;
  1056. that.viewer.entities.removeAll(); // 移除地图标点
  1057. let material = Cesium.Color.fromCssColorString(color).withAlpha(withAlpha);
  1058. for (let i = 0; i < graphicsList.length; i++) {
  1059. let positions = Cesium.Cartesian3.fromDegreesArray(graphicsList[i].latLng);
  1060. let name = graphicsList[i].name.toString();
  1061. let center = Cesium.BoundingSphere.fromPoints(positions).center;
  1062. let namePosition = Cesium.Cartographic.fromCartesian(center);
  1063. namePosition.height = 0; // 将名称高度设置为0,使其贴地显示
  1064. that.graphicsBoxEntity = that.viewer.entities.add({
  1065. polygon: {
  1066. hierarchy: positions,
  1067. clampToGround: true,
  1068. width: 5,
  1069. material: material
  1070. }
  1071. });
  1072. that.viewer.entities.add({
  1073. position: center,
  1074. label: {
  1075. text: name ,
  1076. font: 'Bold 12px sans-serif',
  1077. fillColor: Cesium.Color.BLACK,
  1078. outlineColor: Cesium.Color.WHITE,
  1079. outlineWidth: 2,
  1080. pixelOffset: new Cesium.Cartesian2(0, 0),
  1081. heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
  1082. disableDepthTestDistance: Number.POSITIVE_INFINITY
  1083. }
  1084. });
  1085. }
  1086. },
  1087. /**
  1088. * 地图图形(贴地)
  1089. */
  1090. setGraphicsList(graphicsList, color, withAlpha) {
  1091. let that = this
  1092. //Cesium.Color.fromCssColorString('#67ADDF') 16进制颜色设置
  1093. let material = Cesium.Color.fromCssColorString(color).withAlpha(withAlpha);
  1094. that.graphicsBoxEntity = that.viewer.entities.add({
  1095. polygon: {
  1096. hierarchy: Cesium.Cartesian3.fromDegreesArray(graphicsList),
  1097. clampToGround: true,//贴地 true,不贴地 false
  1098. width: 5,
  1099. material: material
  1100. }
  1101. })
  1102. setTimeout(() => {
  1103. if(graphicsList!=null&&Array.isArray(graphicsList)&&graphicsList.length>0){
  1104. that.viewer.camera.flyTo({
  1105. destination: Cesium.Cartesian3.fromDegrees(graphicsList[0],graphicsList[1],6500),
  1106. complete: function () {
  1107. // 飞行结束后设置相机的高度
  1108. var newHeight = 6500;
  1109. var destination = that.viewer.camera.position.clone();
  1110. destination.z = newHeight;
  1111. }
  1112. });
  1113. }
  1114. }, 3000);
  1115. }
  1116. },
  1117. }
  1118. </script>
  1119. <style rel="stylesheet/scss" lang="scss" scoped>
  1120. .map-tit {
  1121. position: absolute;
  1122. top: 90px;
  1123. left: 50%;
  1124. transform: translatex(-50%);
  1125. border: 1px solid #15519b;
  1126. z-index: 9999;
  1127. background: linear-gradient(rgba(4, 23, 62, 0.6), rgba(0, 28, 70, 0.6));
  1128. min-width: 300px;
  1129. .top-tit {
  1130. width: 100%;
  1131. height: 28px;
  1132. line-height: 28px;
  1133. display: flex;
  1134. flex-direction: row;
  1135. justify-content: space-between;
  1136. background: #15519b80;
  1137. padding: 0px 10px;
  1138. align-items: center;
  1139. i {
  1140. color: #10ccff;
  1141. font-size: 18px;
  1142. text-shadow: 0px 0px 5px #23b3b3;;
  1143. }
  1144. span img {
  1145. display: block;
  1146. width: 12px;
  1147. height: 12px;
  1148. color: #fff;
  1149. cursor: pointer;
  1150. }
  1151. }
  1152. .map-txt {
  1153. padding: 10px 15px;
  1154. color: #fff;
  1155. line-height: 20px;
  1156. font-size: 12px;
  1157. .d-l-con {
  1158. }
  1159. }
  1160. }
  1161. .fade-enter-active,
  1162. .fade-leave-active {
  1163. transition: 1s;
  1164. }
  1165. .fade-enter,
  1166. .fade-leave-to {
  1167. opacity: 0;
  1168. transform: translateY(-10rem);
  1169. }
  1170. </style>