Linked Questions

Popular Questions

Get KML style in OpenLayers 5

Asked by At

I have some code in an application that access the style of a selected feature in a KML layer. It was working in OpenLayers 3.1. I have now upgraded to 5.3.0 and it stopped working. See the relevant lines below:

var featStyle = feature.getStyleFunction().call(feature, map.getView().getResolution());
var strokeWidth = featStyle[0].getStroke().getWidth();
var strokeColor = featStyle[0].getStroke().getColor();
var fillColor = featStyle[0].getFill().getColor();
var fillOpacity = (Math.round(fillColor[3] * 100));

The line:

var featStyle = feature.getStyleFunction().call(feature, map.getView().getResolution());

Produces an error visible in the developer console:

TypeError: o.getGeometry is not a function[Learn More] KML.js:943
    a KML.js:943
    myFunctionName file.php:5371
    onclick file.php:1

I can't find anything in the documentation or examples that shows how to properly access the KML style data for a given feature (not an entire layer/source). Is there a new way to do this or did I miss something?

Could it have to do with this?: Plugged into Google translate it seems to say something about no longer storing style properties inside each feature but it does not seem to say where they are stored...

The KML is valid and displays on the map properly. I just can't seem to find a way to access the style data anymore.

Related Questions