center.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. <template>
  2. <div class="box">
  3. <div class="overbtn" v-if="value==1">
  4. <div class="arrowbtn act">
  5. <img src="@/assets/images/up.png" @click="oarrowClick('left')" />
  6. </div>
  7. <el-carousel ref="overcardShow" height="100%" direction='vertical' :autoplay='false' indicator-position='none' arrow="never">
  8. <el-carousel-item v-for="(cite,cidx) in annexList">
  9. <div class="arrowbox" v-for="(ite,idx) in cite" :key="idx">
  10. <div class="adrbox " :class="annexId==ite.id?'act':''" @click="getVrFn(ite.id)">
  11. <div class="tit">{{ite.tit}}</div>
  12. </div>
  13. </div>
  14. </el-carousel-item>
  15. </el-carousel>
  16. <div class="arrowbtn">
  17. <!-- v-if="pageLength !== currentPage + 1" -->
  18. <img src="@/assets/images/down.png" @click="oarrowClick('right')" />
  19. </div>
  20. </div>
  21. <div class="box-content">
  22. <div class="pr" v-show="value==1">
  23. <img src="@/assets/images/centbg.png" class="centbg"/>
  24. <div class="boxa">
  25. <img src="@/assets/images/jzicoa.png" class="cira"/>
  26. <img src="@/assets/images/jzicob.png" class="cirb"/>
  27. <div class="tit">财务室红外探测器</div>
  28. </div>
  29. <div class="boxb">
  30. <img src="@/assets/images/jziconf.png" class="cira"/>
  31. <img src="@/assets/images/jzicoc.png" class="cirb"/>
  32. <div class="tit">2号仓库半球摄像头</div>
  33. </div>
  34. <div class="boxc">
  35. <img src="@/assets/images/jzicoe.png" class="cira"/>
  36. <div class="line"></div>
  37. <div class="cirbox">
  38. <div class="tit">2号仓库半球摄像头</div>
  39. <img src="@/assets/images/jzicod.png" class="cirb"/>
  40. </div>
  41. <div class="cirbox cirboxa">
  42. <div class="tit">2号仓库半球摄像头</div>
  43. <img src="@/assets/images/jzicod.png" class="cirb"/>
  44. </div>
  45. </div>
  46. </div>
  47. <!-- 地图 -->
  48. <div v-show="value==2">
  49. <div id="container" style="width: 711px;height: 421px">
  50. </div>
  51. </div>
  52. <!-- <slot/> -->
  53. </div>
  54. <!-- 右侧选择 -->
  55. <div class="chosebtn">
  56. <el-select v-model="value" placeholder="请选择">
  57. <el-option
  58. v-for="item in mapoptiops"
  59. :key="item.value"
  60. :label="item.label"
  61. :value="item.value">
  62. </el-option>
  63. </el-select>
  64. </div>
  65. </div>
  66. </template>
  67. <script>
  68. //引入缺德地图
  69. import AMapLoader from '@amap/amap-jsapi-loader'
  70. window._AMapSecurityConfig = {
  71. securityJsCode: '' //填写你的安全密钥
  72. }
  73. //web端:密钥b06df55c66884ce2c9a3f3281c2c5ca9
  74. //keyfba818d626f91cf5a13cd61943a7667e
  75. //web服务8de52b560193f01932ad997dba3e76c0
  76. export default {
  77. props: {
  78. annexList: {
  79. type: [],
  80. default: []
  81. },
  82. mapoptiops:{
  83. type: [],
  84. default: []
  85. }
  86. },
  87. data(){
  88. return{
  89. annexId:0,
  90. value: '1',
  91. map: null,
  92. mapfalg:true,
  93. //标记点的位置信息
  94. mapData: [
  95. {
  96. name: '水域告警',
  97. type:2,
  98. longitude: '117.211954',
  99. latitude: '31.839676',
  100. content:'SYS-463520',
  101. img:'https://n.sinaimg.cn/spider20220702/290/w1080h810/20220702/bdee-24bda60bf8b6cf30b658f25de78e12de.jpg'
  102. },
  103. {
  104. name: '正常位置',
  105. type:1,
  106. longitude: '117.210150',
  107. latitude: '31.839670',
  108. content:'好吃是好吃,吃完必上火,把子肉嘎嘎香',
  109. img:'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fsafe-img.xhscdn.com%2Fbw1%2F25fac10a-1e66-4a6d-a4a1-4bf07d2666a1%3FimageView2%2F2%2Fw%2F1080%2Fformat%2Fjpg&refer=http%3A%2F%2Fsafe-img.xhscdn.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1690684148&t=c2560eb44f5348fc210f74ccd4552555'
  110. }
  111. ],
  112. }
  113. },
  114. watch:{
  115. value(val){
  116. if(val==2&&this.mapfalg){
  117. //DOM初始化完成进行地图初始化
  118. this.initMap()
  119. this.mapfalg=false;
  120. }
  121. }
  122. },
  123. mounted() {
  124. },
  125. methods:{
  126. getVrFn(id){
  127. this.annexId=id
  128. },
  129. oarrowClick(val) {
  130. if(val === 'right') {
  131. this.$refs.overcardShow.next()
  132. } else {
  133. this.$refs.overcardShow.prev()
  134. }
  135. },
  136. initMap() {
  137. AMapLoader.reset()
  138. AMapLoader.load({
  139. key: "8de52b560193f01932ad997dba3e76c0", // 申请好的Web端开发者Key,首次调用 load 时必填
  140. version: "2.0", // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15
  141. plugins: ['AMap.AutoComplete', 'AMap.Marker', 'AMap.PlaceSearch', 'AMap.Geolocation'], // 需要使用的的插件列表,如比例尺'AMap.Scale'等
  142. }).then((AMap) => {
  143. console.log(AMap)
  144. this.map = new AMap.Map("container", { //设置地图容器id
  145. mapStyle: 'amap://styles/darkblue', //设置地图的显示样式
  146. viewMode: "3D", //是否为3D地图模式
  147. zoom: 17.8, //初始化地图级别
  148. center: [117.211954, 31.839676], //初始化地图中心点位置
  149. pitch: 40, // 地图俯仰角度,有效范围 0 度- 83 度
  150. terrain: true, // 开启地形图
  151. buildingAnimation: true,//楼块出现是否带动画
  152. });
  153. // this.getCenter()
  154. this.markPoints()
  155. this.latitude()
  156. }).catch(e => {
  157. console.log(e);
  158. })
  159. },
  160. // 获取当前定位
  161. getCenter(){
  162. AMap.plugin('AMap.Geolocation', () => {
  163. const geolocation = new AMap.Geolocation({
  164. enableHighAccuracy: true, //是否使用高精度定位,默认:true
  165. // timeout: 10000, //超过10秒后停止定位,默认:无穷大
  166. buttonOffset: new AMap.Pixel(10, 20), //定位按钮与设置的停靠位置的偏移量,默认:Pixel(10, 20)
  167. zoomToAccuracy: true //定位成功后是否自动调整地图视野到定位点
  168. });
  169. this.map.addControl(geolocation);
  170. geolocation.getCurrentPosition((status, result) => {
  171. if (status === 'complete') {
  172. // 定位成功,显示当前位置信息
  173. const lnglat = result.position;
  174. console.log('当前位置:', lnglat);
  175. // 可以在这里将位置信息保存到Vue的data中,以便后续使用
  176. // this.currentPosition = lnglat;
  177. // 并在模板中展示
  178. } else {
  179. console.error('定位失败:', result.message);
  180. }
  181. });
  182. });
  183. },
  184. //遍历显示标记点
  185. markPoints() {
  186. const icon = new AMap.Icon({
  187. image: require('@/assets/images/gjicob.png'), // 确保路径正确,根据实际情况调整
  188. // size: new AMap.Size(58, 105), // 图标大小
  189. // imageSize: new AMap.Size(58, 105) // 图标实际大小,如果图片本身大小与此不符,可以调整此属性以适应图片大小
  190. });
  191. const icona = new AMap.Icon({
  192. image: require('@/assets/images/zcicob.png'), // 确保路径正确,根据实际情况调整
  193. // size: new AMap.Size(90, 129), // 图标大小
  194. // imageSize: new AMap.Size(90, 129) // 图标实际大小,如果图片本身大小与此不符,可以调整此属性以适应图片大小
  195. });
  196. this.mapData.forEach(item => {
  197. // 创建一个 Marker 实例:
  198. const marker = new AMap.Marker({
  199. position: new AMap.LngLat(item.longitude, item.latitude), // 经纬度对象,也可以是经纬度构成的一维数组[lng, lat]
  200. icon: item.type==1?icona:icon,
  201. offset: new AMap.Pixel(-25, -10),
  202. });
  203. // 将创建的点标记添加到已有的地图实例:
  204. this.map.add(marker);
  205. //给标记点添加事件
  206. marker.on('click', (e) => {
  207. this.setInfoWindows(e, item)
  208. })
  209. });
  210. },
  211. //显示的弹出框组件
  212. setInfoWindows(e, item) {
  213. // 信息窗体的内容
  214. let content = [
  215. // e.pos[0],e.pos[1],
  216. `<div class="fixbox" style='\'padding:0px' 0px = '' 4px; \'=''><h1>${item.name}</h1>`,
  217. `<div class="fixtit">设备id :${item.content}</div>`,
  218. `<div class="fixtit">告警内容:未成年入水</div>`,
  219. // "地址 : XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</div></div>",
  220. // `<img src=${item.img} alt="" style="width: 100px;height: 100px">`
  221. ];
  222. // 创建 infoWindow 实例
  223. let infoWindow = new AMap.InfoWindow({
  224. // content: content.join("<br>") //传入 dom 对象,或者 html 字符串
  225. content: content.join(" ") //传入 dom 对象,或者 html 字符串
  226. });
  227. // 打开信息窗体
  228. let dd = this.map.getCenter()
  229. // dd.pos = [e.pos[0], e.pos[1]]
  230. dd.lat = item.latitude
  231. dd.lng = item.longitude
  232. console.log(dd)
  233. if(item.type==2){
  234. infoWindow.open(this.map, dd);
  235. }
  236. },
  237. //点击获取经纬度
  238. latitude() {
  239. this.map.on('click', function (ev) {
  240. // console.log(ev)
  241. // 触发事件的对象
  242. let target = ev.target;
  243. // 触发事件的地理坐标,AMap.LngLat 类型
  244. let lnglat = ev.lnglat;
  245. // 触发事件的像素坐标,AMap.Pixel 类型
  246. let pixel = ev.pixel;
  247. // 触发事件类型
  248. let type = ev.type;
  249. console.log(target, lnglat, pixel, type)
  250. });
  251. },
  252. }
  253. };
  254. </script>
  255. <style>
  256. .fixbox{font-size: 14px;color: #FFFFFF;line-height: 18px;padding-top: 2px;}
  257. .fixbox h1{font-weight: bold;font-size: 16px;color: #FFBB37;font-style: italic;line-height: 36px;margin-bottom: 4px;}
  258. .fixtit{font-size: 14px;color: #FFFFFF;}
  259. </style>
  260. <style lang="scss" scoped>
  261. ::v-deep .amap-info-sharp{display: none;}
  262. .flexc{display: flex;align-items: center;}
  263. .box{position: relative;width: 100%;height: 100%;}
  264. .overbtn{width: 83px;height: 112px;display: flex;flex-direction: column;align-items: center;box-sizing: border-box;position: absolute;left:16px;top:20px;z-index: 3;background-color: rgba(27,130,183,0.12);;
  265. .arrowbtn{width:100%;height: 28px;display: flex;align-items: center;justify-content: center;
  266. &.act{background-color: rgba(27,130,183,0.22);}
  267. img{width: 12px;height: 6px;}
  268. }
  269. .arrowbox{display: flex;flex-direction: column;
  270. &:nth-of-type(2n){background-color: rgba(27,130,183,0.22);}
  271. }
  272. ::v-deep .el-carousel{flex:1;width:82px;}
  273. .adrbox{position: relative;width: 100%;height: 28px;line-height: 28px;
  274. &.act{
  275. .tit{color: #99F17A;}
  276. }
  277. .tit{font-size: 14px;font-weight: 500;text-align: center;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;
  278. color: #B9CCDF;box-sizing: border-box;padding: 0 10px;}
  279. }
  280. }
  281. .chosebtn{position: absolute;right: 19px;top: 19px;}
  282. .box-content{width: 100%;height: 100%;display: flex;align-items: center;justify-content: center;}
  283. .centbg{width: 628px;height: 349px;}
  284. // 弹窗
  285. ::v-deep .amap-info-content{width:200px;height: 112px;background: url('~@/assets/images/fixedbg.png') no-repeat;background-size: 100% 100%;}
  286. .pr{position: relative;}
  287. // 建筑
  288. .boxa{
  289. position: absolute;left: 46px;top: 146px;border-top: 1px dashed #FFBA00;
  290. border-left: 1px dashed #FFBA00;width: 178px;height: 40px;
  291. .cira{position: absolute;width: 24px;height: 24px;right: -12px;top: -12px;}
  292. .cirb{width: 52px;height: 53px;position: absolute;bottom: -30px;left: -26px;}
  293. .tit{background: rgba(255, 187, 55, 0.9);font-size: 12px;padding: 3px 10px;color: #FFFFFF;position: absolute;bottom: -46px;transform: translateX(-50%);}
  294. }
  295. .boxb{
  296. position: absolute;right: 35px;top: 107px;border-bottom: 1px dashed #06C4AC;
  297. border-right: 1px dashed #06C4AC;width: 87px;height: 24px;
  298. .cira{position: absolute;width: 8px;height: 8px;left: -4px;bottom: -4px;}
  299. .cirb{width: 53px;height: 53px;position: absolute;bottom: 9px;right: -26px;}
  300. .tit{background: rgba(15, 232, 153, 0.5);font-size: 12px;padding: 3px 10px;color: #FFFFFF;position: absolute;bottom: 58px;transform: translateX(50%);word-break: keep-all;right: 0;}
  301. }
  302. .boxc{
  303. position: absolute;left: 144px;bottom: 36px;border: 1px dashed #16D0FF;border-left: none;width: 15px;height: 51px;
  304. .line{width: 110px;height: 1px;position: absolute;left: 15px;bottom: 26px;border-bottom:1px dashed #16D0FF ;}
  305. .cira{position: absolute;width: 9px;height: 9px;right: -113px;bottom: 21px;z-index: 1;}
  306. .cirbox{
  307. position: absolute;top: -23px;right: 0px;display: flex;align-items: center;
  308. &.cirboxa{top: 23px;}
  309. .cirb{width: 47px;height: 47px;}
  310. .tit{background: rgba(50, 155, 235, 0.7);font-size: 12px;padding: 3px 10px;color: #FFFFFF;word-break: keep-all;}
  311. }
  312. }
  313. </style>