vue集成高德地图amap并实现点聚合、点坐标点击信息窗体

上代码:
HTML部分

<template>
	<Form ref="formInlineSearch" :label-width="0" :model="formInlineSearch" inline>
        <FormItem>
          <Button type="primary" @click="terSearch()">{{$t('com_search')}}</Button>
        </FormItem>
      </Form>
	<Row id="amap" style="width: 100%; height: 100%; margin-top: -40px;">
</template>

实现

methods: {
	request () {
	  this.selectTerminalPosition()
	},
	selectTerminalPosition () {
	  getTerminalPositionList(this.formInlineSearch).then(res => {
	    this.position_data = res.data
	    this.create()
	  }).catch(err => {
	    console.log(err)
	  })
	},
	create () {
	  let self = this
	  let markers = []
	  let num = Number(this.position_data.length)
	  let index = 0
	  let images = [
	    require('../../../assets/images/amap/mark_r.png'),
	    require('../../../assets/images/amap/mark_g.png'),
	    require('../../../assets/images/amap/mark_ru.png'),
	    require('../../../assets/images/amap/mark_gu.png')
	  ]
	  for (let i = 0; i < num; i++) {
	    index++
	    let img = ''
	    if (this.position_data[i].type === '0') {
	      img = images[0]
	    } else if (this.position_data[i].type === '1') {
	      img = images[1]
	    } else if (this.position_data[i].type === '2') {
	      img = images[2]
	    } else {
	      img = images[3]
	    }
	    let marker = new AMap.Marker({
	      position: [this.position_data[i].coordinate0, this.position_data[i].coordinate1],
	      icon: img
	    })
	    // 鼠标点击marker弹出自定义的信息窗体
	    AMap.event.addListener(marker, 'click', function () {
	      let position = marker.getPosition()
	      self.selectInfo(position.lng, position.lat, i)
	    })
	    markers.push(marker)
	    map.add(marker)
	  }
	  this.number = index
	  let cluster = new AMap.MarkerClusterer(map, markers, {
	    gridSize: 80,
	    maxZoom: 16
	  })
	},
	terSearch () {
	  // 地图销毁重新初始化
	  map.destroy()
	  // 初始化地图对象,加载地图
	  this.createAmap()
	  // 检索
	  this.request()
	},
	selectInfo (lng, lat, index) {
	  console.log('通过数据库获取了坐标点:[' + lng + ',' + lat + '] 的数据。。。')
	  this.formInlineSearch.deviceCoordinate = this.position_data[index].coordinate0 + ',' + this.position_data[index].coordinate1
	  let windows = []
	  getTerminalPositionDetailData(this.formInlineSearch).then(res => {
	    this.positionDetailData = res.data
	    let time = this.formatDate(new Date(this.positionDetailData.SignTime), 'yyyy-MM-dd hh:mm:ss')
	    let infoWindow = new AMap.InfoWindow({
	      position: [lng, lat],
	      content: `<div class="prompt">
	                <div>
	                  <span style="color: blue;">${this.positionDetailData.Name}</span>
	                  <span style="color: blue;">【${this.positionDetailData.CorpTerminalIdentifier}】</span>
	                  <span style="color: blue;">【${this.positionDetailData.TerminalIdentifier}】</span>
	                </div>
	                <hr/>
	                <div class="row_c">
	                  <span class="size">签到时间:</span>
	                  <span class="size">${time}</span>
	                </div>
	                <div class="row_c">
	                  <span class="size">点位地址:</span>
	                  <span class="size">${this.positionDetailData.locationAddress}</span>
	                </div>
	                <div class="row_c">
	                  <span class="size">定位位置:</span>
	                  <span class="size">${this.positionDetailData.CoordinateAddress}</span>
	                </div>
	                <div class="row_c">
	                  <hr/>
	                </div>
	                <div>
	                  <span class="size" style="color: blue;">今日销售额:</span>
	                  <span class="size" style="color: blue;">${this.positionDetailData.TotalMoney}元</span>
	                  <span class="size" style="margin-left:30px; color: blue;">今日销售量:</span>
	                  <span class="size" style="color: blue;">${this.positionDetailData.TotalCnt}笔</span>
	                </div>
	              </div>`,
	      visible: false
	    })
	    infoWindow.open(map)
	  }).catch(err => {
	    console.log(err)
	  })
	  return windows
	},
	// 初始化地图
	createAmap () {
	  map = new AMap.Map('amap', {
	    resizeEnable: true,
	    zoom: 10, // 设置地图显示的缩放级别
	    center: this.center, // 设置地图中心点坐标
	    viewMode: '2D', // 设置地图模式
	    // 地图模式
	    lang: 'zh_cn' // 设置地图语言类型
	  })
	  let scale = new AMap.Scale({ // 比例尺
	    visible: true
	  })
	  let toolBar = new AMap.ToolBar({// 工具条
	    visible: true
	  })
	  let overView = new AMap.OverView({ // 鹰眼
	    visible: true
	  })
	  map.addControl(scale)
	  map.addControl(toolBar)
	  map.addControl(overView)
	  // 浏览器精确定位
	  AMap.plugin('AMap.Geolocation', function () {
	    var geolocation = new AMap.Geolocation({
	      enableHighAccuracy: true, // 是否使用高精度定位,默认:true
	      timeout: 10000, // 超过10秒后停止定位,默认:无穷大
	      maximumAge: 0, // 定位结果缓存0毫秒,默认:0
	      convert: true, // 自动偏移坐标,偏移后的坐标为高德坐标,默认:true
	      showButton: true, // 显示定位按钮,默认:true
	      buttonPosition: 'RB', // 定位按钮停靠位置,默认:'LB',左下角
	      buttonOffset: new AMap.Pixel(10, 20), // 定位按钮与设置的停靠位置的偏移量,默认:Pixel(10, 20)
	      showMarker: true, // 定位成功后在定位到的位置显示点标记,默认:true
	      showCircle: true, // 定位成功后用圆圈表示定位精度范围,默认:true
	      panToLocation: true, // 定位成功后将定位到的位置作为地图中心点,默认:true
	      zoomToAccuracy: false // 定位成功后调整地图视野范围使定位位置及精度范围视野内可见,默认:false
	    })
	    map.addControl(geolocation)
	    geolocation.getCurrentPosition(function (status, result) {
	      let position = result.position
	      if (status === 'complete') {
	        console.log('谷歌地图定位成功:定位结果 = %o', [position.lng, position.lat])
	      } else {
	        console.log('谷歌地图定位失败')
	      }
	    })
	  })
	}
},
mounted () {
	this.request()
	// 初始化地图对象,加载地图
	this.createAmap()
},
watch: {
 lngLat: {
   handler (newV, oldV) {
     if (newV !== []) {
       this.center = [newV[0], newV[1]]
       map.setCenter(this.center)
       map.setZoom(10)
     }
   }
 }
}
  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
