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
15
- /*
16
- * signals
17
- OK detectors: seulement ceux sous un signal, ceux qu'on genere en sur les tiv de jonction connait pas leur pk
18
- OK buffer stops
19
- OK les panneaux des psl
20
- OK les operational point parts
21
- */
22
-
23
15
export default function configKPLabelLayer ( props : PlatformProps ) {
24
16
const {
25
17
colors,
26
18
fieldName = 'kp' ,
27
- leftOffset = - 1 ,
28
19
maxzoom = 24 ,
29
20
minzoom = 7 ,
30
- rotation = 'viewport' ,
21
+ isSignalisation ,
31
22
sourceLayer,
32
23
} = props ;
33
- const rkValue : LayerProps = {
24
+
25
+ // Will have to be removed when backend will be updated with consistent fieldnames
26
+ const testSideExpression = ( side : 'LEFT' | 'RIGHT' | 'CENTER' ) => [
27
+ 'any' ,
28
+ [ '==' , [ 'get' , 'extensions_sncf_side' ] , side ] ,
29
+ [ '==' , [ 'get' , 'side' ] , side ] ,
30
+ ] ;
31
+
32
+ const signallingLabeling : LayerProps [ 'layout' ] = isSignalisation
33
+ ? {
34
+ 'text-rotation-alignment' : 'map' ,
35
+ 'text-pitch-alignment' : 'map' ,
36
+ 'text-rotate' : [ 'get' , 'angle' ] ,
37
+ 'text-anchor' : [
38
+ 'case' ,
39
+ testSideExpression ( 'LEFT' ) as ExpressionFilterSpecification ,
40
+ 'right' ,
41
+ testSideExpression ( 'RIGHT' ) as ExpressionFilterSpecification ,
42
+ 'left' ,
43
+ 'center' ,
44
+ ] ,
45
+ 'text-offset' : [
46
+ 'case' ,
47
+ testSideExpression ( 'LEFT' ) as ExpressionFilterSpecification ,
48
+ [ 'literal' , [ - 2.75 , 0.2 ] ] ,
49
+ testSideExpression ( 'RIGHT' ) as ExpressionFilterSpecification ,
50
+ [ 'literal' , [ 2.75 , 0.2 ] ] ,
51
+ [ 'literal' , [ 0 , 2.5 ] ] ,
52
+ ] ,
53
+ }
54
+ : {
55
+ 'text-offset' : [ 'literal' , [ - 1 , 0.1 ] ] ,
56
+ } ;
57
+
58
+ const kpValue : LayerProps = {
34
59
type : 'symbol' ,
35
60
'source-layer' : sourceLayer ,
36
61
filter : [ 'all' , [ '!=' , [ 'literal' , null ] , [ 'get' , fieldName ] ] , [ '!=' , '' , [ 'get' , fieldName ] ] ] ,
@@ -42,11 +67,9 @@ export default function configKPLabelLayer(props: PlatformProps) {
42
67
'text-size' : 9 ,
43
68
'text-anchor' : 'right' ,
44
69
'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 ,
70
+ 'text-ignore-placement' : false ,
71
+
72
+ ...signallingLabeling ,
50
73
} ,
51
74
paint : {
52
75
'text-color' : colors . kp . text ,
@@ -56,5 +79,5 @@ export default function configKPLabelLayer(props: PlatformProps) {
56
79
} ,
57
80
} ;
58
81
59
- return rkValue ;
82
+ return kpValue ;
60
83
}
0 commit comments