关键词:leaflet; WKT; terraformer-wkt-parser
将leaflet L.polyline、L.polygon类型的图层转换为wkt格式。
1.引入插件
import WKT from "terraformer-wkt-parser"
2.示例
let latlngs = [
[ // first polygon
[[37, -109.05],[41, -109.03],[41, -102.05],[37, -102.04]], // outer ring
[[37.29, -108.58],[40.71, -108.58],[40.71, -102.50],[37.29, -102.50]] // hole
],
[ // second polygon
[[41, -111.03],[45, -111.04],[45, -104.05],[41, -104.05]]
]
];
let layer= L.polygon(latlngs, {color: 'red'});
let wktString = WKT.convert(layer.toGeoJSON().geometry);
console.log(wktString);