I have a web page that displays an image excerpt from a document using drawimage(x,z,width,height)
. The user has the ability to draw a rectangle around any given line on the image by clicking the line. The image then has a rectangle drawn on it using rect(x,y,w,h)
.
Using the JavaScript magnifier, the user can hover over the image to see a zoomed in version. However, it does not show the rectangle drawn on to the image on the canvas.
Is it possible to draw both the rectangle and the image? Currently this is the setup for the magnifier:
// - Setup the magnifier component
var glass, w, h, bw;
glass = document.getElementById("magnifier"); // Get pre-existing div for the magnifier
glass.setAttribute("class", "img-magnifier-glass");
// Set background properties for the magnifier glass:
glass.style.backgroundImage = 'url("' + pRow.getValue("imgPath") + '")'; // pRow here refers to a parameter array that is passed in containing data about the image and rectangle
glass.style.backgroundRepeat = "no-repeat";
glass.style.backgroundSize = imgwidth + "px " + imgheight + "px";
bw = 3; // Border width of the magnifier glass.
w = glass.offsetWidth / 2;
h = glass.offsetHeight / 2;
Later on there is code to actually move the background position. But I don't see a way to show the rectangle that is drawn on top of the image, in the canvas, on the magnifier.
Finally I have solved it and this one was quite the task.
To do it
This does introduce a long load time each time you want to change the rectangle location. But allows for the rectangle to become part of the image so the magnifier picks it up.
Here is the code (this was done in Omnis Studio if anything looks off from normal JavaScript (also there is a lot of code before this. But this is the solution, so I'll just show this bit)):
If anyone can find a way to do this without needing to constantly reload the image and cause a large amount of lag/wait time. Please let me know.