My canvas displays an image:
https://i.sstatic.net/p3MV4.png
There is a white square with a refresh icon on the right side of the image, slightly hidden by a black circle. I implemented it like this:
var rotatorSpan = document.createElement("span");
rotatorSpan.id = _this.idRotator;
rotatorSpan.className = "glyphicons glyphicons-restart";
document.getElementById("canvas-overlay").appendChild(rotatorSpan);
In the draw function:
this.drawRotator = function() {
var pivotX = _this.x + (_this.imageWidth / 2);
var pivotY = _this.y + (_this.imageHeight / 2);
var radius = Math.sqrt(Math.pow((_this.x - pivotX), 2) + Math.pow((_this.y - pivotY), 2));
var rotatorX = _this.x + (_this.imageWidth / 2) + radius;
var rotatorY = _this.y + (_this.imageHeight / 2) + (_this.indicatorRadius / 2);
_this.ctx.save();
_this.ctx.translate(pivotX, pivotY);
_this.ctx.rotate(_this.rotation);
_this.ctx.translate(-pivotX, -pivotY);
_this.ctx.beginPath();
_this.ctx.arc(rotatorX, rotatorY, this.indicatorRadius, 0, Math.PI * 2, false);
_this.ctx.closePath();
_this.ctx.fill();
_this.ctx.restore();
document.getElementById(_this.idRotator).style.position = "absolute";
document.getElementById(_this.idRotator).style.top = rotatorY + "px";
document.getElementById(_this.idRotator).style.left = rotatorX + "px";
document.getElementById(_this.idRotator).style.fontSize = "1em";
document.getElementById(_this.idRotator).style.backgroundColor = "#fff";
document.getElementById(_this.idRotator).style.border = "1px solid #000;";
document.getElementById(_this.idRotator).style.zIndex = 1000;
document.getElementById(_this.idRotator).style.transform = "rotate(" + _this.rotation + "rad)";
};
When I rotate the image:
https://i.sstatic.net/72nON.png
You can see that everything rotates except the white square with the refresh icon. It rotates around its own center point.
How can I make the white square (span element I created) rotate around the center point of the image?