This commit is contained in:
2025-07-07 20:11:59 +08:00
parent ab0fdbc447
commit 06e3aa2eb3
2009 changed files with 193082 additions and 0 deletions

View File

@ -0,0 +1,26 @@
package turf
import (
_ "embed"
"github.com/dop251/goja"
)
//go:embed turf.min.js
var turf_min string
//go:embed turf.js
var turf string
var Tin func(wgs84 [][]string) [][]string
var BooleanPointInPolygon func(point []float64, polygon [][]float64) bool
//// 初始化
//func init() {
// InitTurfjs()
//}
func InitTurfjs() {
vm := goja.New()
vm.RunString(turf_min + turf)
vm.ExportTo(vm.Get("Tin"), &Tin)
vm.ExportTo(vm.Get("BooleanPointInPolygon"), &BooleanPointInPolygon)
}

View File

@ -0,0 +1,26 @@
function Tin(points=[]) {
let arr = []
points.forEach(p=>{
arr.push(turf.point( [parseFloat(p[0]), parseFloat(p[1])]))
})
var tin = turf.tin(turf.featureCollection(arr));
let polylines=[]
tin.features.forEach((feature, index) => {
feature.geometry.coordinates.forEach((coordinate,) => {
polylines.push([
coordinate[0],
coordinate[1],
coordinate[2],
])
})
})
return polylines
return JSON.stringify(polylines)
}
function BooleanPointInPolygon(point,polygon=[]) {
var pt = turf.point([point[0],point[1]]);
var poly = turf.polygon([polygon]);
var scaledPoly = turf.transformScale(poly, 2);
return turf.booleanPointInPolygon(pt, poly)
}

91
api/v1/common/tool/turf/turf.min.js vendored Normal file

File diff suppressed because one or more lines are too long