当前位置:网站首页>svg标签中利用<polygon/>循环数组绘制多边形
svg标签中利用<polygon/>循环数组绘制多边形
2022-04-23 03:06:00 【张小欢ㄦ~】
1、将所有循环的坐标存在数组里,因为我们要画矩形,所以每个数组里面的坐标点应该有八个,几循环数组的形式:【 [x1 y1,x2 y2,x3 y3,x4 y4],[x1 y1,x2 y2,x3 y3,x4 y4],[x1 y1,x2 y2,x3 y3,x4 y4]......】;
2、代码: 数组 ratioPositionArr即为上面形式;
//将后端返回来的数据做处理:将每个数组里面的坐标等比例放大缩小,再存在一个新数组中。
locationsPosition(newVal, oldVal) {
this.activeIfSvg = ''
this.ratioPositionArr = []
// console.log(77, newVal)
// this.ratioPositionArr=newVal
const itemArr = []
this.eryArr = []
// console.log('eryArr', this.ratioWidth)
newVal.forEach((item, index) => {
item.forEach(itemevery => {
this.eryArr.push(itemevery / this.ratioWidth)
})
itemArr.push(this.eryArr)
this.eryArr = []
})
// console.log('itemArr', itemArr)
this.ratioPositionArr = itemArr
// console.log('99',this.ratioPositionArr)
},
<div
id="svgbox"
class="svgbox"
style="border: 2px solid white"
ref="svgcanvas"
@mousedown="move"
>
<svg
class="svgelement"
style="width: 100%; height: 100%; border: 1px solid white"
ref="svgcanvas"
>
<polygon
v-for="(item, index) in ratioPositionArr"
:points="item"
:key="index"
:class="activeIfSvg === index ? 'activeIfSvg' : ''"
@click="getClickSvg(index)"
></polygon>
</svg>
</div>
3、最终效果:蓝色边框即为 svg---polygon--points 根据数组中的坐标画出的多边形!

版权声明
本文为[张小欢ㄦ~]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_51196135/article/details/124345579
边栏推荐
- 微软是如何解决 PC 端程序多开问题的——内部实现
- Introduction to ACM [inclusion exclusion theorem]
- TP5 inherits base and uses the variables in base
- JS relearning
- tf. keras. layers. Timedistributed function
- 求二叉树的叶子结点个数
- It turns out that PID was born in the struggle between Lao wangtou and Lao sky
- Openfeign details show
- Source code interpretation of Flink index parameters (read quantity, sent quantity, sent bytes, received bytes, etc.)
- Passing object type parameters through openfeign
猜你喜欢

Response processing of openfeign

樹莓派開發筆記(十二):入手研華ADVANTECH工控樹莓派UNO-220套件(一):介紹和運行系統

宁德时代地位不保?

tf. keras. layers. Conv? D function

基于.NetCore开发博客项目 StarBlog - (1) 为什么需要自己写一个博客?

MAUI初体验:爽

准备一个月去参加ACM,是一种什么体验?

全网讲的最细,软件测试度量,怎样优化软件测试成本提高效率---火爆

Small companies don't make formal offers
![Niuke white moon race 6 [solution]](/img/c5/6c59378c3bb12efa60ab3a8cd2c943.png)
Niuke white moon race 6 [solution]
随机推荐
Ningde's position in the times is not guaranteed?
准备一个月去参加ACM,是一种什么体验?
【鉴权/授权】自定义一个身份认证Handler
JS relearning
tf. keras. layers. Conv? D function
Detailed explanation of distributed things
Thoughts on the 2022 national network security competition of the national secondary vocational group (only one idea for myself) - network security competition questions (9)
TP5 email (2020-05-27)
How to count the number of all files in a directory under win10 system
一套关于 内存对齐 的C#面试题,做错的人很多!
Regular object type conversion tool - Common DOM class
微软是如何解决 PC 端程序多开问题的——内部实现
基于.NetCore开发博客项目 StarBlog - (2) 环境准备和创建项目
TP5 inherits base and uses the variables in base
Source code interpretation of Flink index parameters (read quantity, sent quantity, sent bytes, received bytes, etc.)
Q-Learning & Sarsa
C#语法糖空合并运算符【??】和空合并赋值运算符【 ??=】
全网最全,接口自动化测试怎么做的?精通接口自动化测试详解
【新版发布】ComponentOne 新增 .NET 6 和 Blazor 平台控件支持
Opencv fills the rectangle with a transparent color
https://www.textin.com/experience/text_recognize_3d1