使用百度地图绘点自定义弹窗

<template>
    <div>
        <div id="map_container" ref="container" class="map-container"></div>
        <input type="checkbox" v-model="zfcheck"> 政府
    </div>
</templat>
 
<script>
    const carIcon = require("xxx/xxx.png");
    import {    darkStyle  } from "./darkStyle.js"; //自定义模式
    export default {
        data() {
            return {
                map: null,
                xjcheck: zfcheck,
            }
        },
        watch: {
            zfcheck(newVal, oldVal) {
                if (newVal) {
                    this.map.clearOverlays(); //清除图层覆盖物
                    const local = new BMapGL.LocalSearch(this.map, {
                        renderOptions: { map: this.map, panel: "r-languageResult" },
                        onInfoHtmlSet: function(params, html) {
                            html.innerHTML =`<div style="font-size:30px;white-space:nowrap;font-weight: bold;">`+params.title+`</div>`+
              `<div style="font-size:30px;white-space:nowrap;">地址:`+params.address+`</div>`;
                        },
                        pageCapacity: 40
                    });
                    local.search("政府");
                } else {
                    this.map.clearOverlays(); //清除图层覆盖物
                }
            }
            //学校、医院等都可以使用这种方式自定义弹窗    
        },
        mounted() {
            this.init();
        },
        methods: {
            initMap() {
                // 地图初始化
                const center = [113.55934, 22.271431];
                this.map = new BMapGL.Map(this.$refs.container, {
                    restrictCenter: false,
                    maxZoom: 25,
                    minZoom: 8,
                    displayOptions: {
                        building: false,
                    },
                });
                this.map.setMapStyleV2({
                    styleJson: darkStyle
                    //参考链接https://lbsyun.baidu.com/custom/list.htm
                });
                this.map.centerAndZoom(new BMapGL.Point(center[0], center[1]), 21); //设置中心点坐标和地图级别
                this.map.enableScrollWheelZoom(true); //允许地图可被鼠标滚轮缩放
                this.map.enableKeyboard(); //启用键盘操作,默认禁用
                this.map.enableInertialDragging(); //启用地图惯性拖拽,默认禁用
                this.map.setDisplayOptions({
                    indoor: false
                });
 
                //监听地图缩放事件;
                this.map.addEventListener("zoomend", ()=> {   
                    this.map.setTilt(0); // 设置地图的倾斜角度
                    this.map.setHeading(0); //方向偏移
                });
            },
        }
    }
</script>
 
<style scoped>
::v-deep .BMap_bubble_content{
    width: 500px !important;
    color: #fff !important;
    top: -20px !important;
    line-height: 55px !important;
    font-size: 23px !important;
}

::v-deep .BMap_bubble_pop {
    background-color: #121b4d !important;
    border: 5px solid #408bde !important;
    width: 550px !important;
    text-align: center;
}
::v-deep .BMap_bubble_top {
    height: 31px !important;
}

::v-deep .BMap_bubble_title {
    display: hidden;
    color: #fff !important;
    width: 550px !important;
    line-height: 50px !important;
}

::v-deep .BMap_bubble_title p {
    display: none !important;
}

::v-deep .BMap_bubble_title p a {
    //详情 链接
    display: none !important;
}

::v-deep .BMap_bubble_pop &>img {
    display: none !important;
}
</style>

效果图:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值