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, 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) } }