0

次を使用して、キャンバスに描画する線の長さを計算しています。

layer.on("mouseup", function () {
                moving = false;
                var mousePos = stage.getMousePosition();
                x2 = mousePos.x;
                y2 = mousePos.y;
                $("#distance").val(calculateDistance(x1, y1, x2, y2));

            });
function calculateDistance(x1, y1, x2, y2) {
            var distance = Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
            distance *= 0.264583333;
            distance = Math.round(distance * 100 / 1) / 100;
            return distance;
}

現在、入力フィールドに距離を入れています。しかし、ラインのラベルとして追加したいと思います! http://jsfiddle.net/user373721/xzEad/1/のデモ。

事前に感謝します。

4

1 に答える 1