@@ -23,22 +23,30 @@ var MapLabelsCanvas = CanvasLayer.extend({
23
23
continue ;
24
24
}
25
25
26
+ // Map textScale values to font sizes
26
27
let fontSize ;
27
- let fontColour ;
28
-
29
- // Scale the font, and change colour based on location size
30
- switch ( locations [ i ] . size ) {
31
- case 'default' :
32
- fontSize = 0.08
33
- fontColour = 'white' ;
34
- break ;
35
- case 'medium' :
36
- fontSize = 0.10
37
- fontColour = 'white' ;
38
- break ;
39
- case 'large' :
40
- fontSize = 0.18
41
- fontColour = '#ffaa00' ;
28
+ if ( typeof locations [ i ] . size === 'number' ) {
29
+ switch ( locations [ i ] . size ) {
30
+ case 0 :
31
+ fontSize = 0.08 ; // default
32
+ break ;
33
+ case 1 :
34
+ fontSize = 0.10 ; // medium
35
+ break ;
36
+ case 2 :
37
+ fontSize = 0.18 ; // large
38
+ break ;
39
+ default :
40
+ fontSize = 0.08 ;
41
+ }
42
+ } else {
43
+ fontSize = 0.08 ; // fallback
44
+ }
45
+
46
+ // Convert textColor from decimal to hex, with fallback
47
+ let fontColour = 'white' ;
48
+ if ( locations [ i ] . color ) {
49
+ fontColour = '#' + locations [ i ] . color . toString ( 16 ) . padStart ( 6 , '0' ) ;
42
50
}
43
51
44
52
// Scale font size to match zoom
@@ -53,25 +61,31 @@ var MapLabelsCanvas = CanvasLayer.extend({
53
61
54
62
const name = locations [ i ] . name
55
63
56
- const words = name . split ( ' ' )
57
-
64
+ // First split by <br> tags to handle explicit line breaks
65
+ const brLines = name . split ( '<br>' )
58
66
const lines = [ ]
59
67
60
- let line = "" ;
61
- words . forEach ( word => {
62
- if ( ( line + word ) . length < 10 ) {
63
- if ( line !== "" ) {
64
- line += " "
68
+ brLines . forEach ( brLine => {
69
+ const words = brLine . trim ( ) . split ( ' ' )
70
+
71
+ let line = "" ;
72
+ words . forEach ( word => {
73
+ if ( ( line + word ) . length < 10 ) {
74
+ if ( line !== "" ) {
75
+ line += " "
76
+ }
77
+ line += word
78
+ } else {
79
+ if ( line !== "" ) {
80
+ lines . push ( line ) ;
81
+ }
82
+ line = word ;
65
83
}
66
- line += word
67
- } else {
84
+ } )
85
+ if ( line !== "" ) {
68
86
lines . push ( line ) ;
69
- line = word ;
70
87
}
71
88
} )
72
- if ( line !== "" ) {
73
- lines . push ( line ) ;
74
- }
75
89
76
90
let y = canvasPoint . y ;
77
91
lines . forEach ( line => {
0 commit comments