viewerlabel.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. <script setup>
  2. import {
  3. inject
  4. } from "vue";
  5. import html2canvas from 'html2canvas';
  6. import {Store} from '@/store/index';
  7. store = Store()
  8. import {
  9. blobToBase64,
  10. base64ToBlob
  11. } from '@/assets/js/blobtobase64';
  12. const getMapInstance = inject("getMapInstance");
  13. jt3d = getMapInstance();
  14. </script>
  15. <template>
  16. <div class="mainview">
  17. <div class="header">
  18. <input @input="getName()" id="inputValue" type="text" placeholder="创建视角标签" />
  19. <el-button v-if="store.userport=='PC'" type="primary" @click="addviewer" size="small">添加</el-button>
  20. <el-button type="primary" @click="searchviewer" size="small">查询</el-button>
  21. </div>
  22. <div class="middleviewer">
  23. <div class="viewer" v-for="(res,index) in ImgurlList" :key="index">
  24. <div class="viewertop">
  25. <img :src="res.url" @click="flyto(res.info)">
  26. </div>
  27. <div class="viewerbottom">
  28. {{res.name}}
  29. <img src="@/assets/images/delete.png" class="deleteImg" @click="deleteviewer(res,index)" />
  30. </div>
  31. </div>
  32. </div>
  33. </div>
  34. </template>
  35. <script>
  36. let store = undefined;
  37. let jt3d = undefined;
  38. export default {
  39. data() {
  40. return {
  41. viewersName: '', //视角标签名称
  42. ImgurlList: [], //截图地址列表
  43. }
  44. },
  45. methods: {
  46. //获取输入框值
  47. getName() {
  48. this.viewersName = document.getElementById("inputValue").value;
  49. },
  50. //跳转方法
  51. flyto(options) {
  52. jt3d.LocateUtil.flyToPoint(options)
  53. },
  54. //删除方法,传keyvalue以及需要修改属性
  55. deleteviewer(item, index) {
  56. //删除对应数组内的对象
  57. this.ImgurlList.splice(index, 1)
  58. if (item.id) {
  59. this.$http.get('/delete', {
  60. tableName: 'map_angle',
  61. keyValue: item.id,
  62. }).then(res => {
  63. console.log(res.data)
  64. })
  65. }
  66. },
  67. //添加视角标签,当前页存数组,向数据库传入相机参数
  68. addviewer() {
  69. //获取当前界面截图方法
  70. html2canvas(
  71. this.$parent.$parent.$refs.refMap3d.$refs.cesiumContainer, {
  72. // backgroundColor: null, //画出来的图片有白色的边框,不要可设置背景为透明色(null)
  73. useCORS: true, //支持图片跨域
  74. scale: 1 / 8, //设置放大的倍数
  75. }
  76. ).then(canvas => {
  77. //截图用img元素承装,显示在页面的上
  78. let url = canvas.toDataURL('image/png')
  79. //经纬度、高度
  80. // 获取 相机姿态信息
  81. let heading = window["viewer"].scene.camera.heading
  82. let pitch = window["viewer"].scene.camera.pitch
  83. let roll = window["viewer"].scene.camera.roll
  84. let position = window["viewer"].scene.camera.positionCartographic
  85. let longitude = Cesium.Math.toDegrees(position.longitude) //y
  86. let latitude = Cesium.Math.toDegrees(position.latitude) //x
  87. let height = position.height
  88. let info = {
  89. latitude: latitude,
  90. longitude: longitude,
  91. height: height,
  92. pitch: Cesium.Math.toDegrees(pitch),
  93. roll: Cesium.Math.toDegrees(roll),
  94. heading: Cesium.Math.toDegrees(heading)
  95. }
  96. //dom for循环渲染列表
  97. this.ImgurlList.unshift({
  98. url: url,
  99. name: this.viewersName,
  100. info: info
  101. })
  102. //base64转换为二进制文件
  103. // let blob = base64ToBlob(url)
  104. // //文件转为文件流
  105. // let formData = new FormData();
  106. // formData.append('file',blob)
  107. let data = {
  108. name: this.viewersName,
  109. x: latitude,
  110. y: longitude,
  111. z: height,
  112. pitch: Cesium.Math.toDegrees(pitch),
  113. roll: Cesium.Math.toDegrees(roll),
  114. heading: Cesium.Math.toDegrees(heading),
  115. screenshot: url,
  116. // screenshot: '',
  117. userId: this.id,
  118. // id:0
  119. }
  120. //添加数据接口
  121. this.$http.post('/postSubmit', {
  122. tableName: 'map_angle',
  123. keyValue: '',
  124. formData: data,
  125. }).then(res => {
  126. console.log(res)
  127. if (res.success == true) {
  128. console.log('添加成功')
  129. document.getElementById("inputValue").value = ''
  130. }
  131. })
  132. }).catch(err => {
  133. console.log(err)
  134. })
  135. },
  136. searchviewer() {
  137. this.info = JSON.parse(localStorage.getItem('person'))
  138. this.id = this.info.id
  139. //获取所有图片数据
  140. this.$http.get('/getTableList', {
  141. tableName: 'map_angle', //
  142. sqlWhere: "name like '%" + this.viewersName + "%'",
  143. orderByField: ''
  144. }).then(res => {
  145. console.log('获取图片', res.data)
  146. this.ImgurlList = [];
  147. res.data.forEach(item => {
  148. let info = {
  149. latitude: item.x,
  150. longitude: item.y,
  151. height: item.z,
  152. pitch: item.pitch,
  153. roll: item.roll,
  154. heading: item.heading
  155. }
  156. // let url = blobToBase64(item.screenshot)
  157. //dom for循环渲染列表
  158. this.ImgurlList.push({
  159. url: item.screenshot,
  160. name: item.name,
  161. info: info,
  162. id: item.id
  163. })
  164. })
  165. // console.log('img列表',this.ImgurlList)
  166. })
  167. }
  168. },
  169. mounted() {
  170. this.info = JSON.parse(localStorage.getItem('person'))
  171. this.id = this.info.id
  172. //获取所有图片数据
  173. this.$http.get('/getTableList', {
  174. tableName: 'map_angle', //
  175. sqlWhere: '', //+ this.loginForm.id
  176. orderByField: ''
  177. }).then(res => {
  178. console.log('获取图片', res.data)
  179. if(res.data.length == 0) return
  180. res.data.forEach(item => {
  181. let info = {
  182. latitude: item.x,
  183. longitude: item.y,
  184. height: item.z,
  185. pitch: item.pitch,
  186. roll: item.roll,
  187. heading: item.heading
  188. }
  189. // let url = blobToBase64(item.screenshot)
  190. //dom for循环渲染列表
  191. this.ImgurlList.push({
  192. url: item.screenshot,
  193. name: item.name,
  194. info: info,
  195. id: item.id
  196. })
  197. })
  198. // console.log('img列表',this.ImgurlList)
  199. })
  200. }
  201. }
  202. </script>
  203. <style lang="scss" scoped>
  204. .el-button--small{
  205. --el-button-size:24rem;
  206. font-size:12rem;
  207. padding: 5rem 12rem;
  208. }
  209. .mainview {
  210. width: 100%;
  211. height: 100%;
  212. height: calc(calc(100% - 115rem) / 3 + 90rem);
  213. .header {
  214. width: 100%;
  215. display: flex;
  216. input,
  217. input:focus {
  218. outline: none;
  219. width: 185rem !important;
  220. border: 1rem solid rgba(255, 255, 255, 0.8);
  221. margin-right: 10rem;
  222. height: 26rem !important;
  223. color: rgba(255, 255, 255, 1);
  224. background-color: rgba(255, 255, 255, 0) !important;
  225. border-radius: 3rem;
  226. }
  227. }
  228. .middleviewer {
  229. width: 322rem;
  230. height: 100%;
  231. margin-left: 7rem;
  232. .viewer {
  233. width: 322rem !important;
  234. height: 240rem !important;
  235. margin-top: 15rem;
  236. border: 1rem solid #ffffff !important;
  237. border-radius: 1rem !important;
  238. .viewertop {
  239. width: 322rem !important;
  240. height: 210rem !important;
  241. img {
  242. width: 100% !important;
  243. height: 100% !important;
  244. }
  245. }
  246. .viewerbottom {
  247. line-height: 30rem !important;
  248. text-align: center !important;
  249. width: 322rem !important;
  250. height: 30rem !important;
  251. position: relative;
  252. background-color: rgba(15, 145, 185, 0.7);
  253. .deleteImg {
  254. width: 24rem;
  255. height: 24rem;
  256. right: 5rem;
  257. top: 3rem;
  258. position: absolute;
  259. }
  260. }
  261. }
  262. }
  263. }
  264. ::v-deep .el-input {
  265. flex-grow: 0 !important;
  266. width: 200rem !important;
  267. // display: inline !important;
  268. // margin-left: 5rem;
  269. margin-right: 10rem;
  270. height: 30rem !important;
  271. }
  272. //输入框文字颜色
  273. ::v-deep .el-input__inner {
  274. color: rgba(255, 255, 255, 1)
  275. }
  276. //输入框背景色
  277. ::v-deep .el-input__wrapper {
  278. background-color: rgba(255, 255, 255, 0) !important;
  279. }
  280. ::v-deep .el-button {
  281. border-radius: 3rem !important;
  282. }
  283. ::v-deep .el-button--primary {
  284. background-color: rgba(64, 158, 255, 0.6) !important;
  285. }
  286. ::-webkit-scrollbar {
  287. width: 0rem;
  288. }
  289. </style>