This commit is contained in:
BianLzhaoMin 2025-10-24 15:39:25 +08:00
parent 9fe54cd44c
commit 13fe0cbb99
1 changed files with 117 additions and 1 deletions

View File

@ -317,6 +317,8 @@ export default {
.then((res) => { .then((res) => {
this.modelPreviewInfoList = res.data this.modelPreviewInfoList = res.data
this.modelPreviewVisible = true this.modelPreviewVisible = true
console.log('res', res.data)
this.initMap() this.initMap()
}) })
.catch((err) => { .catch((err) => {
@ -693,8 +695,49 @@ export default {
this.map.clearOverlays() this.map.clearOverlays()
for (const item of modelInfoList) { for (const item of modelInfoList) {
console.log(item, 'item')
try { try {
if (item.entityType === 'LINE') { // LWPOLYLINE
if (item.entityType === 'LWPOLYLINE') {
console.log('处理LWPOLYLINE:', item)
const pointList = JSON.parse(item.geometry)
if (pointList.points && pointList.points.length > 0) {
//
const pointsWithAngles = pointList.points.map((point) => {
const [lng, lat, , , angle] = point //
return {
point: new BMapGL.Point(lng, lat),
angle: angle || 40, //
}
})
console.log(pointsWithAngles, 'pointsWithAngles')
// 线
const getColorByIndex = (colorIndex) => {
const colors = ['red', 'yellow', 'green', 'cyan', 'blue', 'magenta', 'white', 'gray']
return colors[colorIndex] || 'red'
}
// 0-7
const colorIndex = Math.floor(Math.random() * 7)
// 线
const curvedLinePoints = this.createCurvedLine(pointsWithAngles)
// 线
const polyline = new BMapGL.Polyline(curvedLinePoints, {
strokeColor: getColorByIndex(colorIndex),
strokeWeight: 2,
strokeOpacity: 0.8,
strokeStyle: 'solid',
})
this.map.addOverlay(polyline)
}
} else if (item.entityType === 'LINE') {
const geometry = JSON.parse(item.geometry) const geometry = JSON.parse(item.geometry)
const start = geometry.start const start = geometry.start
const end = geometry.end const end = geometry.end
@ -725,6 +768,8 @@ export default {
// //
const pointList = JSON.parse(item.geometry) const pointList = JSON.parse(item.geometry)
console.log(pointList, 'pointList')
if (pointList.points.length > 0) { if (pointList.points.length > 0) {
// [x, y, ..., angle] // [x, y, ..., angle]
const path = pointList.points.map((p) => { const path = pointList.points.map((p) => {
@ -829,6 +874,77 @@ export default {
}) })
} }
}, },
// 线
createCurvedLine(pointsWithAngles) {
if (pointsWithAngles.length < 2) {
return pointsWithAngles.map((p) => p.point)
}
const curvedPoints = []
for (let i = 0; i < pointsWithAngles.length - 1; i++) {
const currentPoint = pointsWithAngles[i]
const nextPoint = pointsWithAngles[i + 1]
//
curvedPoints.push(currentPoint.point)
//
if (currentPoint.angle !== 0) {
const controlPoints = this.generateCurveControlPoints(
currentPoint.point,
nextPoint.point,
currentPoint.angle,
)
curvedPoints.push(...controlPoints)
}
}
//
curvedPoints.push(pointsWithAngles[pointsWithAngles.length - 1].point)
return curvedPoints
},
// 线
generateCurveControlPoints(startPoint, endPoint, angle) {
const controlPoints = []
const segments = 5 // 5线
//
const distance = this.calculateDistance(startPoint, endPoint)
//
const radius = Math.abs(distance * 0.3) // 30%
for (let i = 1; i < segments; i++) {
const t = i / segments // (0-1)
// 线
const baseLng = startPoint.lng + (endPoint.lng - startPoint.lng) * t
const baseLat = startPoint.lat + (endPoint.lat - startPoint.lat) * t
//
const offsetDistance = radius * Math.sin(t * Math.PI) // 使
const offsetLng = offsetDistance * Math.cos(angle) * 0.0001 //
const offsetLat = offsetDistance * Math.sin(angle) * 0.0001 //
//
const controlPoint = new BMapGL.Point(baseLng + offsetLng, baseLat + offsetLat)
controlPoints.push(controlPoint)
}
return controlPoints
},
//
calculateDistance(point1, point2) {
const dx = point2.lng - point1.lng
const dy = point2.lat - point1.lat
return Math.sqrt(dx * dx + dy * dy)
},
}, },
} }
</script> </script>