2016-09-28 116 views
2

我有一些多边形geojson,添加它作为一个来源,并创建一个图层显示mapbox地图上的这些功能。是否可以检查一个点是否在geojson的多边形内?

由于我使用这种方法:(编辑从样品烃源:MapboxGLAndroidSDKTestApp

final PointF pixel = mapboxMap.getProjection().toScreenLocation(point); 
        List<Feature> fList = mapboxMap.queryRenderedFeatures(pixel, "polygons"); 
        for(Feature feature:fList){ 
         Log.d(TAG,"FeatureInfo: "+feature.toJson()); 
        } 

我可以检查标记是内部那些多边形之一通过使标记位置到它。

但是,当我将我的相机很远的地方标记,多边形不会呈现和检查者不再工作。

所以我的问题是,有没有什么办法来检查,如果该标志是多边形,这无论在哪里我的相机指着里面?

回答

1

要检查点是否说谎或不是多边形内部的mapbox 可以使用turf.js库http://turfjs.org/

这是你并不需要绘制在mapbox点或多边形的方式(不绘制)。

var point = turf.point([-75.343, 39.984]); 
// here first is lng and then lat 
var polygon = turf.polygon([[ 
    [-2.275543, 53.464547], 
    [-2.275543, 53.489271], 
    [-2.215118, 53.489271], 
    [-2.215118, 53.464547], 
    [-2.275543, 53.464547] 
]], { name: 'poly1'}); 
// here first is lng and then lat 

现在可以在里面使用的方法从草坪的lib 即turf.inside(point, polygon); // return boolean True/False

相关问题