I am currently working on a project using Angular where my objective is to create a polygon within an image. In order to achieve this, I have placed an SVG element inside the image tag. Both the image and the SVG have fixed width and height dimensions, and the points for the polygon are retrieved from the database with static values. However, I am facing an issue where the polygon does not display correctly. Here is a small example:
https://i.sstatic.net/swbkd.png
Here is the code snippet:
HTML:
<div class="img-map">
<img #image src="https://content.gnoss.ws/imagenes/Documentos/ImagenesSemanticas/07aabdfa-981f-41f7-828d-78f21adb80a6/eb1d0185-7d5b-4d3a-b84a-5aefd95d3365.jpg" alt=""/>
<svg style="position:absolute; left:0px; top:0px; width: 100%; height: 100%">
<polygon class="polygonStyle" [attr.points]="stringPoints" />
</svg>
</div>
CSS:
.img-map {
overflow: auto;
position: relative;
max-width: calc(100vw - 450px);
}
.polygonStyle {
stroke: rgba(0, 0, 255, 0.75);
fill: none;
}
img {
top: 0;
left: 0;
border-radius: 10px;
height: auto;
width: 100%;
}
TS:
stringPoints = "1015,481 1043,578 1087,565 1055,467";
I have created a stackblitz to demonstrate the issue. It seems that the problem may be related to scaling, but I am uncertain of how to address it.
Efforts so far:
- I have come across this question on stackoverflow, but no viable solution was found.
- This project contains code utilizing the viewbox attribute, yet it does not seem to have any impact. https://i.sstatic.net/3hKE4.png
I am unsure of what mistake I might be making here. Any insights would be greatly appreciated. Thank you!