问题描述
我有一些功能需要在用户的视野内显示,我该怎么做Image of a polygon that needs to be removed if it is off-screen of the user?
解决方法
确定要素是否在视口中
var visibleExtent = map.getView().calculateExtent();
if (feature.getGeometry().intersectsExtent(visibleExtent)) {
// feature is visible to user
}
请注意,如果视图旋转,则可能会出现一些误报。它们可以通过测试旋转的几何形状和范围来消除,如本例所示 https://openlayers.org/en/latest/examples/box-selection.html