mapbox 實現draw 點擊事件的更改

直接上圖,相從右側換到左側的點擊事件上面

 原始的添加一個點的方式是這樣的,剛開始通過更改他的css發現不能實現,

//添加工具
    draw = new MapboxDraw({
      displayControlsDefault: false,
      controls: {
        point: true
        // line_string: true,
        // polygon: true,
        // trash: true
      }
    });
    window.Draw = draw;
    map.addControl(draw, "top-right");
    // map.addControl(new mapboxgl.NavigationControl(), "bottom-right");
    map.on("draw.create", this.newArea);
    map.on("draw.delete", this.delArea);
    map.on("draw.update", this.updateArea);

mapbox網站https://github.com/mapbox/mapbox-gl-draw/blob/master/docs/API.md

//添加工具
    draw = new MapboxDraw({
      displayControlsDefault: false,
      controls: {
        //將這個地方註釋掉
        // point: true
        // line_string: true,
        // polygon: true,
        // trash: true
      }
    });
    window.Draw = draw;
    map.addControl(draw, "top-right");

在點擊事件上面加一句話

 startDraw(){
      draw.changeMode('draw_point')
    },

效果就是醬紫的

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章