使用 point wkt 作为带有 openlayers 的圆
Use a point wkt as a circle with openlayers
我正在寻找一种使用 Openlayers 在 WKT 格式内绘制圆圈的方法。我知道 WKT 标准不支持圆,但有人说您可以使用点 wkt 然后为其设置半径(对于 android 但也可能适用于其他事物)。因此,我的问题是,如果可能的话,我该如何在 Openlayers 中做到这一点?
link 汤姆说的
这就是我制作多边形的方法
let polyFeature = new ol.format.WKT().readFeature(polygonWKT, {
// Must use both projections in order to draw the feature with the wkt format
dataProjection : "EPSG:4326",
featureProjection: map.getView().getProjection() // Can at least get the standard projection and not have to fiddle with that
});
vectorSource.addFeature(polyFeature);
我问这个问题是想看看能不能把坐标的drawing/saving简化一下。现在,我在字符串“coord1, coord2;”中有坐标。并且在使用多边形时必须拆分它们,然后在保存坐标时将它们转换回该字符串格式。
使用 wkt,我可以将字符串放入 Openlayers 函数中,我已经完成了,如果我可以对圆做同样的事情,那就太好了。
我用什么
Openlayers v6(某些版本)
香草 js,php
如果您总是将 wkt 包装在 JSON
'{"wkt":"POINT(28.625360369528934 77.2227479486792)"}'
您可以选择添加半径来表示圆
'{"wkt":"POINT(28.625360369528934 77.2227479486792)","radius":50}'
然后 OpenLayers 可以解析 JSON 字符串并将带有半径的点转换为圆
let json = JSON.parse(jsonString);
let polyFeature = new ol.format.WKT().readFeature(json.wkt, {
dataProjection : "EPSG:4326",
featureProjection: map.getView().getProjection()
});
if (json.radius && polyFeature.getGeometry().getType() === 'Point') {
polyFeature.setGeometry(new ol.geom.Circle(polyFeature.getGeometry().getCoordinates(), json.radius));
}
vectorSource.addFeature(polyFeature);
我正在寻找一种使用 Openlayers 在 WKT 格式内绘制圆圈的方法。我知道 WKT 标准不支持圆,但有人说您可以使用点 wkt 然后为其设置半径(对于 android 但也可能适用于其他事物)。因此,我的问题是,如果可能的话,我该如何在 Openlayers 中做到这一点?
link 汤姆说的
这就是我制作多边形的方法
let polyFeature = new ol.format.WKT().readFeature(polygonWKT, {
// Must use both projections in order to draw the feature with the wkt format
dataProjection : "EPSG:4326",
featureProjection: map.getView().getProjection() // Can at least get the standard projection and not have to fiddle with that
});
vectorSource.addFeature(polyFeature);
我问这个问题是想看看能不能把坐标的drawing/saving简化一下。现在,我在字符串“coord1, coord2;”中有坐标。并且在使用多边形时必须拆分它们,然后在保存坐标时将它们转换回该字符串格式。 使用 wkt,我可以将字符串放入 Openlayers 函数中,我已经完成了,如果我可以对圆做同样的事情,那就太好了。
我用什么 Openlayers v6(某些版本) 香草 js,php
如果您总是将 wkt 包装在 JSON
'{"wkt":"POINT(28.625360369528934 77.2227479486792)"}'
您可以选择添加半径来表示圆
'{"wkt":"POINT(28.625360369528934 77.2227479486792)","radius":50}'
然后 OpenLayers 可以解析 JSON 字符串并将带有半径的点转换为圆
let json = JSON.parse(jsonString);
let polyFeature = new ol.format.WKT().readFeature(json.wkt, {
dataProjection : "EPSG:4326",
featureProjection: map.getView().getProjection()
});
if (json.radius && polyFeature.getGeometry().getType() === 'Point') {
polyFeature.setGeometry(new ol.geom.Circle(polyFeature.getGeometry().getCoordinates(), json.radius));
}
vectorSource.addFeature(polyFeature);