I created a vector layer called "locationGeoJSON" in OpenLayers using a GeoJSON file and I'm trying to use the .getSource() method to access the location data for the layer. I'm currently using a workaround where I access the location data with locationGeoJSON.getSource().Uu. But I feel like there's some get method that can be used to retrieve the data in a more appropriate manner. I've tried using locationGeoJSON.getSource().getFeatures(), but I just get an empty array in return. Can anyone give some insight into this issue? Here is the console output after I use .getSource() on my vector layer. How do I access the "Uu" property?
locationGeoJSON.getSource().getFeatures() is correct, but you may have to wait for the geojson file to load before calling it.
locationGeoJSON.getSource().on('featuresloadend', function (evt) {
console.log(evt.target.getFeatures());
});
The object in the console output already has the features because it is linked to the original object and refreshes whenever its state changes.