<template>
<div class="sindagis-map-compass">
<span class="left" @click="leftClick"></span>
<span class="center" @click="recoveryClick" :style="{transform: `rotate(${rotate}deg)`}"></span>
<span class="right" @click="rightClick"></span>
</div>
</template>
<script>
import { easeOut } from 'ol/easing'
export default {
name: "MapCompass",
created() {
},
data(){
return {
rotate: 0,
currentDir: ''
}
},
beforeDestroy() {},
methods: {
leftClick(){
var view = this.map.getView();
var center = this.map.getView().getCenter();
var rotation = this.map.getView().getRotation();
rotation = rotation - Math.PI/2
this.rotate -= 90
view.animate({
center: center, //旋转中心点
rotation: rotation,
easing: easeOut //旋转速度
})
this.currentDir = 'left'
},
recoveryClick(){
var view = this.map.getView();
var center = this.map.getView().getCenter();
let a = this.rotate % 360 // -270
if(a != 0){ // 复位
let dis = 360 - Math.abs(a)
let dis1 = Math.abs(a)
dis = dis > dis1 ? dis1 : dis
if(dis == 180) dis = -180
this.rotate = (this.rotate + dis) % 360 == 0 ? this.rotate + dis : this.rotate - dis
}
view.animate({
center: center,
rotation: 0,
easing: easeOut
})
},
rightClick(){
var view = this.map.getView();
var center = this.map.getView().getCenter();
var rotation = this.map.getView().getRotation();
rotation = rotation + Math.PI/2
this.rotate += 90
view.animate({
center: center,
rotation: rotation,
easing: easeOut
})
this.currentDir = 'right'
},
}
}
</script>
<style lang="scss">
.sindagis-map-compass{
position: absolute;
z-index: 5;
bottom: 60px;
right: 0px;
width: 52px;
height: 54px;
background: url('../../assets/img/earth-navi-control-pc4.png') 0% 0% / 266px no-repeat;
.left, .center, .right{
position: absolute;
outline: none;
border: none;
cursor: pointer;
opacity: 1;
}
.left{
background: url('../../assets/img/earth-navi-control-pc4.png') -75px -5px / 266px no-repeat;
left: 2px;
top: 5px;
z-index: 1;
width: 15px;
height: 42px;
&:hover{
background: url('../../assets/img/earth-navi-control-pc4.png') -89px -5px / 266px no-repeat;
}
}
.center{
background: url('../../assets/img/earth-navi-control-pc4.png') -56px -4px / 266px no-repeat;
left: 19px;
top: 4px;
width: 14px;
height: 44px;
transform: rotate(0deg);
transition: 1s;
}
.right{
background: url('../../assets/img/earth-navi-control-pc4.png') -75px -5px / 266px no-repeat;
right: 2px;
top: 5px;
z-index: 1;
width: 15px;
height: 42px;
transform: scaleX(-1);
&:hover{
background: url('../../assets/img/earth-navi-control-pc4.png') -89px -5px / 266px no-repeat;
}
}
}
</style>