CSS画极坐标的实际示例是怎样的,代码是什么
Admin 2022-11-12 群英技术资讯 1251 次浏览
很多朋友都对“CSS画极坐标的实际示例是怎样的,代码是什么”的内容比较感兴趣,对此小编整理了相关的知识分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获,那么感兴趣的朋友就继续往下看吧!项目有图表方面的需求,其中有做卫星定位的图形,需要制作极坐标来显示当前北半球或南半球的卫星分布情况。第一时间想到了echarts的极坐标,找到示例,虽然满足了部分需求,但是极坐标是由canvs画的,卫星有自己的编号,所以难以辨析每个点对应的卫星编号。于是就想到了自己去用CSS画极坐标
提示:以下是本篇文章正文内容,下面案例可供参考
上面示例,下面echarts示例

1.纬度
几个div,设置圆角
2.经度
多条0.5px的边框,通过旋转实现
lines: [
{
id: 1,
transform: "translateX(-50%) rotateZ(0deg) scaleX(0.4)",
borderStyle: "solid",
borderColor: "#333",
},
{
id: 2,
transform: "translateX(-50%) rotateZ(45deg) scaleX(0.4)",
borderStyle: "dashed",
borderColor: "#91cc75",
},
{
id: 3,
transform: "translateX(-50%) rotateZ(90deg) scaleX(0.4)",
borderStyle: "solid",
borderColor: "#333",
},
{
id: 4,
transform: "translateX(-50%) rotateZ(135deg) scaleX(0.4)",
borderStyle: "dashed",
borderColor: "#91cc75",
},
],
3.卫星(点)
后台的数据只有经度和纬度。纬度很好做,按照90°的比例进行定位。经度用到旋转,注意不是直接在点上旋转,否则只是盒子旋转,需要在点外边套一个div进行旋转,如果需要美化,可以使点反方向旋转该角度达到编号是一个正的效果。
代码是以vue的组件来写的,satellites就是极坐标的数据接口。
<template>
<div class="polar">
<div class="polar-main">
<div class="polar-1">
<div class="polar-2">
<div class="polar-3">
<p
v-for="item in latitudes"
:key="item.id"
class="latitude"
:style="{
top: item.location.top,
transform: item.location.transform,
}"
>
{{ item.value }}
</p>
<div class="polar-center">
<div class="satellites">
<div v-for="item in satellites" :key="item.name">
<p
v-for="ele in item.distribution"
:key="ele.id"
class="satellite-box"
:style="{
transform: rotate(ele.long),
}"
>
<el-tooltip
class="item"
effect="dark"
:content="`经度:${ele.long} 纬度:${ele.lati}`"
placement="top-start"
>
<span
class="satellite"
:style="{
backgroundColor: ele.color,
top: top(ele.lati),
transform: rotate(-1 * ele.long),
}"
>{{ ele.id }}</span
>
</el-tooltip>
</p>
</div>
</div>
</div>
</div>
</div>
</div>
<p
v-for="item in lines"
:key="item.id"
class="line"
:style="{
transform: item.transform,
borderStyle: item.borderStyle,
borderColor: item.borderColor,
}"
></p>
<p
v-for="item in longitudes"
:key="item.id"
class="longitude"
:style="{
top: item.location.top,
left: item.location.left,
transform: item.location.transform,
}"
>
{{ item.value }}
</p>
</div>
<div class="satellite-name"></div>
</div>
</template>
<script>
export default {
data() {
return {
lines: [
{
id: 1,
transform: "translateX(-50%) rotateZ(0deg) scaleX(0.4)",
borderStyle: "solid",
borderColor: "#333",
},
{
id: 2,
transform: "translateX(-50%) rotateZ(45deg) scaleX(0.4)",
borderStyle: "dashed",
borderColor: "#91cc75",
},
{
id: 3,
transform: "translateX(-50%) rotateZ(90deg) scaleX(0.4)",
borderStyle: "solid",
borderColor: "#333",
},
{
id: 4,
transform: "translateX(-50%) rotateZ(135deg) scaleX(0.4)",
borderStyle: "dashed",
borderColor: "#91cc75",
},
],
longitudes: [
{
id: 5,
value: "90°",
location: {
top: "50%",
left: "100%",
transform: "translateY(-50%)",
},
},
{
id: 6,
value: "180°",
location: {
top: "100%",
left: "50%",
transform: "translateX(-50%)",
},
},
{
id: 7,
value: "270°",
location: {
top: "50%",
left: "0",
transform: "translateX(-100%) translateY(-50%)",
},
},
{
id: 8,
value: "360°",
location: {
top: "0",
left: "50%",
transform: "translateX(-50%) translateY(-100%)",
},
},
],
latitudes: [
{
id: 1,
value: "90°",
location: {
top: "50%",
left: "0",
transform: "translateY(-50%) translateX(50%)",
},
},
{
id: 2,
value: "60°",
location: {
top: "0",
left: "0",
transform: "translateY(-50%) translateX(50%)",
},
},
{
id: 3,
value: "30°",
location: {
top: "-50%",
left: "0",
transform: "translateY(-50%) translateX(50%)",
},
},
],
satellites: [
{
name: "Below Mask",
distribution: [
{
id: "10",
long: 46.397128,
lati: 56.397128,
color: "#409eff",
},
{
id: "08",
long: 76.397128,
lati: 32.916527,
color: "#409eff",
},
],
},
{
name: "Unhealthy",
distribution: [
{
id: "25",
long: 156.397128,
lati: 62.916527,
color: "#f56c6c",
},
{
id: "25",
long: 316.397128,
lati: 12.916527,
color: "#f56c6c",
},
],
},
{
name: "Missing",
distribution: [
{
id: "07",
long: 256.397128,
lati: 22.916527,
color: "#118452",
},
{
id: "18",
long: 56.397128,
lati: 27.916527,
color: "#118452",
},
{
id: "12",
long: 66.397128,
lati: 27.916527,
color: "#118452",
},
{
id: "16",
long: 196.397128,
lati: 67.916527,
color: "#118452",
},
],
},
],
};
},
methods: {
top(lati) {
return ((90 - lati) / 90) * -90 - 10 + "px";
},
rotate(long) {
let z = (long / 360) * 360;
return `rotateZ(${z}deg)`;
},
},
// filters: {},
};
</script>
<style scoped lang='scss'>
$polarPiameter: 180px;
.polar-main {
width: $polarPiameter;
height: $polarPiameter;
position: relative;
p {
margin: 0;
}
.polar-1 {
width: $polarPiameter;
height: $polarPiameter;
border-style: solid;
.polar-2 {
width: $polarPiameter * 2/3;
height: $polarPiameter * 2/3;
border-style: dashed;
.polar-3 {
width: $polarPiameter/3;
height: $polarPiameter/3;
border-style: dashed;
.polar-center {
width: 1px;
height: 1px;
background-color: #333;
}
}
}
}
.line {
height: $polarPiameter;
border-right-color: #333;
border-right-width: 1px;
border-right-style: solid;
position: absolute;
left: 50%;
cursor: pointer;
}
.longitude,
.latitude {
height: 14px;
line-height: 14px;
font-size: 12px;
color: #868585;
position: absolute;
cursor: pointer;
}
}
.polar-1,
.polar-2,
.polar-3,
.polar-center {
border-radius: 50%;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
border-color: #91cc75;
border-width: 1px;
box-sizing: border-box;
cursor: pointer;
}
.polar-1:hover {
border-width: 2px;
}
.polar-2:hover{
border-width: 2px;
}
.satellite-box {
position: absolute;
width: 1px;
height: 1px;
border-radius: 50%;
background-color: transparent;
.satellite {
position: absolute;
left: -10px;
width: 20px;
height: 20px;
line-height: 20px;
text-align: center;
border-radius: 50%;
font-size: 14px;
color: #fff;
cursor: pointer;
z-index: 999;
opacity: 0.6;
transition: 0.6s;
}
.satellite:hover {
background-color: #333 !important;
}
}
</style>
示例图:

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
弹性布局,顾名思义就是具有弹性特点,能够自由的伸缩,也就是自适应网页。所以使用css弹性布局flex可以便捷,完整,响应式地实现多种页面布局。这篇文章就主要给大家介绍一下css弹性布局flex的使用。
第一点,和我的相符,但我把它改成了position:absolute,问题依然存在。第二点、第三点和我的情况不符。接着就是一层一层地追,发现把这个层(A)比较高一级的父层(B)加上position:relative;z-index:100;就好了,原来是B层比与相邻的层(C)低了,导致B层里的任何一层无论怎么设z-index,也高不过与B层相邻的那个C层。第 ...
css中hack的介绍:为了达到统一的页面效果,需要为不同的浏览器或者不同版本编写CSS样式。将这个程序写成对应于不同浏览器/不同版本的CSScode,称为CSShack。
我们在HTML中设置frameset的高度时会出现界面变形的情况,那么设置frameset的高度界面变形怎么办呢?接下来我们就一起去看看设置frameset的高度界面变形的解决方法。
background-repeat:指背景图片的重复与否以及重复方式,有no-repeat,repeat,repeat-x,repeat-y四种属性值.no-repeat:即无论背景图片的大小,只显示单个背景图片,如首页的第一篇文章标题前的”NEW”图标,代码如上所示;repeat:指背景图片横向和纵向重复连续显示;repeat-x:指背景图片横向重复连续显示;repeat-
成为群英会员,开启智能安全云计算之旅
立即注册关注或联系群英网络
7x24小时售前:400-678-4567
7x24小时售后:0668-2555666
24小时QQ客服
群英微信公众号
CNNIC域名投诉举报处理平台
服务电话:010-58813000
服务邮箱:service@cnnic.cn
投诉与建议:0668-2555555
Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 ICP核准(ICP备案)粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008