I have a list of features and a vector layer and I need to know, whether each feature is within the bounds of the view of the map or not.
I'm using openlayers v3.9.0 and in the corresponding documentation there is a function containsExtent()
(link) which takes an extent and returns a boolean. Seems to be exactly the function I'm looking for. But an error is thrown saying that containsExtent is not a function.
Uncaught TypeError: extent.containsExtent is not a function
code snippet:
// someVectorSource is of type ol.source.Vector
// allMyFeatures is an array of features of type ol.Feature
var extent = someVectorSource.getExtent();
_.each(allMyFeatures, function(feature) {
if (extent.containsExtent(feature.getGeometry().getExtent())) {
// do something
}
});
What is the problem here?
If the is a better way, to get only those features which are within the extent, in a single call without iterating through the list, would be even better.
The correct syntax is:
ol.extent.containsExtent(extent, feature.getGeometry().getExtent())
If you look closer at the doc page, you'll see that the method is a static one, not part of a ol.Extent
object. FYI, there's no actual ol.Extent
object in ol3. It's just an array of 4 numbers. I think ol.Extent
is just a reference for the compiler.
HTH
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With