天地图使用定位,点击,标点,飞行,画线,清除画线,标点vue

6 篇文章 0 订阅
1 篇文章 0 订阅

初始化

init() {
            this.map = new window.T.Map('mapDiv', {
                projection: 'EPSG:4326'
            })
            this.map.centerAndZoom(new window.T.LngLat(106.59588, 29.57764), this.zoom)
            // 注册点击事件
            this.map.addEventListener('click', this.mapClick)
            // 地理编码
            this.geocode = new window.T.Geocoder()
            // 输入提示
            var config = {
                pageCapacity: 10, // 每页显示的数量
                onSearchComplete: this.localSearchResult // 接收数据的回调函数
            }
            // 创建搜索对象
            this.localsearch = new window.T.LocalSearch(this.map, config)
            this.iptchange()
        },

点击获取经纬度并查询地址

mapClick(e) {
		//e.lnglat.getLng(), e.lnglat.getLat() 经纬度
      this.address.lngLats = [e.lnglat.getLng(), e.lnglat.getLat()]
      this.geocode.getLocation(new window.T.LngLat(e.lnglat.getLng(), e.lnglat.getLat()), (result) => {
      		//地址
          this.address= result.formatted_address
      })
      //标点事件
      this.addMarker(e.lnglat.getLng(), e.lnglat.getLat())
  },

标点

// 标点
addMarker(getLng, getLat) {
    if (this.marker) {
        this.map.removeOverLay(this.marker)
    }
    var icon = new window.T.Icon({
        iconUrl: bd,
        iconSize: new window.T.Point(30, 30),
        iconAnchor: new window.T.Point(10, 56)
    })
    var point = new window.T.LngLat(getLng, getLat, {
        icon: icon
    })
    this.marker = new window.T.Marker(point) // 创建标注
    this.map.addOverLay(this.marker) // 将标注添加到地图中
},

画线

// 画线
   Polyline() {
   		//清除画线
       if (this.line) {
           this.map.removeOverLay(this.line)
       }
       var points = []
       this.address.lngLats.forEach(item => {
           points.push(new window.T.LngLat(item[0], item[1]))
       })
       this.line = new window.T.Polyline(points)
       this.map.addOverLay(this.line)
   },

跳转到经纬度所在位置

this.map.panTo(new window.T.LngLat(lg[0] * 1, lg[1] * 1), 15)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值