featureOf
函数用于断言一个要素是否属于某个图层中(即该图层是否具有该要素)。
turf.featureOf(feature, layer)
feature
:传入一个Feature
类型的对象。layer
:传入一个FeatureCollection
类型的对象,表示某一图层。如果该图层包含该要素,则返回true
,否则返回false
。
var pt = {
"type": "Feature",
"properties": {
"marker-color": "#0F0"
},
"geometry": {
"type": "Point",
"coordinates": [-77.032, 38.913]
}
};
var polygons = {
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"properties": {
"fill": "#0F0"
},
"geometry": {
"type": "Polygon",
"coordinates": [[
[-77.032, 38.913],
[-77.024, 38.913],
[-77.024, 38.916],
[-77.032, 38.916],
[-77.032, 38.913]
]]
}
}]
};
// 判断pt是否属于polygons图层
var isContained = turf.featureOf(pt, polygons); // true