admin管理员组文章数量:1291327
Using fabric js i draw a different shapes such as circle ,rectangle .I tried
the rectangle is drawn by fabric.rect() method
canvas.getActiveObject().get('points');
but it returns undefined
I have also gone through this post
How to get polygon points in Fabric.js
but i cannot solve the issue
var object = canvas.getActiveObject();
var objectCenter = object.getCenterPoint();
var translatedPoints = object.get('points');
console.log(object);
console.log(translatedPoints);
translatedPoints.map(function(p) {
var pt = {
x: objectCenter.x + p.x,
y: objectCenter.y + p.y
};
console.log(pt);
Is there any way to find the coordinates of the rectangle or other active objects drawn by similar methods
Using fabric js i draw a different shapes such as circle ,rectangle .I tried
the rectangle is drawn by fabric.rect() method
canvas.getActiveObject().get('points');
but it returns undefined
I have also gone through this post
How to get polygon points in Fabric.js
but i cannot solve the issue
var object = canvas.getActiveObject();
var objectCenter = object.getCenterPoint();
var translatedPoints = object.get('points');
console.log(object);
console.log(translatedPoints);
translatedPoints.map(function(p) {
var pt = {
x: objectCenter.x + p.x,
y: objectCenter.y + p.y
};
console.log(pt);
Is there any way to find the coordinates of the rectangle or other active objects drawn by similar methods
Share Improve this question edited Sep 29, 2017 at 18:31 Ali Soltani 9,9465 gold badges31 silver badges57 bronze badges asked Mar 3, 2016 at 11:16 ArUnArUn 1,3372 gold badges23 silver badges40 bronze badges2 Answers
Reset to default 6You can use this code:
var obj = canvas.getActiveObject();
alert(obj.left + "," + obj.top);
If you want to get the data for all objects on your canvas, you can create a JSON object using the following code. Coordinates for all of your objects will be included as properties in the output (along with object height & width - per Chirag's question in the previous answer).
function serializeCanvas(c) {
var canvasJson = JSON.stringify(c);
console.log(canvasJson);
}
本文标签: javascriptFind Coordinates of the Active Object in fabricjsStack Overflow
版权声明:本文标题:javascript - Find Coordinates of the Active Object in fabric.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741529160a2383649.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论