@@ -23,22 +23,30 @@ var MapLabelsCanvas = CanvasLayer.extend({
2323 continue ;
2424 }
2525
26+ // Map textScale values to font sizes
2627 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' ) ;
4250 }
4351
4452 // Scale font size to match zoom
@@ -53,25 +61,31 @@ var MapLabelsCanvas = CanvasLayer.extend({
5361
5462 const name = locations [ i ] . name
5563
56- const words = name . split ( ' ' )
57-
64+ // First split by <br> tags to handle explicit line breaks
65+ const brLines = name . split ( '<br>' )
5866 const lines = [ ]
5967
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 ;
6583 }
66- line += word
67- } else {
84+ } )
85+ if ( line !== "" ) {
6886 lines . push ( line ) ;
69- line = word ;
7087 }
7188 } )
72- if ( line !== "" ) {
73- lines . push ( line ) ;
74- }
7589
7690 let y = canvasPoint . y ;
7791 lines . forEach ( line => {
0 commit comments