编辑地图

This commit is contained in:
yyy 2025-02-21 17:36:25 +08:00
parent a23543522b
commit ad59ca88b6
4 changed files with 64 additions and 50 deletions

View File

@ -4,7 +4,7 @@ NODE_ENV=development
VITE_DEV=true
# 请求路径
VITE_BASE_URL='http://192.168.0.66:48080'
VITE_BASE_URL='http://192.168.0.172:48080'
# VITE_BASE_URL='http://192.168.0.189:48080'
# 文件上传类型server - 后端上传, client - 前端直连上传,仅支持 S3 服务

View File

@ -229,10 +229,10 @@ const open = (item, list) => {
console.log(item)
form.value = item
form.value.layersNumber = item.dataList.length || ''
form.value.deviceId = item.deviceId || item.dataObj.id || ''
form.value.deviceId = item?.deviceId || item?.dataObj?.id || ''
form.value.positionMapId = props.positionMapId
equipmentList.value = list
if (item.dataObj.deviceType) {
if (item?.dataObj?.deviceType) {
deviceInfo.value.deviceType = item.dataObj.deviceType || ''
getDeviceList()
} else {

View File

@ -334,6 +334,7 @@
:width="imgBgObj.width"
:height="imgBgObj.height"
style="position: absolute; top: 0; left: 0; z-index: 9"
id="svgId"
>
<template v-for="(curve, index) in state.mapRouteList" :key="index">
<!-- 直线 -->
@ -379,6 +380,7 @@
stroke-width="2"
/>
<circle
id="startCircle"
:cx="curve.beginControlX"
:cy="curve.beginControlY"
r="5"
@ -386,6 +388,7 @@
@mousedown="startDrag(curve, index, 'start')"
/>
<circle
id="endCircle"
:cx="curve.endControlX"
:cy="curve.endControlY"
r="5"
@ -1484,11 +1487,16 @@ const startDrag = (item, index, type) => {
}
//
const handleDrag = (event) => {
const x = disposeEventPoints(event).x
const y = disposeEventPoints(event).y
let x = disposeEventPoints(event).x
let y = disposeEventPoints(event).y
if (state.currentDragTarget.index !== null) {
const curve = state.mapRouteList[state.currentDragTarget.index]
//
x = Math.max(0, Math.min(x, imgBgObj.width))
y = Math.max(0, Math.min(y, imgBgObj.height))
if (state.currentDragTarget.type === 'start') {
curve.beginControlX = x
curve.beginControlY = y
@ -1499,27 +1507,16 @@ const handleDrag = (event) => {
}
}
//
const endDrag = () => {
let actualBeginControl = disposeEventPoint(
state.mapRouteList[state.currentDragTarget.index].beginControlX,
state.mapRouteList[state.currentDragTarget.index].beginControlY
)
let actualEndControl = disposeEventPoint(
state.mapRouteList[state.currentDragTarget.index].endControlX,
state.mapRouteList[state.currentDragTarget.index].endControlY
)
const endDrag = (event) => {
const curve = state.mapRouteList[state.currentDragTarget.index]
let actualBeginControl = disposeEventPoint(curve.beginControlX, curve.beginControlY)
let actualEndControl = disposeEventPoint(curve.endControlX, curve.endControlY)
state.mapRouteList[state.currentDragTarget.index].actualBeginControlX =
actualBeginControl.actualLocationX
state.mapRouteList[state.currentDragTarget.index].actualBeginControlY =
actualBeginControl.actualLocationY
curve.actualBeginControlX = actualBeginControl.actualLocationX
curve.actualBeginControlY = actualBeginControl.actualLocationY
state.mapRouteList[state.currentDragTarget.index].actualEndControlX =
actualEndControl.actualLocationX
state.mapRouteList[state.currentDragTarget.index].actualEndControlY =
actualEndControl.actualLocationY
console.log(state.mapRouteList[state.currentDragTarget.index])
curve.actualEndControlX = actualEndControl.actualLocationX
curve.actualEndControlY = actualEndControl.actualLocationY
state.currentDragTarget = { index: null, type: null }
window.removeEventListener('mousemove', handleDrag)
@ -1545,7 +1542,6 @@ const handleEditRoute = (item, index) => {
}
//
const handleChooseRoute = (item, index) => {
console.log(item)
state.mapRouteList.forEach((curve, i) => {
curve.isSelected = i === index
})
@ -1699,6 +1695,8 @@ const getAllNodeList = async () => {
positionMapId: imgBgObj.positionMapId
})
allMapPointInfo.value = []
allHistoryList.value = []
currentIndex.value = 0
list.forEach((item) => {
item.layerSelectionShow = true //
item.locationX = Number(item.locationX)
@ -1816,7 +1814,6 @@ const saveNodeList = async () => {
const saveMapRoute = async () => {
await MapApi.createOrEditOrDelPositionMapLine(imgBgObj.positionMapId, state.mapRouteList)
}
//
const layerSelectionSuccess = (typeList) => {
allHistoryList.value[currentIndex.value].forEach((item) => {
@ -1828,13 +1825,13 @@ const layerSelectionSuccess = (typeList) => {
}
})
}
//
const disposeEventPoints = (event) => {
const rect = mapBackgroundRef.value.getBoundingClientRect()
const scrollLeft = mapBackgroundRef.value.scrollLeft //
const scrollTop = mapBackgroundRef.value.scrollTop //
const devicePixelRatio = window.devicePixelRatio || 1
// const devicePixelRatio = window.devicePixelRatio || 1 //
const devicePixelRatio = 1
//
const x = (event.clientX - rect.left + scrollLeft) / state.imageChangeMultiple / devicePixelRatio

View File

@ -1,6 +1,6 @@
<template>
<div>
<svg width="800" height="600">
<div class="box">
<svg :width="boxWidth" :height="boxHeight">
<path
v-for="(curve, index) in curves"
:key="index"
@ -13,8 +13,8 @@
<circle
v-for="(curve, index) in curves"
:key="'start-' + index"
:cx="curve.beginControlX"
:cy="curve.beginControlY"
:cx="curve.startControlX"
:cy="curve.startControlY"
r="5"
fill="green"
@mousedown="startDrag(index, 'start')"
@ -35,28 +35,32 @@
<script setup>
import { ref } from 'vue'
//
const boxWidth = ref(800)
const boxHeight = ref(600)
//
const curves = ref([
{
startPointX: 100,
startPointY: 100,
endPointX: 300,
endPointY: 100,
beginControlX: 100,
beginControlY: 100,
startX: 100,
startY: 100,
endX: 300,
endY: 100,
startControlX: 100,
startControlY: 100,
endControlX: 300,
endControlY: 100,
isSelected: false
},
{
startPointX: 200,
startPointY: 200,
endPointX: 400,
endPointY: 200,
beginControlX: 200,
beginControlY: 200,
startX: 200,
startY: 200,
endX: 400,
endY: 200,
startControlX: 200,
startControlY: 200,
endControlX: 400,
endControlY: 200,
endControlY: 400,
isSelected: false
}
])
@ -69,7 +73,7 @@ const dragging = ref({
// 线
const getCurvePath = (curve) => {
return `M${curve.startPointX},${curve.startPointY} C${curve.beginControlX},${curve.beginControlY} ${curve.endControlX},${curve.endControlY} ${curve.endPointX},${curve.endPointY}`
return `M${curve.startX},${curve.startY} C${curve.startControlX},${curve.startControlY} ${curve.endControlX},${curve.endControlY} ${curve.endX},${curve.endY}`
}
// 线
@ -91,12 +95,19 @@ const startDrag = (index, type) => {
const handleDrag = (event) => {
if (dragging.value.index !== null) {
const curve = curves.value[dragging.value.index]
let newX = event.offsetX
let newY = event.offsetY
//
newX = Math.max(0, Math.min(newX, boxWidth.value))
newY = Math.max(0, Math.min(newY, boxHeight.value))
if (dragging.value.type === 'start') {
curve.beginControlX = event.offsetX
curve.beginControlY = event.offsetY
curve.startControlX = newX
curve.startControlY = newY
} else {
curve.endControlX = event.offsetX
curve.endControlY = event.offsetY
curve.endControlX = newX
curve.endControlY = newY
}
}
}
@ -108,3 +119,9 @@ const endDrag = () => {
window.removeEventListener('mouseup', endDrag)
}
</script>
<style scoped>
.box {
border: 1px solid black;
}
</style>