"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getOLStyleFunction = exports.setOLVectorLayerStyle = exports.getClusterSubFeatures = exports.isClusteredFeature = exports.DEFAULT_STYLE_KEY = void 0;
var ol_style_map_set_1 = require("./ol-style-map-set");
var common_1 = require("./common");
/**
 * @since 0.14
 */
exports.DEFAULT_STYLE_KEY = "default";
function isClusteredFeature(feature) {
    var _a;
    if ((_a = getClusterSubFeatures(feature)) === null || _a === void 0 ? void 0 : _a.length) {
        return true;
    }
    return false;
}
exports.isClusteredFeature = isClusteredFeature;
function getClusterSubFeatures(feature) {
    return feature.get("features");
}
exports.getClusterSubFeatures = getClusterSubFeatures;
/**
 * Sets the vector layer style for the given OpenLayers vector layer
 *
 * @since 0.13
 * @since 0.14 style now takes IVectorLayerStyle instead of IVectorFeatureStyle and accepts an optional cluster style
 * and layer can be either a vector layer or a vector tile layer
 */
function setOLVectorLayerStyle(layer, style, clusterStyle) {
    var olstyles = new ol_style_map_set_1.OLStyleMapSet(style, clusterStyle);
    layer.set(common_1.LayerProperty.VECTOR_STYLE, olstyles);
    var layerStyleFunc = function (feature) {
        //TODO: Perf opportunity, cache styles by type_filter|default. Of course, if we ever
        //decide to go for fully dynamic styles (where any property could be an expression to evaluate)
        //such styles are not candidates for caching.
        var sset = this;
        return sset.evaluateStyle(feature);
    }.bind(olstyles);
    layer.setStyle(layerStyleFunc);
}
exports.setOLVectorLayerStyle = setOLVectorLayerStyle;
/**
 * Gets the OL style function for the given style
 *
 * @param style
 * @param clusterStyle
 * @returns
 * @since 0.14
 */
function getOLStyleFunction(style, clusterStyle) {
    var olstyles = new ol_style_map_set_1.OLStyleMapSet(style, clusterStyle);
    var layerStyleFunc = function (feature) {
        //TODO: Perf opportunity, cache styles by type_filter|default. Of course, if we ever
        //decide to go for fully dynamic styles (where any property could be an expression to evaluate)
        //such styles are not candidates for caching.
        var sset = this;
        return sset.evaluateStyle(feature);
    }.bind(olstyles);
    return layerStyleFunc;
}
exports.getOLStyleFunction = getOLStyleFunction;
//# sourceMappingURL=ol-style-helpers.js.map