2017-03-27 54 views
0

我看this documentation和getClosesPoint()想获得最接近的功能,以给定的特征是这样的:的OpenLayers 3 - 一个给定的特征

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未定义,以及无法读取0错误的属性。

回答

2

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

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

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

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

相关问题