当前位置:网站首页>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
边栏推荐
- Summary of software test interview questions
- C# WPF UI框架MahApps切换主题
- Dynamic sequence table + OJ
- [learn junit5 from official documents] [II] [writingtests] [learning notes]
- Opencv reads webcam video and saves it locally
- Redis Cluster集群,主节点故障,主从切换后ip变化,客户端需要处理不
- [format] simple output (2)
- Summary of interface automation interview questions for software testing
- Basic workflow of CPU
- What kind of experience is it to prepare for a month to participate in ACM?
猜你喜欢

Introduction and use of openfeign component

AOT和单文件发布对程序性能的影响

Summary of software test interview questions

BLDC double closed loop (speed PI + current PI) Simulink simulation model

tf. keras. layers. Timedistributed function

宁德时代地位不保?

Notes sur le développement de la tarte aux framboises (XII): commencer à étudier la suite UNO - 220 de la tarte aux framboises de contrôle industriel advantech (i): Introduction et fonctionnement du s

ASP.NET 6 中间件系列 - 执行顺序

Depth deterministic strategy gradient (ddpg)

PDH optical transceiver 4-way E1 + 4-way 100M Ethernet 4-way 2m optical transceiver FC single fiber 20km rack type
随机推荐
MYSQL_ From mastery to abandonment
Q-Learning & Sarsa
Dynamic sequence table + OJ
Assembly learning Chapter III of assembly language (Third Edition) written by Wang Shuang
The whole network is the most complete. How to do interface automation test? Proficient in interface automation test details
Recursion - outputs continuously increasing numbers
Cloud computing learning 1 - openstack cloud computing installation and deployment steps with pictures and texts (Xiandian 2.2)
Use DFS to solve the problem of "number of dictionary rows"
TP5 customization in extend directory succeeded and failed. Return information
微软是如何解决 PC 端程序多开问题的——内部实现
Sonic cloud real machine tutorial
Array and collection types passed by openfeign parameters
C#语法糖空合并运算符【??】和空合并赋值运算符【 ??=】
tf. keras. layers. Embedding function
Ningde's position in the times is not guaranteed?
The difference between encodeuri and encodeuricomponent
c#语法糖模式匹配【switch 表达式】
Traversal of l2-006 tree (middle and later order determination binary tree & sequence traversal)
交换二叉树中每个结点的左和右
Er and eer models
https://www.textin.com/experience/text_recognize_3d1