vue谷歌地图聚合功能

五申请秘钥在 入口文件里面引入 写入key值
<script src="http://maps.google.cn/maps/api/js?key="></script>

写入一个存放地图的div标签
<div id="googleMap" style="height: 100%;"></div>
五在vue模板里面引入自定义的聚合图标并且挂在在vue实例是哪个
  import mar0 from "./img/img/0.png";
  import mar1 from "./img/img/1.png";
  import mar2 from "./img/img/2.png";
  import mar3 from "./img/img/3.png";
  import mar4 from "./img/img/4.png";
  export default {
    data() {
      return {
        map:null,
        infowindow:null,
        clickTimer: null,
        imgUrl22 :require("../../../../static/img/marker-1.png"),
        imgUrl11 :require("../../../../static/img/marker0.png"),
        markerStyles:[
          {
            url:mar0,
            width:53,
            height:53,
          },
          {
            url:mar1,
            width:56,
            height:56,
          },
          {
            url:mar2,
            width:66,
            height:66,
          },
          {
            url:mar3,
            width:78,
            height:78,
          },
          {
            url:mar4,
            width:90,
            height:90,
          },
        ],
        markerCluster:null
      };
    },

初始化地图
   mounted() {
      this.mapBuild(); //初始化实例之后调用
      this.setPoint(this.pointsguge); //地图数据
    },
    methods: {
      mapBuild() {
        let mapProp = {
          center:new google.maps.LatLng(39.839472,116.288262),
          zoom:7,//缩放级数
          mapTypeId:google.maps.MapTypeId.ROADMAP
        };
        this.map = new google.maps.Map(document.getElementById("googleMap"),mapProp);
        //自定义的聚合图标
        this.markerCluster = new MarkerClusterer(this.map, [],{imagePath:this.markerStyles});
      },
      removePoints(){//清楚坐标点
        this.markerCluster.clearMarkers()
      },
      setPoint(pointsguge){
         console.error(pointsguge)
        this.removePoints();
        this.latlngbounds = new google.maps.LatLngBounds();
        let markers =[];
        let marker;
        let position;
        for(let node of pointsguge){
          position = new google.maps.LatLng(node.lat, node.lon);
          let icon = node.noticeLevel == '-1'  ? this.imgUrl22 : this.imgUrl11;
          marker =new google.maps.Marker({
            position: position,
            icon: icon
          });
          this.latlngbounds.extend(position);
          markers.push(marker)
          this.clickInfo(marker,node,this)
        }
        this.markerCluster.addMarkers(markers,false)
        if(!this.latlngbounds.isEmpty()){
          this.map.setCenter( this.latlngbounds.getCenter());
        }
       // this.map.fitBounds( this.latlngbounds);
      },
      clickInfo(marker,node,that){
        google.maps.event.addListener(marker, 'click', function() {
         //单击事件
        });
        google.maps.event.addListener(marker, 'dblclick', function() {
         //双击事件
        });
      },
  
    },
五级标题
五级标题
五级标题
五级标题
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值