javascript - 使用一个点 wkt 作为一个带有 openlayers 的圆
问题描述
我正在寻找一种使用 Openlayers 在 WKT 格式中绘制圆圈的方法。我知道 WKT 标准不支持圆,但有人说你可以使用一个点 wkt 然后为它设置一个半径(对于 android,但也可能适用于其他东西)。因此,我的问题是,如果可能的话,我该如何在 Openlayers 中做到这一点?
链接到汤姆所说的https://stackoverflow.com/a/58430532
这就是我制作多边形的方式
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);
我在问这个问题,看看我是否可以使坐标的绘制/保存更简单。现在,我在字符串“coord1, coord2;”中有坐标。并且在使用多边形时必须将它们拆分,然后在保存坐标时将它们转换回该字符串格式。使用 wkt,我可以将字符串放入 Openlayers 函数中,然后我就完成了,如果我可以对圆圈做同样的事情,那就太好了。
我使用什么 Openlayers v6(一些版本)vanilla 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);
推荐阅读
- python - Python TypeError:“NoneType”对象不可下标-我在进行车道检测时遇到了这个问题
- android - 如何处理谷歌 Firestore 中的外键情况?
- python - Python UTF8 编码 2.7.5 / 3.8.5
- lua - Roblox 游戏内禁令系统
- rust - 过滤与迭代器中的模式匹配的值的惯用方法
- php - 拉拉维尔 | 无法获得针对*多个关键字*过滤的搜索结果 | 现在从表中返回所有
- javascript - 使用 JavaScript 更改 HTML 本地存储图标和暗模式
- c# - 除了使用 ContinueWith 方法之外,还有更好的方法来链接异步任务吗?
- javascript - 每次单击按钮时用JS更改图像
- java - 如何在发送文件后停止套接字自动关闭