javascript - How to set text in center of curve shape with jCanvas? -
i'm drawing "map" jcanvas using drawline method , need put house number in center of curve shape (it can has random number of angles).
also please note, objects draggable , text must draggable it.
or how can calculate center of object, can has random number of angles?
i wrote function solved problem. var points must send svg polygon points.
function getcenter(points, index) { if (typeof points!="undefined") { var pairs = []; pairs = points.split(" "); var first = true; var min; var max; for(var i=0;i<pairs.length;i++) { var list = pairs[i].split(','); if(first===true) { first = false; min = max = list[index]; } else { if(list[index]<min) min = list[index]; if(list[index]>max) max = list[index]; } } min = parseint(min); max = parseint(max); var result = (min+max)/2; return result; } else return false; };
Comments
Post a Comment