OpenLayers 3 - 给定特征的 getClosesPoint()

OpenLayers 3 - getClosesPoint() of a given feature

我查看了 this documentation 并试图获得最接近给定特征的特征,如下所示:

var foo = pretendLocation.getGeometry();
console.log(getClosestPoint(foo));

我也试过:

console.log(pretendLocation.getClosestPoint());

pretendLocation 是我这样创建的功能,

var pretendLocation = new ol.Feature({
            geometry: new ol.geom.Point(ol.proj.transform([-121, 37], 'EPSG:4326', 'EPSG:3857'))
        });

我使用 getClosestPoint() 不正确吗?我使用什么函数来获得最接近给定特征的特征?我搜索了其他帖子,但找不到解决方案。我从两种方式都收到控制台错误 - 未定义 getClosestPoint,以及无法读取 属性 of 0 错误。

如果您看到文档 getClosestPoint()ol.geom.Point 的 api。

因此需要使用 geom 对象引用调用它并 ol.Coordinate 传递给方法。 getClosestPoint() 将通过评估传递的坐标找到几何中的最近点。

var foo = pretendLocation.getGeometry();
console.log(foo.getClosestPoint([-121, 37]));

foo 是要素的几何图形。 [-121,37] 是搜索最近点的 ol.Coordinate