import mapboxgl from 'mapbox-gl' ; import { hexToHSL } from './colorFormat' ; import { WeightTemplateProperty } from './map-styling/macgyver/weightTemplate' ; export enum ColorType { fill = 'fill-color' , line = 'line-color' , text = 'text-color' , background = 'background-color' , textHalo = 'text-halo-color' , icon = 'icon-opacity' } export enum WeightType { line = 'line-width' , textHalo = 'text-halo-width' } interface ApplyProps { map : mapboxgl . Map ; layerNames : string [ ] ; color ? : string ; type ? : StyleTypes ; saturation ? : number ; lightness ? : number ; weight ? : number | WeightTemplateProperty [ ] ; visibility ? : string ; } export enum VisibilityType { visible = 'visible' , inherit = 'inherit' , none = 'none' } export type StyleTypes = VisibilityType | ColorType | WeightType ; export function applyColor ( { map , layerNames , color , type , } ) { if ( ! type || ! color ) return ; const { h , s , l } = hexToHSL ( color ) ; return layerNames . forEach ( ( layerName ) => { map . setPaintProperty ( layerName , type , `hsl(${ h }, ${ s }%, ${ l }%)` ) ; } ) ; } export function applyVisibility ( { map , layerNames , visibility , } ) { layerNames . forEach ( ( layerName ) => { if ( visibility === 'inherit' ) { map . setLayoutProperty ( layerName , 'visibility' , 'visible' ) ; } else map . setLayoutProperty ( layerName , 'visibility' , visibility ) ; } ) ; } export function applyWeight ( { map , layerNames , type , weight = 1 , } ) { if ( ! type ) return ; const weightValue = weight === 0 ? 0 : weight ; layerNames . forEach ( ( layerName ) => { map . setPaintProperty ( layerName , type , weightValue ) ; } ) ; }