javascript - OpenLayers OpenMaps Circle 在地图上绘制时大小不正确
问题描述
我正在尝试在地图上绘制一个以 KM 为半径的圆圈。但是,圆圈的大小不正确。
如果调用plotPoint({'lat'=>35.055615,'lon'=>-85.311179,'radius'=>1000})
您可以看到显示了圆圈,但是,圆圈太小并不是很明显。
我通过访问验证了大小:
https://appelsiini.net/circles/?c=35.055615,-85.311179,1000
您可以看到圆圈更大并且包含更多区域。在示例中超越制造之路。
我知道我的版本更小,因为我一直在研究三边测量点。虽然我的点出现在正确的位置并且计算都是正确的,但从视觉上看,圆圈没有接触。
有谁知道为什么我的圈子变小了?
代码
let attribution = new ol.control.Attribution({
collapsible: true
});
let center = ol.proj.transform([center_point[0], center_point[1]], 'EPSG:4326', 'EPSG:3857');
let baseMapLayer = new ol.layer.Tile({
source: new ol.source.OSM()
});
let map_view = new ol.View({
center: center,
maxZoom: 18,
zoom: 12
});
let map = new ol.Map({
controls: ol.control.defaults({attribution: false}).extend([attribution]),
layers: [baseMapLayer],
loadTilesWhileAnimating: true,
target: 'map',
view: map_view,
});
let features = [];
let vectorSource = new ol.source.Vector({
projection: 'EPSG:4326'
});
let vectorLayer = new ol.layer.Vector({
source: vectorSource,
updateWhileAnimating: true,
updateWhileInteracting: true,
});
function buildFeature(point) {
console.log(point.lat, point.lon);
let feature = new ol.Feature({
geometry: new ol.geom.Point(ol.proj.transform([point.lon, point.lat], 'EPSG:4326', 'EPSG:3857')),
});
let circleStyle = new ol.style.Style({
geometry: function (feature) {
return new ol.geom.Circle(feature.getGeometry().getCoordinates(), point.radius);
},
stroke: new ol.style.Stroke({color: '#2E86C1', width: 2})
});
feature.setStyle(circleStyle);
return feature;
}
function plotPoint(point) {
vectorSource.addFeature(buildFeature(point));
map.addLayer(vectorLayer);
}
解决方案
推荐阅读
- python - 查找发送帖子请求的 url
- c# - DataGridViewImageColumn 背景为黑色
- rust - 在 Rust 的同一个 crate 文件中从另一个模块调用一个模块的函数
- swift - 如何在 Swift 中向 URL 目录添加附加值?
- audio - 关于客户端回声消除的建议
- php - PHP 调用私有方法 Kreait\Firebase\ServiceAccount::fromJsonFile() 错误
- python - 有没有办法在硒中一个一个地单击多个按钮的列表?
- swift - 单元测试 VIPER 协议
- r - 在 R Shiny 中下载反应表的输出
- sql - Oracle 配对记录的最佳方式