一个通用的feature 转wkt 不好写
昨天就遇到一个坑,wkt的格式定义没有圆,所以你在ol5中画出来了圆之后是不能和多边形一样直接转的。这里采用的是把圆转为多边形的方式来避免wkt不能定义圆,缺点当然就是圆变成了多边形。
import Circle from 'ol/geom/Circle';
import Polygon, { fromCircle } from 'ol/geom/Polygon';
import WKT from 'ol/format/WKT';
import Feature from 'ol/Feature';
public convertFeature2Wkt(feature): string {
const format = new WKT();
if (feature.getGeometry() instanceof Circle) {
return format.writeGeometry(fromCircle(feature.getGeometry(), 36, 90));
} else {
return format.writeFeature(feature);
}
}
以上,就到这里把
发表回复