This commit is contained in:
BianLzhaoMin 2025-11-04 09:36:40 +08:00
parent 974a12ec82
commit 9400e5e138
1 changed files with 148 additions and 29 deletions

View File

@ -698,45 +698,94 @@ export default {
console.log(item, 'item')
try {
// LWPOLYLINE
if (item.entityType === 'LWPOLYLINE') {
console.log('处理LWPOLYLINE:', item)
const pointList = JSON.parse(item.geometry)
console.log(pointList, 'pointList')
const newPointList = pointList?.segments
console.log(newPointList, 'newPointList')
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),
// newPointList type线
newPointList.forEach((item) => {
if (item.type === 'line') {
const line = new BMapGL.Polyline(
[
new BMapGL.Point(item.start[0], item.start[1]),
new BMapGL.Point(item.end[0], item.end[1]),
],
{
strokeColor: 'red',
strokeWeight: 2,
strokeOpacity: 0.8,
strokeStyle: 'solid',
},
)
this.map.addOverlay(line)
} else if (item.type === 'arc') {
console.log('画半圆', item)
// 线
if (item.start_point && item.end_point && item.center && item.radius) {
const arcPoints = this.generateArcPoints(
item.center,
item.radius,
item.start_point,
item.end_point,
)
const arcPolyline = new BMapGL.Polyline(arcPoints, {
strokeColor: 'red',
strokeWeight: 2,
strokeOpacity: 0.8,
})
this.map.addOverlay(arcPolyline)
} else {
//
const circle = new BMapGL.Circle(
new BMapGL.Point(item.center[0], item.center[1]),
item.radius,
{
strokeColor: 'red',
strokeWeight: 2,
fillColor: 'rgba(0,0,255,0.3)',
},
)
this.map.addOverlay(circle)
}
}
})
this.map.addOverlay(polyline)
}
// 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 start = geometry.start
@ -945,6 +994,76 @@ export default {
const dy = point2.lat - point1.lat
return Math.sqrt(dx * dx + dy * dy)
},
// 线
generateArcPoints(center, radius, startPoint, endPoint) {
// BMapGL.Point
const centerPoint = Array.isArray(center) ? new BMapGL.Point(center[0], center[1]) : center
const start = Array.isArray(startPoint) ? new BMapGL.Point(startPoint[0], startPoint[1]) : startPoint
const end = Array.isArray(endPoint) ? new BMapGL.Point(endPoint[0], endPoint[1]) : endPoint
//
const startAngle = Math.atan2(start.lat - centerPoint.lat, start.lng - centerPoint.lng)
const endAngle = Math.atan2(end.lat - centerPoint.lat, end.lng - centerPoint.lng)
//
let angleDiff = endAngle - startAngle
// [-π, π]
if (angleDiff > Math.PI) {
angleDiff -= 2 * Math.PI
} else if (angleDiff < -Math.PI) {
angleDiff += 2 * Math.PI
}
//
// π180
if (Math.abs(angleDiff) > Math.PI) {
angleDiff = angleDiff > 0 ? angleDiff - 2 * Math.PI : angleDiff + 2 * Math.PI
}
//
//
// 11111111*cos(lat)
const latRad = (centerPoint.lat * Math.PI) / 180
const metersPerDegreeLat = 111000 // 111
// >1<0.1
// 1
let radiusInDegrees = radius
if (radius > 1) {
//
radiusInDegrees = radius / metersPerDegreeLat
}
//
const arcPoints = []
//
const segments = Math.max(30, Math.abs(angleDiff) * 30)
//
arcPoints.push(start)
//
for (let i = 1; i < segments; i++) {
const t = i / segments // (0-1)
const angle = startAngle + angleDiff * t
//
// 使
const deltaLng = (radiusInDegrees * Math.cos(angle)) / Math.cos(latRad)
const deltaLat = radiusInDegrees * Math.sin(angle)
const x = centerPoint.lng + deltaLng
const y = centerPoint.lat + deltaLat
arcPoints.push(new BMapGL.Point(x, y))
}
//
arcPoints.push(end)
return arcPoints
},
},
}
</script>