1
+ import { ExpressionFilterSpecification } from 'maplibre-gl' ;
1
2
import { LayerProps } from 'react-map-gl/maplibre' ;
2
3
3
4
import { Theme } from 'types' ;
4
5
5
6
interface PlatformProps {
6
7
colors : Theme ;
7
8
fieldName ?: string ;
8
- leftOffset ?: number ;
9
9
maxzoom ?: number ;
10
10
minzoom ?: number ;
11
- rotation ?: 'map' | 'viewport' | 'auto' ;
11
+ isSignalisation ?: boolean ;
12
12
sourceLayer : string ;
13
13
}
14
14
@@ -24,12 +24,45 @@ export default function configKPLabelLayer(props: PlatformProps) {
24
24
const {
25
25
colors,
26
26
fieldName = 'kp' ,
27
- leftOffset = - 1 ,
28
27
maxzoom = 24 ,
29
28
minzoom = 7 ,
30
- rotation = 'viewport' ,
29
+ isSignalisation ,
31
30
sourceLayer,
32
31
} = props ;
32
+
33
+ // Will have to be removed when backend will be updated with consistent fieldname
34
+ const testSideExpression = ( side : 'LEFT' | 'RIGHT' | 'CENTER' ) => [
35
+ 'any' ,
36
+ [ '==' , [ 'get' , 'extensions_sncf_side' ] , side ] ,
37
+ [ '==' , [ 'get' , 'side' ] , side ] ,
38
+ ] ;
39
+
40
+ const signallingLabeling : LayerProps [ 'layout' ] = isSignalisation
41
+ ? {
42
+ 'text-rotation-alignment' : 'map' ,
43
+ 'text-pitch-alignment' : 'map' ,
44
+ 'text-rotate' : [ 'get' , 'angle' ] ,
45
+ 'text-anchor' : [
46
+ 'case' ,
47
+ testSideExpression ( 'LEFT' ) as ExpressionFilterSpecification ,
48
+ 'right' ,
49
+ testSideExpression ( 'RIGHT' ) as ExpressionFilterSpecification ,
50
+ 'left' ,
51
+ 'center' ,
52
+ ] ,
53
+ 'text-offset' : [
54
+ 'case' ,
55
+ testSideExpression ( 'LEFT' ) as ExpressionFilterSpecification ,
56
+ [ 'literal' , [ - 2.75 , 0.2 ] ] ,
57
+ testSideExpression ( 'RIGHT' ) as ExpressionFilterSpecification ,
58
+ [ 'literal' , [ 2.75 , 0.2 ] ] ,
59
+ [ 'literal' , [ 0 , 2.5 ] ] ,
60
+ ] ,
61
+ }
62
+ : {
63
+ 'text-offset' : [ 'literal' , [ - 1 , 0.1 ] ] ,
64
+ } ;
65
+
33
66
const rkValue : LayerProps = {
34
67
type : 'symbol' ,
35
68
'source-layer' : sourceLayer ,
@@ -42,11 +75,9 @@ export default function configKPLabelLayer(props: PlatformProps) {
42
75
'text-size' : 9 ,
43
76
'text-anchor' : 'right' ,
44
77
'text-allow-overlap' : true ,
45
- 'text-ignore-placement' : true ,
46
- 'text-offset' : [ leftOffset , 0.1 ] ,
47
- 'text-rotation-alignment' : rotation ,
48
- 'text-pitch-alignment' : rotation ,
49
- 'text-rotate' : rotation === 'map' ? [ 'get' , 'angle_geo' ] : 0 ,
78
+ 'text-ignore-placement' : false ,
79
+
80
+ ...signallingLabeling ,
50
81
} ,
51
82
paint : {
52
83
'text-color' : colors . kp . text ,
0 commit comments