MapBox测量组件

贴个群号

WebGIS学习交流群461555818,欢迎大家。

源码

这里用到一个插件 mapbox-measure,需要首先安装一下,npm i maobox-measure
只需要传入map实例,注意不能立即监听,因为第一次传入map实例的时候一般是空的,map还没有load好,这样立即监听就会第二次找不到map容器。

<template>
    <div class="print-tools tool-item">
      <!-- <i class="iconfont iconmeasure"  @click="showMeasureSub"></i> -->
      <div class="measure-result-sub sub" ref="measure"></div>
    </div>
  </template>
  
  <script>
  import Measure from 'mapbox-measure'
  const measure = new Measure()
  
  export default {
    name: 'Measure',
    data () {
      return {
        measure: null,
        map:null
      }
    },
    props:['mapLoad'],
    watch: {
        mapLoad:{
            handler:function(newVal){
                this.map=newVal,
                // this.initMeasure()
                setTimeout(() => {
                    if (!this.measure) {
                    this.initMeasure()
                    }
                }, 1000)
            },
            // immediate:true
        }
    },
    // computed: {
    //   map () {
    //     return this.$store.state.map.map
    //   }
    // },
    // mounted () {
    //   setTimeout(() => {
    //     if (!this.measure) {
    //       this.initMeasure()
    //     }
    //   }, 1000)
    // },
    methods: {
      initMeasure () {
        this.$refs.measure.appendChild(measure.onAdd(this.map))
        this.measure = measure
      }
    }
  }
  </script>
  
  <style lang="less" scoped>
  .tool-item {
  width: 28px;
  height: 28px;
  border-radius: 4px;
  // background-color: #ffffff;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;

  > i {
    font-size: 20px;
  }

  .sub {
    position: absolute;
    top: 0;
    left: 0;
    transform: translateX(-110%);

    :deep(.mapboxgl-ctrl-group){
      display: flex;

      .mapbox-gl-draw_ctrl-draw-btn {
        border-top: none!important;
      }
    }
  }
}
  </style>
  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值