leaflet 添加矩形,可放大縮小,可移動,可旋轉(transform)

效果如下圖所示:

 

代碼如下圖所示 

var rectangle = new L.Rectangle(L.latLngBounds(this.polygonPosition), {
      weight: 2,
      draggable: true,
      transform: true,
      fillColor: "transport",
      fillOpacity: 0
    }).addTo(this.leafletService.map);

    this.rectangle.transform.enable({ rotation: false, scaling: true, uniformScaling:true });


    var that = this;

    //旋轉完執行,一般是爲了放中間的圖標,所以纔要獲取位置信息
    this.rectangle.on("rotateend", function (e) {
      console.log(e.target.getBounds());

      
    })

    //放大縮小執行,一般是爲了放中間的圖標,所以纔要獲取位置信息
    this.rectangle.on("scaleend ", function (e) {
      console.log(e.target.getBounds());


    })


    //拖動完執行,一般是爲了放中間的圖標,所以纔要獲取位置信息
    this.rectangle.on("dragend ", function (e) {
      console.log(e.target.getBounds());

      
    })

 

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