feat: 添加当前位置Marker,显示实时设计高度,完善地形图代码
This commit is contained in:
54
android/src/main/java/com/icegps/geotools/TriangleDisplay.kt
Normal file
54
android/src/main/java/com/icegps/geotools/TriangleDisplay.kt
Normal file
@@ -0,0 +1,54 @@
|
||||
package com.icegps.geotools
|
||||
|
||||
import com.icegps.geotools.ktx.toMapboxPoint
|
||||
import com.icegps.triangulation.Triangle
|
||||
import com.mapbox.geojson.Feature
|
||||
import com.mapbox.geojson.FeatureCollection
|
||||
import com.mapbox.geojson.LineString
|
||||
import com.mapbox.maps.MapView
|
||||
import com.mapbox.maps.extension.style.layers.addLayer
|
||||
import com.mapbox.maps.extension.style.layers.generated.lineLayer
|
||||
import com.mapbox.maps.extension.style.layers.properties.generated.LineJoin
|
||||
import com.mapbox.maps.extension.style.sources.addSource
|
||||
import com.mapbox.maps.extension.style.sources.generated.geoJsonSource
|
||||
|
||||
/**
|
||||
* @author tabidachinokaze
|
||||
* @date 2025/11/28
|
||||
*/
|
||||
fun MapView.displayTriangle(
|
||||
triangles: List<Triangle>,
|
||||
sourceId: String,
|
||||
layerId: String
|
||||
) {
|
||||
val features = triangles.map {
|
||||
listOf(it.x1, it.x2, it.x3)
|
||||
}.map {
|
||||
fromPoints(points = it, closed = true)
|
||||
}.map {
|
||||
it.map { line ->
|
||||
val lineA = line.a.toMapboxPoint()
|
||||
val lineB = line.b.toMapboxPoint()
|
||||
LineString.fromLngLats(listOf(lineA, lineB))
|
||||
}.map {
|
||||
Feature.fromGeometry(it)
|
||||
}
|
||||
}.flatten()
|
||||
mapboxMap.getStyle { style ->
|
||||
style.removeStyleLayer(layerId)
|
||||
style.removeStyleSource(sourceId)
|
||||
val source = geoJsonSource(sourceId) {
|
||||
featureCollection(FeatureCollection.fromFeatures(features))
|
||||
}
|
||||
style.addSource(source)
|
||||
|
||||
val layer = lineLayer(layerId, sourceId) {
|
||||
lineWidth(1.5)
|
||||
lineJoin(LineJoin.ROUND)
|
||||
lineOpacity(1.0)
|
||||
lineColor("#ff0000")
|
||||
}
|
||||
|
||||
style.addLayer(layer)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user