我希望在开放式3中以足够的精度获得两点之间的距离。
答案 0 :(得分:2)
我将它实现为以下函数:
function getCoordsDistance(firstPoint, secondPoint, projection) {
projection = projection || 'EPSG:4326';
length = 0;
var sourceProj = mapObj.getView().getProjection();
var c1 = ol.proj.transform(firstPoint, sourceProj, projection);
var c2 = ol.proj.transform(secondPoint, sourceProj, projection);
var wgs84Sphere = new ol.Sphere(6378137);
length += wgs84Sphere.haversineDistance(c1, c2);
return length;
}