在露天层中的拖曳点之间的距离为3米

时间:2016-12-31 05:43:19

标签: javascript distance openlayers-3

我希望在开放式3中以足够的精度获得两点之间的距离。

1 个答案:

答案 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;
}