初始
This commit is contained in:
26
api/v1/common/tool/turf/turf.go
Normal file
26
api/v1/common/tool/turf/turf.go
Normal 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)
|
||||
}
|
26
api/v1/common/tool/turf/turf.js
Normal file
26
api/v1/common/tool/turf/turf.js
Normal 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
91
api/v1/common/tool/turf/turf.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user