vue 使用vue-amp给地图添加点标注,鼠标移入移出显示和隐藏对应的弹框

1.安装

npm install vue-amap --save

2.在main.js文件中引入

import VueAMap from 'vue-amap';
Vue.use(VueAMap);
VueAMap.initAMapApiLoader({
  key: '40804db8586c2c1e8fa23b7541a6ebe2',
  plugin: ['AMap.Geolocation','Geolocation','AMap.DistrictSearch'],//按需引入
  // 默认高德 sdk 版本为 1.4.4
  v: '1.4.4'
});

3.调用

 data中:

method中

加载点标注

getMarkers() {
                const markers = []
                const windows = []
                const that = this
                this.dataList.forEach((item, index) => {
                    markers.push({
                        position: item.position,
                        icon: require('../../../../assets/noneMap/water.png'),
                        events: {
                            mouseover() {//移入
                                // 方法:鼠标移动到点标记上,显示相应窗体
                                that.windows.forEach(window => {
                                    window.visible = false // 关闭窗体
                                })
                                that.window = that.windows[index]
                                that.$nextTick(() => {
                                    that.window.visible = true
                                })
                            },
                            mouseout(){//移出
                                that.windows.forEach(window => {
                                    window.visible = false // 关闭窗体
                                })
                                that.window = that.windows[index]
                                that.$nextTick(() => {
                                    that.window.visible = false
                                })
                            }
                        }
                    })
                    windows.push({
                        position: item.position,
                        isCustom: true,
                        offset: [0, -30], // 窗体偏移
                        showShadow: false,
                        visible: false, // 初始是否显示
                        name:item.name,
                        type:item.type,
                        model:item.model,
                        status:item.status
                    })

                })
                //  加点
                this.markers = markers
                // 加弹窗
                this.windows = windows
            },

 绘制行政区js:

drawBounds() {
                var that = this;
                //加载行政区划插件
                if (!that.district) {
                    //实例化DistrictSearch
                    var opts = {
                        subdistrict: 0, //获取边界不需要返回下级行政区
                        extensions: "all", //返回行政区边界坐标组等具体信息
                        level: "district", //查询行政级别为 区  市为city
                    };
                    that.district = new AMap.DistrictSearch(opts);
                }
                //循环各个市的行政区查询 *********关键性代码
                for (let i = 0; i < this.polygonss.length; i++) {
                    that.district.search(this.citys[i], function(status, result) {
                        that.polygonss[i] = [];
                        var bounds = result.districtList[0].boundaries;
                        if (bounds) {
                            for (var i = 0, l = bounds.length; i < l; i++) {
                                var polygon = new AMap.Polygon({
                                    path: bounds[i],
                                });
                                that.polygonss[i].push(polygon);
                            }
                        }
                        AMap.Polygon.bind(that.polygonss[i]);
                    });
                }


            },

最终效果图:

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值