leaflet怎么去掉放大缩小按钮,去掉测量,绘制框

本文介绍了一种地图操作的封装方法,包括放大缩小控制、绘图功能的初始化等。通过将常用的地图操作封装成方法,如addZoomCtrl和initDraw,可以简化地图应用的开发流程,提高代码复用性和维护性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. 在封装的地方,init下边不放上这些属性

2.把这些封装成方法

    


  addZoomCtrl() {
    //放大缩小按钮
    L.control
      .zoom({
        zoomInTitle: "放大",
        zoomOutTitle: "缩小",
        position: "bottomright"
      })
      .addTo(this._map);
  }


  initDraw() {
    // 初始化DrawControl
    //绘制框,编辑和删除
    this.drawControl = new L.Control.Draw({
      draw: {
        polygon: true,
        marker: false,
        circle: false,
        polyline: false,
        rectangle: true,
        circlemarker: false
      },
      edit: {
        featureGroup: this._drawnFeauresLayer,
        edit: true
      },
      delete: {
        removeAllLayers: false
      },
      position: "bottomright"
    });



    this._map.addControl(this.drawControl);
    this._map.addLayer(this._drawnFeauresLayer);

    // 开始绘制监听事件,清除上一次绘制的图形
    this._map.on("draw:drawstart", e => {
      this._drawnFeauresLayer.clearLayers();
      this.setQueryBounds(null);
    });

    // 创建查询矩形
    this._map.on("draw:created", e => {
      const type = e.layerType,
        layer = e.layer;
      this._drawnFeauresLayer.addLayer(layer);
      console.log(layer.getBounds());
      const bounds = layer.getBounds(),
        south = bounds.getSouth().toFixed(4),
        east = bounds.getEast().toFixed(4),
        west = bounds.getWest().toFixed(4),
        north = bounds.getNorth().toFixed(4);
      this.setQueryBounds({ east, west, south, north });
    });

    this._map.on("draw:edited", e => {
      console.log("draw:edited");
    });
  }

3. 这样再使用的时候,调用这个封装的 方法然后放上就可以了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

wu_223

嘿嘿,求打赏

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值