实现vue集成高德地图实现考勤打卡,首先需要在vue项目中引入高德地图API。接下来,我们可以使用高德地图的地图组件来展示地图,并将地图与用户信息进行关联。 首先,我们需要在项目中安装高德地图的JavaScript API,并在项目中引入相关的库文件。 在vue的组件中,我们可以通过创建地图容器元素来展示地图,然后使用高德地图Map类来初始化地图。可以设置地图的中心、缩放级别、控件等属性。 为了实现考勤打卡功能,我们需要在地图上添加打卡。可以使用标记(Marker)来表示打卡,并给每个打卡添加点击事件。 当用户点击地图上的打卡时,可以弹出打卡窗口,显示用户的相关信息,例如姓名、工号等。可以通过自定义窗体(InfoWindow)来实现。 另外,为了保证用户只能在指定的区域进行打卡,可以使用高德地图的多边形(Polygon)工具来标记可打卡区域。在每次打卡时,可以使用高德地图位检索(PlaceSearch)功能来判断用户当前位置是否在可打卡区域内。 当用户点击打卡按钮时,可以触发相关的逻辑代码,例如获取用户位置信息、判断用户位置是否在可打卡区域内等。根据打卡结果,可以将相关信息保存到数据库中,并给用户显示打卡成功或失败的提示。 总结起来,通过vue集成高德地图实现考勤打卡,我们可以使用高德地图的API来展示地图、添加打卡、设置打卡区域等功能。通过与用户信息和数据库的交互,可以实现考勤打卡的功能需求。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值