ERROR Error: Uncaught (in promise): TypeError:
vectorLayer.getSource(...).getFeatures(...)[i].getStyle(...).getStroke is not a function
I'm trying to get the color of a feature, but I'm getting this error. This is what I'm doing:
for (let i = vectorLayer.getSource().getFeatures().length - 1; i >= 0; i--) {
arrayOfColors.push({
feature_color: vectorLayer.getSource().getFeatures()[i].getStyle().getStroke().getColor()
});
}
This is working until getStyle(), which returns a style function f (feature, resolution). I found this a little odd, because I thought that was why the getStyleFunction() function had been done. The features are imported from KML files using the same method as the example provided from OL, which sets the style automatically based on the feature style in the file. From the documentation I see that what returns from the getStyle() function is this:
Get the feature's style. Will return what was provided to the module:ol/Feature~Feature#setStyle method.
What am I doing wrong? Did I get confused in any way regarding the method of obtaining the color or style? Is there a simpler way to achieve this goal?
I'm using OpenLayers v5.3