From 52a8d2598e536db59eb900211f0521a67af764e1 Mon Sep 17 00:00:00 2001 From: suixy <2277317060@qq.com> Date: Fri, 19 Sep 2025 17:31:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/ruler-1.vue | 410 +++++++++++++++++++++++++++++++++++++ src/components/ruler.vue | 61 ++++-- src/views/index.vue | 4 +- 3 files changed, 456 insertions(+), 19 deletions(-) create mode 100644 src/components/ruler-1.vue diff --git a/src/components/ruler-1.vue b/src/components/ruler-1.vue new file mode 100644 index 0000000..044b34b --- /dev/null +++ b/src/components/ruler-1.vue @@ -0,0 +1,410 @@ + + + + + \ No newline at end of file diff --git a/src/components/ruler.vue b/src/components/ruler.vue index c0a46d5..016d881 100644 --- a/src/components/ruler.vue +++ b/src/components/ruler.vue @@ -13,7 +13,7 @@ left: lineCoordinates.startX + 'px', bottom: lineCoordinates.startY + 'px', width: lineCoordinates.width + 'px', - transform: `translateY(50%) rotate(${lineCoordinates.angle}deg) scaleY(${1/scale})`, + transform: `translateY(-50%) rotate(${lineCoordinates.angle}deg) scaleY(${1/scale})`, transformOrigin: 'left center' }" > @@ -82,9 +82,9 @@ const props = defineProps({ dotIndex: Number }) setInterval(() => { - props.boxPos.x += (-0.001 + (Math.random() * 0.002)) - props.boxPos.y += (-0.001 + (Math.random() * 0.002)) - props.boxPos.rotate += (-25 + (Math.random() * 50)) + // props.boxPos.x += (-0.001 + (Math.random() * 0.002)) + // props.boxPos.y += (-0.001 + (Math.random() * 0.002)) + props.boxPos.rotate += (-0 + (Math.random() * 50)) }, 1000) const wrapperRef = ref(null) const parentWidth = ref(0) @@ -215,37 +215,62 @@ const boxContentY = computed(() => { if (!props.boxPos) return 0 return latToPixel(props.boxPos.y) }) -const lineCoordinates = computed(() => { - if (!props.boxPos || !props.dots || props.dotIndex === undefined) return null +const BOX_SIZE = 30 // 与 .box 的 width/height 保持一致 +const DOT_SIZE = 10 // 与 .dot 的 width/height 保持一致 +const lineCoordinates = computed(() => { + if (!props.boxPos || !props.dots || props.dotIndex == null) return null const startDot = props.dots[props.dotIndex] if (!startDot) return null + // dot center const startX = lonToPixel(startDot.lon) - const startY = latToPixel(startDot.lat) + const startY = latToPixel(startDot.lat) - (DOT_SIZE / 2) * (1 / scale.value) + + // box 底边中点 + const boxBottomX = lonToPixel(props.boxPos.x) + const boxBottomY = latToPixel(props.boxPos.y) - 15 + + // 换算成 box 中心点 + const centerX = boxBottomX + const centerY = boxBottomY + (BOX_SIZE / 2) * (1 / scale.value) + + const carHeadOffset = BOX_SIZE * 0.5 + + const localAttachX = 0 + const localAttachY = carHeadOffset + + const ox = localAttachX * (1 / scale.value) + const oy = localAttachY * (1 / scale.value) + + const rotDeg = props.boxPos.rotate || 0 + const rad = -rotDeg * Math.PI / 180 + + const rotatedX = ox * Math.cos(rad) - oy * Math.sin(rad) + const rotatedY = ox * Math.sin(rad) + oy * Math.cos(rad) + + const endX = centerX + rotatedX + const endY = centerY + rotatedY - const endX = lonToPixel(props.boxPos.x) - const endY = latToPixel(props.boxPos.y) + 15 const dx = endX - startX const dy = endY - startY - const width = Math.hypot(dx, dy) - const angle = Math.atan2(dx, dy) * 180 / Math.PI - 90 + const angle = -Math.atan2(dy, dx) * 180 / Math.PI - return {startX, startY, width, angle} + return {startX, startY, width, angle, endX, endY} }) defineExpose({setZoom}) // 测试缩放 -// setTimeout(() => { -// setZoom({lon: 120.005, lat: 30.005}, 2) -// }, 3000) -// setTimeout(() => { -// setZoom({lon: 120.005, lat: 30.005}, 3) -// }, 5000) +setTimeout(() => { + setZoom({lon: 120.005, lat: 30.005}, 2) +}, 3000) +setTimeout(() => { + setZoom({lon: 120.005, lat: 30.005}, 3) +}, 5000) // setTimeout(() => { // setZoom({lon: 120.005, lat: 30.005}, 2) // }, 8000) diff --git a/src/views/index.vue b/src/views/index.vue index ffbf84e..f018e10 100644 --- a/src/views/index.vue +++ b/src/views/index.vue @@ -76,12 +76,14 @@ const LEFT = defineComponent({ ref={rulerRef} index={dotIndex.value} dots={dots.value} - dotIndex={3} + dotIndex={1} boxPos={boxPos.value} minlon={120} maxlon={120.01} minlat={30} maxlat={30.01} + rightBottomLocation={{lon: 120.01, lat: 30.01}} + bottomScaleStep={10} /> )