function setStyleOpacities(map, styleOpacities, factorKey) {
    let factor, prop;

    for (const {id, key, opacity, metadata} of styleOpacities) {
        if (Array.isArray(factorKey)) {
            factor = factorKey.reduce((value, key) => valueOrDefault(value, metadata[key]), undefined);
        } else {
            factor = metadata[factorKey];
        }

        if (key) {
            if (Array.isArray(opacity)) {
                prop = map.getPaintProperty(id, key);
                for (const {index, value} of opacity) {
                    const scaledOpacity = value * factor;

                    if (prop.stops) {
                        prop.stops[index][1] = scaledOpacity;
                    } else {
                        prop[index] = scaledOpacity;
                    }
                }
            } else {
                prop = opacity * factor;
            }
            map.setPaintProperty(id, key, prop);
        } else {
            setLayerProps(map, id, {opacity: factor});
        }
    }
}
Sets style opacities based on the style opacity objects and factor
@param {mapboxgl.Map} map - Mapbox's Map object
@param {Array<Object>} styleOpacities - Array of the style opacity objects
@param {string | Array<string>} factorKey - Metadata key for the factor to multiply