亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術(shù)文章
文章詳情頁

vue-openlayers實現(xiàn)地圖坐標彈框效果

瀏覽:82日期:2022-11-18 10:16:30

本文實例為大家分享了vue-openlayers實現(xiàn)地圖坐標彈框的具體代碼,供大家參考,具體內(nèi)容如下

openlayers

這個效果是點擊地圖,彈出坐標信息。

vue-openlayers實現(xiàn)地圖坐標彈框效果

點擊地圖邊緣時,底圖會跟著移動,使彈窗能完整顯示出來。

<template> <div class='vm'> <h2 class='h-title'>彈窗 popup</h2> <div class='map-x'></div> <!-- 彈窗元素 --> <div ref='popup' v-show='currentCoordinate' > <span @click='closePopup'>✖</span> <div class='content'>{{currentCoordinate}}</div> </div> </div></template> <script>import ’ol/ol.css’import { Map, View } from ’ol’import Tile from ’ol/layer/Tile’import OSM from ’ol/source/OSM’import { toStringHDMS } from ’ol/coordinate’import { toLonLat } from ’ol/proj’import Overlay from ’ol/Overlay’ export default { name: ’Popup’, data () { return { map: null, currentCoordinate: null, // 彈窗坐標數(shù)據(jù) overlay: null } }, methods: { initMap () { // 彈窗 this.overlay = new Overlay({ element: this.$refs.popup, // 彈窗標簽,在html里 autoPan: true, // 如果彈窗在底圖邊緣時,底圖會移動 autoPanAnimation: { // 底圖移動動畫 duration: 250 } }) // 實例化地圖 this.map = new Map({ target: ’map’, layers: [ new Tile({ source: new OSM() // 使用OSM底圖 }) ], overlays: [this.overlay], // 把彈窗加入地圖 view: new View({ center: [-27118403.38733027, 4852488.79124965], // 北京坐標 zoom: 12 // 地圖縮放級別(打開頁面時默認級別) }) }) this.mapClick() // 初始化地圖成功后,給地圖添加點擊事件 }, mapClick () { // 地圖點擊事件 // 通過 map.on() 監(jiān)聽,singleclick 是單擊的意思。也可以用 click 代替 singleclick。 this.map.on(’singleclick’, evt => { const coordinate = evt.coordinate // 獲取坐標 const hdms = toStringHDMS(toLonLat(coordinate)) // 轉(zhuǎn)換坐標格式this.currentCoordinate = hdms // 保存坐標點 setTimeout(() => { // 設(shè)置彈窗位置 // 這里要設(shè)置定時器,不然彈窗首次出現(xiàn),底圖會跑偏 this.overlay.setPosition(coordinate) }, 0)}) }, // 關(guān)閉彈窗 closePopup () { // 把彈窗位置設(shè)置為undefined,并清空坐標數(shù)據(jù) this.overlay.setPosition(undefined) this.currentCoordinate = null } }, mounted () { this.initMap() }}</script> <style lang='scss' scoped> /* 彈窗樣式 */ .popup { min-width: 280px; position: relative; background: #fff; padding: 8px 16px; display: flex; flex-direction: column; transform: translate(-50%, calc(-100% - 12px)); /* 彈窗下方的小三角形 */ &::after { display: block; content: ’’; width: 0; height: 0; position: absolute; border: 12px solid transparent; border-top-color: #fff; bottom: -23px; left: 50%; transform: translateX(-50%); } } /* 關(guān)閉彈窗按鈕 */ .icon-close { cursor: pointer; align-self: flex-end; margin-bottom: 10px; }</style>

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標簽: Vue
相關(guān)文章:
主站蜘蛛池模板: 伊人这里只有精品 | 99成人在线| 免费网站看av片 | 欧美激情一区二区三区蜜桃视频 | 被黑人做的白浆直流在线播放 | 九九热精品在线观看 | 国产精品国内免费一区二区三区 | 日本高清在线不卡 | 久久中文字幕一区二区三区 | 一级毛片免费视频日本 | 初女破苞国语在线观看免费 | 亚洲国产精 | 亚洲欧美h| 亚洲成人影院在线 | 一级大片黄色 | 男女免费爽爽爽在线视频 | 亚洲激情视频网 | 免费观看在线永久免费xx视频 | 一级特黄录像视频免费 | a毛片在线观看 | 中文国产成人精品久久96 | 国产免费叼嘿视频 | 国产一区在线看 | 欧美特黄视频在线观看 | 免费观看黄色一级视频 | 国产盗摄福利视频 | 日韩精品欧美视频 | 高清在线观看自拍视频 | 国拍在线精品视频免费观看 | 天天躁日日躁狠狠躁中文字幕老牛 | 国产精品亚洲欧美云霸高清 | 日韩不卡| 日本三级黄网站 | 亚洲区欧美中文字幕久久 | 在线免费一区二区 | 永久免费的啪啪免费的网址 | 亚洲精品久久久久中文字小说 | 亚洲国产精品看片在线观看 | 91成人午夜在线精品 | 中文字幕有码热在线视频 | 国产日韩欧美综合 |