vue3实现根据x,y坐标数据,绘图

<div class="back">
     <img src="back.png" class="backImg"/>
     <div class="backposide">    
         <i 
             v-for="(item,index) in sunCoronalholeArr" 
             :key="index"  
             class="sunspot2"
             :style="{'top':item.y +'px',left:item.x +'px'}"
              ></i>
     </div>
</div>

<script lang="ts" setup>
 const   sunCoronalholeArr = ref([])
   const getQuery = ()=>{
      //获取到X坐标和Y坐标的数据
       getQuery().then(res=>{
            //获取要绘制区域的大小
            let mapWidth = document.getElementsByClassName('back')[0].offsetWidth;
            let mapHeight = document.getElementsByClassName('back')[0].offsetHeight;
            let add: any = []
             //这个注意,因为原始x,y的底图大小和前端可视区域的大小,肯定不一样,所以,我们要根据
            // 前端的大小和底图的大小,进行计算
            //  这里的1000是底图的大小
            // 这样计算,就能拿到可以适合前端大小的X,Y坐标了
            res.data.result.list.forEach((el, index) => {
             add.push({ 'x': (el.x * mapWidth) / 1000, 'y': (el.y * mapHeight) / 1000})
            })
       })
   }

</script>
<style>
.back{
  position: relative;
  width:100px;
  height:100px;
}
.backImg{
   width:100px;
  height:100px;
}

.backposide{
   position: absolute;
   width:100px;
   height:100px;
   top:0;
   left:0;
   z-index:11;
}
i{
        position: absolute;
        display: block;
        width: 0.5rem;
        height: 0.5rem;
        border-radius: 50%;
        background-color: #0e0b0b;
}
</style>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值