Browse Source

坐标转换

lbj
sd 2 months ago
parent
commit
2227d367fd
  1. 95
      ruoyi-ui/src/views/cesiumMap/LocateDialog.vue
  2. 49
      ruoyi-ui/src/views/cesiumMap/index.vue
  3. 8
      ruoyi-ui/src/views/childRoom/index.vue

95
ruoyi-ui/src/views/cesiumMap/LocateDialog.vue

@ -61,7 +61,7 @@
<el-option <el-option
v-for="item in waypointList" v-for="item in waypointList"
:key="item.id" :key="item.id"
:label="`${item.name} (${degreesToDMS(item.lng)}, ${degreesToDMS(item.lat)})`" :label="`${item.name} (${formatCoordinate(item.lng)}, ${formatCoordinate(item.lat)})`"
:value="item.id" :value="item.id"
/> />
</el-select> </el-select>
@ -70,7 +70,7 @@
<el-form-item label="经度:"> <el-form-item label="经度:">
<el-input <el-input
v-model="formData.lng" v-model="formData.lng"
placeholder="例如 116°23'48.64"" :placeholder="coordinateFormat === 'dms' ? '例如 116°23\'48.64&quot;' : '例如 116.396844'"
clearable clearable
/> />
</el-form-item> </el-form-item>
@ -78,7 +78,7 @@
<el-form-item label="纬度:"> <el-form-item label="纬度:">
<el-input <el-input
v-model="formData.lat" v-model="formData.lat"
placeholder="例如 39°54'33.48"" :placeholder="coordinateFormat === 'dms' ? '例如 39°54\'33.48&quot;' : '例如 39.909289'"
clearable clearable
/> />
</el-form-item> </el-form-item>
@ -107,6 +107,10 @@ export default {
visible: { visible: {
type: Boolean, type: Boolean,
default: false default: false
},
coordinateFormat: {
type: String,
default: 'dms' // 'decimal' 'dms'
} }
}, },
data() { data() {
@ -137,9 +141,44 @@ export default {
this.loadScenarios() this.loadScenarios()
} }
this.$emit('update:visible', newVal) this.$emit('update:visible', newVal)
},
coordinateFormat: {
handler(newVal) {
this.updateCoordinateFormat(newVal)
}
} }
}, },
methods: { methods: {
updateCoordinateFormat(newFormat) {
if (!this.formData.lng || !this.formData.lat) return
let lngDegrees, latDegrees
if (this.coordinateFormat === 'dms') {
lngDegrees = this.dmsToDegrees(this.formData.lng)
latDegrees = this.dmsToDegrees(this.formData.lat)
} else {
lngDegrees = parseFloat(this.formData.lng)
latDegrees = parseFloat(this.formData.lat)
}
if (lngDegrees !== null && latDegrees !== null && !isNaN(lngDegrees) && !isNaN(latDegrees)) {
if (newFormat === 'dms') {
this.formData.lng = this.degreesToDMS(lngDegrees)
this.formData.lat = this.degreesToDMS(latDegrees)
} else {
this.formData.lng = lngDegrees.toFixed(6)
this.formData.lat = latDegrees.toFixed(6)
}
}
},
formatCoordinate(value) {
if (this.coordinateFormat === 'dms') {
return this.degreesToDMS(value)
} else {
return value.toFixed(6)
}
},
degreesToDMS(decimalDegrees) { degreesToDMS(decimalDegrees) {
const degrees = Math.floor(decimalDegrees) const degrees = Math.floor(decimalDegrees)
const minutesDecimal = (decimalDegrees - degrees) * 60 const minutesDecimal = (decimalDegrees - degrees) * 60
@ -157,12 +196,22 @@ export default {
return sign * (Math.abs(degrees) + minutes / 60 + seconds / 3600) return sign * (Math.abs(degrees) + minutes / 60 + seconds / 3600)
}, },
resetForm() { resetForm() {
this.formData = { if (this.coordinateFormat === 'dms') {
scenarioId: null, this.formData = {
routeId: null, scenarioId: null,
waypointId: null, routeId: null,
lng: '116°23\'48.64"', waypointId: null,
lat: '39°54\'33.48"' lng: '116°23\'48.64"',
lat: '39°54\'33.48"'
}
} else {
this.formData = {
scenarioId: null,
routeId: null,
waypointId: null,
lng: '116.396844',
lat: '39.909289'
}
} }
this.routeList = [] this.routeList = []
this.waypointList = [] this.waypointList = []
@ -214,8 +263,8 @@ export default {
if (value) { if (value) {
const waypoint = this.waypointList.find(w => w.id === value) const waypoint = this.waypointList.find(w => w.id === value)
if (waypoint) { if (waypoint) {
this.formData.lng = this.degreesToDMS(waypoint.lng) this.formData.lng = this.formatCoordinate(waypoint.lng)
this.formData.lat = this.degreesToDMS(waypoint.lat) this.formData.lat = this.formatCoordinate(waypoint.lat)
} }
} }
}, },
@ -233,12 +282,24 @@ export default {
return return
} }
const lngDegrees = this.dmsToDegrees(lng) let lngDegrees, latDegrees
const latDegrees = this.dmsToDegrees(lat)
if (lngDegrees === null || latDegrees === null || isNaN(lngDegrees) || isNaN(latDegrees)) { if (this.coordinateFormat === 'dms') {
this.$message.error('请输入有效的度分秒格式!格式:116°23\'48.64"') lngDegrees = this.dmsToDegrees(lng)
return latDegrees = this.dmsToDegrees(lat)
if (lngDegrees === null || latDegrees === null || isNaN(lngDegrees) || isNaN(latDegrees)) {
this.$message.error('请输入有效的度分秒格式!格式:116°23\'48.64"')
return
}
} else {
lngDegrees = parseFloat(lng)
latDegrees = parseFloat(lat)
if (isNaN(lngDegrees) || isNaN(latDegrees)) {
this.$message.error('请输入有效的十进制格式!')
return
}
} }
if (lngDegrees < -180 || lngDegrees > 180 || latDegrees < -90 || latDegrees > 90) { if (lngDegrees < -180 || lngDegrees > 180 || latDegrees < -90 || latDegrees > 90) {

49
ruoyi-ui/src/views/cesiumMap/index.vue

@ -43,6 +43,7 @@
<!-- 定位弹窗 --> <!-- 定位弹窗 -->
<locate-dialog <locate-dialog
:visible="locateDialogVisible" :visible="locateDialogVisible"
:coordinateFormat="coordinateFormat"
@update:visible="locateDialogVisible = $event" @update:visible="locateDialogVisible = $event"
@confirm="handleLocateConfirm" @confirm="handleLocateConfirm"
@cancel="handleLocateCancel" @cancel="handleLocateCancel"
@ -114,6 +115,10 @@ export default {
unit: 'km', unit: 'km',
position: 'bottom-right' position: 'bottom-right'
}) })
},
coordinateFormat: {
type: String,
default: 'dms' // 'decimal' 'dms'
} }
}, },
watch: { watch: {
@ -133,6 +138,11 @@ export default {
this.updateScaleFromConfig(newVal) this.updateScaleFromConfig(newVal)
} }
} }
},
coordinateFormat: {
handler(newVal) {
this.updateCoordinatesDisplay()
}
} }
}, },
data() { data() {
@ -185,6 +195,7 @@ export default {
}, },
// //
coordinatesText: '经度: --, 纬度: --', coordinatesText: '经度: --, 纬度: --',
currentCoordinates: null,
// //
scaleBarText: '--', scaleBarText: '--',
scaleBarWidthPx: 80, scaleBarWidthPx: 80,
@ -1695,7 +1706,7 @@ export default {
webgl: { webgl: {
antialias: true, antialias: true,
msaa: true, msaa: true,
msaaSamples: 8 msaaSamples: 4
} }
} }
}) })
@ -2259,10 +2270,18 @@ this.viewer.scene.postProcessStages.fxaa.enabled = true
addCoordinateLabels() { addCoordinateLabels() {
for (let lon = -180; lon <= 180; lon += 30) { for (let lon = -180; lon <= 180; lon += 30) {
for (let lat = -90; lat <= 90; lat += 30) { for (let lat = -90; lat <= 90; lat += 30) {
let latText, lonText
if (this.coordinateFormat === 'dms') {
latText = `${this.degreesToDMS(lat)}N`
lonText = `${this.degreesToDMS(lon)}E`
} else {
latText = `${lat.toFixed(2)}°N`
lonText = `${lon.toFixed(2)}°E`
}
this.viewer.entities.add({ this.viewer.entities.add({
position: Cesium.Cartesian3.fromDegrees(lon, lat), position: Cesium.Cartesian3.fromDegrees(lon, lat),
label: { label: {
text: `${this.degreesToDMS(lat)}N\n${this.degreesToDMS(lon)}E`, text: `${latText}\n${lonText}`,
font: '12px sans-serif', font: '12px sans-serif',
fillColor: Cesium.Color.BLACK, fillColor: Cesium.Color.BLACK,
outlineColor: Cesium.Color.WHITE, outlineColor: Cesium.Color.WHITE,
@ -2524,7 +2543,7 @@ this.viewer.scene.postProcessStages.fxaa.enabled = true
color: Cesium.Color.fromCssColorString(this.defaultStyles.line.color), color: Cesium.Color.fromCssColorString(this.defaultStyles.line.color),
dashLength: 16 dashLength: 16
}), }),
arcType: Cesium.ArcType.NONE clampToGround: true
} }
}); });
} }
@ -4653,7 +4672,13 @@ this.viewer.scene.postProcessStages.fxaa.enabled = true
}, },
duration: 2 duration: 2
}) })
this.$message.success(`已定位到经度 ${this.degreesToDMS(lng)},纬度 ${this.degreesToDMS(lat)}`) let coordinateText
if (this.coordinateFormat === 'dms') {
coordinateText = `${this.degreesToDMS(lng)}${this.degreesToDMS(lat)}`
} else {
coordinateText = `${lng.toFixed(6)}${lat.toFixed(6)}`
}
this.$message.success(`已定位到经度 ${coordinateText}`)
} }
}, },
@ -4925,12 +4950,26 @@ this.viewer.scene.postProcessStages.fxaa.enabled = true
const cartographic = Cesium.Cartographic.fromCartesian(cartesian) const cartographic = Cesium.Cartographic.fromCartesian(cartesian)
const longitude = Cesium.Math.toDegrees(cartographic.longitude) const longitude = Cesium.Math.toDegrees(cartographic.longitude)
const latitude = Cesium.Math.toDegrees(cartographic.latitude) const latitude = Cesium.Math.toDegrees(cartographic.latitude)
this.coordinatesText = `经度: ${this.degreesToDMS(longitude)}, 纬度: ${this.degreesToDMS(latitude)}` this.currentCoordinates = { longitude, latitude }
this.updateCoordinatesDisplay()
} else { } else {
this.coordinatesText = '经度: --, 纬度: --' this.coordinatesText = '经度: --, 纬度: --'
} }
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE) }, Cesium.ScreenSpaceEventType.MOUSE_MOVE)
}, },
//
updateCoordinatesDisplay() {
if (!this.currentCoordinates) {
this.coordinatesText = '经度: --, 纬度: --'
return
}
const { longitude, latitude } = this.currentCoordinates
if (this.coordinateFormat === 'dms') {
this.coordinatesText = `经度: ${this.degreesToDMS(longitude)}, 纬度: ${this.degreesToDMS(latitude)}`
} else {
this.coordinatesText = `经度: ${longitude.toFixed(6)}, 纬度: ${latitude.toFixed(6)}`
}
},
destroyViewer() { destroyViewer() {
this.stopDrawing() this.stopDrawing()
this.clearAll(false) this.clearAll(false)

8
ruoyi-ui/src/views/childRoom/index.vue

@ -12,6 +12,7 @@
<cesiumMap ref="cesiumMap" :drawDomClick="drawDom || airspaceDrawDom" <cesiumMap ref="cesiumMap" :drawDomClick="drawDom || airspaceDrawDom"
:tool-mode="drawDom ? 'ranging' : (airspaceDrawDom ? 'airspace' : 'airspace')" :tool-mode="drawDom ? 'ranging' : (airspaceDrawDom ? 'airspace' : 'airspace')"
:scaleConfig="scaleConfig" :scaleConfig="scaleConfig"
:coordinateFormat="coordinateFormat"
@draw-complete="handleMapDrawComplete" @draw-complete="handleMapDrawComplete"
@drawing-points-update="missionDrawingPointsCount = $event" @drawing-points-update="missionDrawingPointsCount = $event"
@open-waypoint-dialog="handleOpenWaypointEdit" @open-waypoint-dialog="handleOpenWaypointEdit"
@ -563,6 +564,9 @@ export default {
showLandmark: true, showLandmark: true,
showRoute: true, showRoute: true,
//
coordinateFormat: 'dms', // 'decimal' 'dms'
menuItems: [], menuItems: [],
// //
@ -1794,8 +1798,8 @@ export default {
}, },
coordinateConversion() { coordinateConversion() {
this.$message.success('坐标换算'); this.coordinateFormat = this.coordinateFormat === 'decimal' ? 'dms' : 'decimal'
// this.$message.success(`坐标格式已切换为:${this.coordinateFormat === 'decimal' ? '十进制' : '度分秒'}`)
}, },
// //

Loading…
Cancel
Save