实现定位点的功能
parent
d24c9643ce
commit
4dc89128da
|
@ -0,0 +1,8 @@
|
|||
export const isLnglat = lnglat => {
|
||||
const { lng, lat } = lnglat
|
||||
|
||||
if (isNaN(lng) || lng > 180 || lng < -180) return false
|
||||
if (isNaN(lat) || lat > 90 || lat < -90 ) return false
|
||||
|
||||
return true
|
||||
}
|
|
@ -1,7 +1,11 @@
|
|||
<template>
|
||||
<Pin :position="{ lng: 116.4, lat: 39.9 }" />
|
||||
<Pin :position="position" />
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import Pin from '/@/components/Pin.vue'
|
||||
import { usePositionStore } from '/@/stores/position'
|
||||
|
||||
|
||||
const position = usePositionStore()
|
||||
</script>
|
|
@ -1,24 +1,34 @@
|
|||
<template>
|
||||
<form>
|
||||
<form @keyup.enter="onFlyBtnClick">
|
||||
<label>经度:</label>
|
||||
<input type="text" id="lon-input" placeholder="请输入经度值">
|
||||
<input type="number" v-model="lng" placeholder="请输入经度值">
|
||||
<label>纬度:</label>
|
||||
<input type="text" id="lat-input" placeholder="请输入纬度值">
|
||||
<input type="number" v-model="lat" placeholder="请输入纬度值">
|
||||
<input type="button" id="fly-btn" @click="onFlyBtnClick" value="飞到这个点">
|
||||
<input type="button" id="clear-btn" @click="onClearBtnClick" value="清除坐标">
|
||||
</form>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { usePointStore } from '../stores/point'
|
||||
import { ref } from 'vue';
|
||||
import { usePointStore } from '/@/stores/point'
|
||||
import { usePositionStore } from '/@/stores/position'
|
||||
|
||||
const lng = ref(NaN)
|
||||
const lat = ref(NaN)
|
||||
const position = usePositionStore()
|
||||
const onFlyBtnClick = () => {
|
||||
|
||||
if ( !position.set({ lng: lng.value, lat: lat.value }) ) alert('请输入正确的经纬度信息')
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
const point = usePointStore()
|
||||
const onClearBtnClick = () => {
|
||||
lng.value = NaN
|
||||
lat.value = NaN
|
||||
position.$reset()
|
||||
point.$reset()
|
||||
}
|
||||
|
||||
|
@ -52,6 +62,18 @@ input:focus {
|
|||
outline: none;
|
||||
}
|
||||
|
||||
/* Chrome, Safari, Edge, Opera */
|
||||
input[type=number]::-webkit-outer-spin-button,
|
||||
input[type=number]::-webkit-inner-spin-button {
|
||||
-webkit-appearance: none;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
/* Firefox */
|
||||
input[type=number] {
|
||||
-moz-appearance: textfield;
|
||||
}
|
||||
|
||||
input#fly-btn, input#clear-btn {
|
||||
border-radius: 3px;
|
||||
background-color: #41ddee;
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
<script setup>
|
||||
import { computed } from 'vue'
|
||||
import { usePointStore } from '../stores/point'
|
||||
import { usePointStore } from '/@/stores/point'
|
||||
|
||||
const point = usePointStore()
|
||||
const show = computed(() => point.index)
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
</template>
|
||||
|
||||
<script setup>
|
||||
import { VcEntity, VcGraphicsBillboard } from 'vue-cesium'
|
||||
|
||||
import { computed } from 'vue'
|
||||
import { VcEntity, VcGraphicsBillboard } from 'vue-cesium'
|
||||
import { isLnglat } from '/@/api/util'
|
||||
import pin from '/@/assets/pin.png'
|
||||
|
||||
const props = defineProps({
|
||||
|
@ -21,12 +21,5 @@ const props = defineProps({
|
|||
}
|
||||
})
|
||||
|
||||
const show = computed(() => {
|
||||
const { lng, lat } = props.position
|
||||
|
||||
if (isNaN(lng) || lng > 180 || lng < -180) return false
|
||||
if (isNaN(lat) || lat > 90 || lat < -90 ) return false
|
||||
|
||||
return true
|
||||
})
|
||||
const show = computed(() => isLnglat(props.position))
|
||||
</script>
|
|
@ -0,0 +1,24 @@
|
|||
import { defineStore } from 'pinia'
|
||||
import { isLnglat } from '/@/api/util'
|
||||
|
||||
|
||||
export const usePositionStore = defineStore({
|
||||
id: 'position',
|
||||
state: () => ({
|
||||
lng: NaN,
|
||||
lat: NaN,
|
||||
}),
|
||||
getters: {
|
||||
value: (state) => { state.lng, state.lat }
|
||||
},
|
||||
actions: {
|
||||
set(position) {
|
||||
if ( !isLnglat(position) ) return false
|
||||
|
||||
this.lng = position.lng
|
||||
this.lat = position.lat
|
||||
|
||||
return true
|
||||
},
|
||||
},
|
||||
})
|
Loading…
Reference in New Issue