vue 百度地图自定义弹框样式

    <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文件内添加 externals 选项
    无需再用import引入
	module.exports = {
		context: path.resolve(__dirname, '../'),
		entry: {
		    app: './src/main.js'
		},
		externals: {
			'BMap': 'BMap',
			'BMapLib': 'BMapLib'
		},
		output: {}
	}
  • 地图开发代码参考
<template>
    <!--地图容器-->
    <div id="map_box"></div>
</template>
<script>
  export default {
    name:'',
    data () {
      return {
      	map: null,
      	infoBox: null,
      }
    },
    mounted(){
	    this.showMap()
	    
	    //动态添加的dom 调用vue事件
	    let _this = this
		window.imageClick= function() {
			_this.vueImageClick()
		}
    },
    methods: {
		/**
		* 地图展示
		*/
		showMap() {
			this.map = new BMap.Map('map_box')//对应地图容器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 })  // 创建标注
	        marker.addEventListener('click', () => {
	        	//关闭其他标记点的弹框
				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>
  • 效果展示
    上面代码部分未贴动态加的节点与相关样式,可以自行添加
    在这里插入图片描述
  • 1
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 9
    评论
自定义 ArcGIS API for JavaScript 中的 Vue 弹框样式,您需要使用自定义 CSS 样式表。以下是一个简单的例子: 1. 在您的 Vue 组件中,添加以下代码: ```html <template> <div> <div ref="popupContainer"></div> </div> </template> <script> import { loadModules } from 'esri-loader'; export default { name: 'MyMap', data() { return { view: null, popup: null } }, mounted() { this.initializeMap(); }, methods: { async initializeMap() { const [Map, MapView, Popup] = await loadModules(['esri/Map', 'esri/views/MapView', 'esri/widgets/Popup']); this.view = new MapView({ container: 'map', map: new Map({ basemap: 'streets-navigation-vector' }) }); this.popup = new Popup({ container: this.$refs.popupContainer, content: 'This is a test popup' }); this.view.popup = this.popup; } } } </script> <style> /* Customize the popup style here */ .esri-popup__main-container { border-radius: 10px; box-shadow: rgba(0, 0, 0, 0.3) 0px 2px 4px; background-color: #fff; color: #333; font-size: 14px; } </style> ``` 2. 在上面的代码中,我们使用了 `loadModules` 方法来加载 `esri/widgets/Popup` 模块,并在 `mounted` 钩子函数中初始化了弹框。我们在 `popup` 对象中设置了 `container` 属性为 `this.$refs.popupContainer`,这是一个空的 `div` 元素,用于容纳弹框内容。 3. 最后,在样式表中,我们可以使用 CSS 选择器来选择弹框的不同部分,并添加自定义样式。在这个例子中,我们选择了 `.esri-popup__main-container` 类,添加了一些样式,如圆角和阴影。 请注意,这只是一个简单的例子,您可以根据您的需求自定义更多样式

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值