fix: 修改普通交限的显示

This commit is contained in:
2023-05-26 13:46:32 +08:00
parent 12e9fd1a2a
commit 22f52429f4
5 changed files with 52 additions and 11 deletions

View File

@@ -131,7 +131,7 @@
"k": "geometry",
"v": "~",
"klib": "geometry",
"vlib": "translateRight()"
"vlib": "translateRightWithAngle()"
}
]
},

View File

@@ -5,6 +5,7 @@ import com.navinfo.collect.library.utils.GeometryTools
import org.locationtech.jts.algorithm.Angle
import org.locationtech.jts.geom.Coordinate
import org.locationtech.jts.geom.Geometry
import org.oscim.core.GeoPoint
class ImportPreProcess {
@@ -37,8 +38,8 @@ class ImportPreProcess {
}
// 计算偏移距离
val dx: Double = GeometryTools.convertDistanceToDegree(5.0, geometry?.coordinate?.y!!) * Math.cos(radian)
val dy: Double = GeometryTools.convertDistanceToDegree(5.0, geometry?.coordinate?.y!!) * Math.sin(radian)
val dx: Double = GeometryTools.convertDistanceToDegree(3.0, geometry?.coordinate?.y!!) * Math.cos(radian)
val dy: Double = GeometryTools.convertDistanceToDegree(3.0, geometry?.coordinate?.y!!) * Math.sin(radian)
// 计算偏移后的点
val coord =
@@ -50,6 +51,42 @@ class ImportPreProcess {
return renderEntity
}
/**
* 将要素按照点位角度的垂直方向右移5米并生成一个按照垂直角度指向方向的线段用以显示有方向的图标
* */
fun translateRightWithAngle(renderEntity: RenderEntity): RenderEntity {
// 获取当前renderEntity的geometry
val geometry = renderEntity.wkt
var radian = 0.0 // geometry的角度如果是点获取angle如果是线获取最后两个点的方向
var point = Coordinate(geometry?.coordinate)
if (Geometry.TYPENAME_POINT == geometry?.geometryType) {
val angle = if(renderEntity?.properties?.get("angle") == null) 0.0 else renderEntity?.properties?.get("angle")?.toDouble()!!
radian = Math.toRadians(angle)
} else if (Geometry.TYPENAME_LINESTRING == geometry?.geometryType) {
val p1: Coordinate = geometry.coordinates.get(geometry.coordinates.size - 2)
val p2: Coordinate = geometry.coordinates.get(geometry.coordinates.size - 1)
// 计算线段的方向
radian = Angle.angle(p1, p2)
point = p2
}
// 根据角度计算偏移距离
val dx: Double = GeometryTools.convertDistanceToDegree(3.0, geometry?.coordinate?.y!!) * Math.cos(radian)
val dy: Double = GeometryTools.convertDistanceToDegree(3.0, geometry?.coordinate?.y!!) * Math.sin(radian)
// 计算偏移后的点
// val coordMid =
// Coordinate(point.getX() + dy, point.getY() - dx)
val pointStart = GeoPoint(point.getY() - dx, point.getX() + dy)
// val pointStart = GeoPoint(pointMid.latitude-dy, pointMid.longitude-dx)
val pointEnd = GeoPoint(pointStart.latitude- dx, pointStart.longitude+ dy)
// 将这个线记录在数据中
val geometryTranslate: Geometry = GeometryTools.createLineString(listOf(pointStart, pointEnd))
renderEntity.geometry = geometryTranslate.toString()
return renderEntity
}
fun addAngleFromGeometry(renderEntity: RenderEntity): String {
if (!renderEntity.properties.containsKey("angle")) {
if (renderEntity.wkt!=null) {