av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁技術文章
文章詳情頁

vue-openlayers實現地圖坐標彈框效果

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

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

openlayers

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

vue-openlayers實現地圖坐標彈框效果

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

<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, // 彈窗坐標數據 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() 監聽,singleclick 是單擊的意思。也可以用 click 代替 singleclick。 this.map.on(’singleclick’, evt => { const coordinate = evt.coordinate // 獲取坐標 const hdms = toStringHDMS(toLonLat(coordinate)) // 轉換坐標格式this.currentCoordinate = hdms // 保存坐標點 setTimeout(() => { // 設置彈窗位置 // 這里要設置定時器,不然彈窗首次出現,底圖會跑偏 this.overlay.setPosition(coordinate) }, 0)}) }, // 關閉彈窗 closePopup () { // 把彈窗位置設置為undefined,并清空坐標數據 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%); } } /* 關閉彈窗按鈕 */ .icon-close { cursor: pointer; align-self: flex-end; margin-bottom: 10px; }</style>

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

標簽: Vue
相關文章:
主站蜘蛛池模板: 国产丝袜一区二区三区免费视频 | 国产视频一区二区在线观看 | 浴室洗澡偷拍一区二区 | 国产一区二区毛片 | 国产欧美久久精品 | 久久99精品久久久久 | 91久久北条麻妃一区二区三区 | 奇米超碰 | 亚洲国产精品人人爽夜夜爽 | 欧美电影一区 | 久久久精品网站 | 国产在线精品一区二区三区 | 国产毛片久久久久久久久春天 | 中文字幕视频在线看 | 亚洲精品www久久久久久广东 | 久久国产综合 | 国产精品视频一区二区三区, | 欧美高清视频一区 | 亚洲热在线视频 | 亚洲精品国产电影 | 福利片在线 | 亚洲国产免费 | 久久久久久久综合 | 91精品成人久久 | av天天澡天天爽天天av | 欧美精品一区在线发布 | 国产97色| 男人的天堂在线视频 | 欧美一级欧美一级在线播放 | 亚洲精品久久嫩草网站秘色 | 国产精品久久精品 | 日韩精品一区二区三区中文字幕 | 国产欧美在线播放 | 国产欧美一区二区三区在线看蜜臀 | 日韩精品一区二 | 精品久久久久久久久久 | 久久久久国产一区二区三区四区 | 在线观看免费毛片 | 麻豆视频国产在线观看 | 久久久婷 | 亚洲精品一二区 |