天天看點

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

效果如下圖所示:

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());

      
    })

           

繼續閱讀