OpenLayers 实现画点、画线、画面、画圆

本文将实现如何用openlayers在地图上画点、线、面、圆,创建地图可参考我的上一篇文章Vue+OpenLayers 创建地图并显示鼠标所在经纬度

1、页面

在这里插入图片描述

2、代码

                  <div class="fense_card_top_flex">
          <button @click="selectDraw('Point')"></button>
          <button @click="selectDraw('LineString')">线</button>
                   <button @click="selectDraw('Polygon')">多边形</button>
                 <button @click="selectDraw('Circle')"></button>                
        </div>
  import VectorSource from "ol/source/Vector";
import VectorLayer from "ol/layer/Vector";
import {  Draw } from "ol/interaction";

     selectDraw(value) {
        //取消上一次的绘制动作,避免重叠
        this.draw ? this.map.removeInteraction(this.draw) : '';

        var source = new VectorSource();
        //定义vector图层,将绘制的图形加入到vector图层,叠加在地图上展示
        var vector = new VectorLayer({
          source: source
        });

        if (value === 'Polygon') {

          this.draw = new Draw({
            source: source,
            type: value,
            geometryFunction: Draw.createBox
          });
        } else {
          this.draw = new Draw({
            source: source,
            type: value
          });
        }
        // 将交互动作添加到地图上
        this.map.addInteraction(this.draw);
        this.map.addLayer(vector);


      },
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值