我查看了这份文件,并试图获得与给定特性最接近的特性,如下所示:
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错误的属性。
发布于 2017-03-28 05:42:04
如果您看到文档,getClosestPoint()是ol.geom.Point的api。
因此,需要使用geom对象引用调用它,并将ol.Coordinate传递给该方法。getClosestPoint()将通过计算所传递的坐标来找到几何学中最接近的点。
var foo = pretendLocation.getGeometry();
console.log(foo.getClosestPoint([-121, 37]));foo是特征的几何图形。[-121,37]是搜索最近点的ol.Coordinate。
https://stackoverflow.com/questions/43055401
复制相似问题