vue百度地圖實現(xiàn)自定義彈框樣式
更新時間:2024年03月19日 10:07:52 作者:sunfan0
這篇文章主要介紹了vue百度地圖實現(xiàn)自定義彈框樣式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
引入百度地圖
在index.html文件中引入百度地圖 申請百度密鑰
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=密鑰"></script> <script type="text/javascript" src="http://api.map.baidu.com/library/InfoBox/1.2/src/InfoBox_min.js" ></script>
在webpack.base.conf.js文件內(nèi)添加 externals 選項
無需再用import引入
module.exports = { context: path.resolve(__dirname, '../'), entry: { app: './src/main.js' }, externals: { 'BMap': 'BMap', 'BMapLib': 'BMapLib' }, output: {} }
地圖開發(fā)代碼參考
<template> <!--地圖容器--> <div id="map_box"></div> </template> <script> export default { name:'', data () { return { map: null, infoBox: null, } }, mounted(){ this.showMap() //動態(tài)添加的dom 調(diào)用vue事件 let _this = this window.imageClick= function() { _this.vueImageClick() } }, methods: { /** * 地圖展示 */ showMap() { this.map = new BMap.Map('map_box')//對應(yīng)地圖容器id let centerPoint = new BMap.Point(113.302114, 22.452695) this.map.centerAndZoom(centerPoint, 15) this.map.enableScrollWheelZoom(true) this.map.enableDoubleClickZoom(true) /* //地圖樣式 this.map.setMapStyle({ styleJson: [] })*/ this.markerPoint() }, /** * 添加地圖marker */ markerPoint() { let _this = this this.map.clearOverlays() let iconImage = new BMap.Icon(require('../assets/icon/menuIcon.png'), new BMap.Size(24, 24)) let point = new BMap.Point(113.302114, 22.452695) let marker = new BMap.Marker(point, { icon: iconImage }) // 創(chuàng)建標(biāo)注 marker.addEventListener('click', () => { //關(guān)閉其他標(biāo)記點的彈框 if (_this.infoBox != null) { _this.infoBox.close() } _this.markerPointClick(113.302114, 22.452695) }) _this.map.addOverlay(marker) }, /** * 點擊marker彈出信息框 */ markerPointClick(lat, lng) { let _this = this let html = '<div class="infoBoxContent">\n' + '<p οnclick="imageClick()">按鈕</p>\n' + '</div>' let opts = { boxStyle: { width: '435px', height: '233px' // margin: '30px 0', }, closeIconMargin: '25px 5px 0 0', closeIconUrl: require('../assets/icon/close_btn.png'), enableAutoPan: true, align: INFOBOX_AT_TOP } this.infoBox = new BMapLib.InfoBox(this.map, html, opts) /*this.infoBox._getCloseIcon = function() { return '' }*/ let point = new BMap.Point(lat, lng) let marker = new BMap.Marker(point) this.infoBox.open(marker) }, vueImageClick(){ console.log('彈框中按鈕的點擊事件') } } } </script> <style scoped> #map_box{ width: 100%; height: 650px; } </style> <style> /*自定義彈框樣式--需要寫在公共樣式中才起作用*/ .infoBoxContent{ width: 435px; height: 233px; background-color: cyan; } </style>
效果展示
上面代碼部分未貼動態(tài)加的節(jié)點與相關(guān)樣式,可以自行添加
總結(jié)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
vue3開啟攝像頭并進(jìn)行拍照的實現(xiàn)示例
本文主要介紹了vue3開啟攝像頭并進(jìn)行拍照的實現(xiàn)示例,主要是使用navigator.mediaDevices.getUserMedia這個API來實現(xiàn),具有一定的參考價值,感興趣的可以了解一下2024-01-01Vue純前端實現(xiàn)導(dǎo)出excel中的圖片與文件超鏈接
這篇文章主要為大家詳細(xì)介紹了Vue如何純前端實現(xiàn)導(dǎo)出excel中的圖片與文件超鏈接,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以參考一下2025-03-03詳解element-ui表格的合并行和列(非常細(xì)節(jié))
最近在需求中遇到了elementUI合并行,索性給大家整理下,這篇文章主要給大家介紹了關(guān)于element-ui表格的合并行和列的相關(guān)資料,文中通過實例代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-06-06