1
変換を適用した後にSVGポリゴンでポイントを更新するための関数やメソッドはありますか?私はJavaScriptで変換を行っていますが、変換後も同じ点に気づきました。変換後のポリゴンポイントの更新を取得する(SVG)
function drawPolygon(){
var points = "100,100 200,100 200,200 100,200";
var polygon = document.createElementNS(svgURL, "polygon");
polygon.setAttribute("style", "fill: gray; stroke: black; stroke-width: 1; cursor: pointer;");
polygon.setAttribute("points", points);
mySVG.appendChild(polygon);
console.log(polygon.points);
// Points: 100,100 200,100 200,200 100,200
polygon.setAttribute("transform", "translate(200,0)");
console.log(polygon.points);
//Points: 100,100 200,100 200,200 100,200
}
どのように私は次のように更新ポイントを得ることができます:300、100、400、100 400、200 300、200または更新されたポイントを他のポリゴンを取得しますか?
編集:
<svg id="my_svg" version="1.1" baseProfile="full" xmlns="http://www.w3.org/2000/svg" width="300px" height="300px" viewBox="-150 -150 300 300" style="background-color: lightblue">
</svg>
function drawRoom(){
var points = "-100,0 100,0 100,100 -100,100";
var polygon = document.createElementNS(svgURL, "polygon");
polygon.setAttribute("style", "fill: gray; stroke: black; stroke-width: 1; cursor: pointer;");
polygon.setAttribute("points", points);
mySVG.appendChild(polygon);
//Points: "-100,0 100,0 100,100 -100,100";
polygon.setAttribute("transform", "translate(0,-50)");
screenPolygon(polygon);
//Points should be: "-100,-50 100,-50 100,50 -100,50" if I apply function provided by Francis
//But points are: "50, 100 250,100 250,200 50,200"
}
:私たちはビューボックスを持っていない場合はフランシスHemsherから最初の答えは、うまく機能している今、私は問題を抱えている、私は私のSVGでのビューボックスを持っています
polygon after apply function screenPolygon(myPoly)
図1のような更新されたポイントを取得するにはどうすればよいか知っていますか?おかげ
直前removeAttributeへのsetAttributeの呼び出しのポイントは何ですか?また、私はあなたが最近(for myPoly.pointsのvar item)で繰り返すことができると思います。 –
@RobertLongson注意:IEの古いバージョンでは、removeAttributeだけを使用してトランスフォームを削除しませんが、何らかの理由で削除する前に空でなければなりませんでした。 –
@FrancisHemsherありがとう、まさに私が必要なものです。 – insurg3nt3