@@ -6,22 +6,27 @@ L.TextSymbolizer = L.Path.extend({
66 includes : L . Symbolizer . prototype ,
77
88 options : {
9- color : 'black ' ,
9+ color : 'white ' ,
1010 fillColor : 'black' ,
1111 fill : true ,
12- fillOpacity : 1.0 ,
13- weight : 0.2 ,
12+ fillOpacity : 1 ,
13+ opacity : 0.6 ,
14+ weight : 1 ,
1415 rotation : 0.0 ,
1516 stroke : true ,
16- fontFamily : 'Microsoft Yahei' ,
17- fontSize : 12 ,
18- fontWeight : 'normal' ,
19- textAlign : 'center'
17+ fontFamily : "Arial Unicode MS Regular" ,
18+ fontSize : 14 ,
19+ fontWeight : 'bold' ,
20+ textAlign : 'center' ,
21+ offsetX : 1 ,
22+ offsetY : 1
2023 } ,
2124
2225 initialize : function ( feature , pxPerExtent ) {
2326 L . Symbolizer . prototype . initialize . call ( this , feature ) ;
2427 this . _makeFeatureParts ( feature , pxPerExtent ) ;
28+ this . options . offsetX = pxPerExtent || 1 ;
29+ this . options . offsetY = pxPerExtent || 1 ;
2530 } ,
2631
2732 render : function ( renderer , style ) {
@@ -35,8 +40,10 @@ L.TextSymbolizer = L.Path.extend({
3540 this . _text = ( attributes && this . properties . textField ) ?
3641 attributes [ this . properties . textField ] || "" : "" ;
3742 }
38- L . Symbolizer . prototype . render . call ( this , renderer , style ) ;
39- L . Util . setOptions ( this , style ) ;
43+ options = this . options ;
44+ this . _pxBounds = L . bounds ( this . _point , this . _point ) ;
45+ L . Symbolizer . prototype . render . apply ( this , [ renderer , style ] ) ;
46+ this . options = L . Util . extend ( options , style ) ;
4047 this . _updatePath ( ) ;
4148 } ,
4249
@@ -79,45 +86,45 @@ L.Canvas.Renderer.include({
7986 _getTextWidth : function ( layer ) {
8087 return this . _ctx . measureText ( layer . _text ) . width ;
8188 } ,
82-
8389 _updateText : function ( layer ) {
8490 if ( ! this . _drawing || layer . _empty ( ) ) {
8591 return ;
8692 }
87-
93+ container = this . getContainer ( ) ;
94+ var size = this . _map . getSize ( ) ;
95+ container . width = size . x ;
96+ container . height = size . y ;
97+ container . style . width = size . x + 'px' ;
98+ container . style . height = size . y + 'px' ;
8899 var ctx = this . _ctx ,
89100 options = layer . options ,
90- offsetX = options . offsetX || 0 ,
91- offsetY = options . offsetY || 0 ,
101+ offsetX = options . offsetX || 1 ,
102+ offsetY = options . offsetY || 1 ,
92103 p = layer . _point . subtract ( L . point ( offsetX , offsetY ) ) ;
93104 if ( ! options . fill ) {
94105 return ;
95106 }
96107
97108 this . _drawnLayers [ layer . _leaflet_id ] = layer ;
98109
99- ctx . translate ( p . x , p . y ) ;
100- ctx . rotate ( options . rotation ) ;
101- ctx . fillStyle = options . fillColor ;
110+ ctx . fillRect ( 0 , 0 , size . x , size . y ) ;
102111 ctx . font = [
103- "normal" ,
104- "normal" ,
105- options . fontWeight ? options . fontWeight : "normal" ,
106- options . fontSize ? options . fontSize : "1em" ,
107- options . fontFamily ? options . fontFamily : "Microsoft Yahei"
112+ options . fontWeight ? options . fontWeight : "bold" ,
113+ options . fontSize ? options . fontSize : "14px" ,
114+ options . fontFamily ? options . fontFamily : "Arial Unicode MS Regular,Microsoft Yahei"
108115 ] . join ( " " ) ;
109116 ctx . textAlign = options . textAlign ;
110- ctx . lineWidth = options . weight / 10 ;
111- ctx . fillText ( layer . _text , 0 , 0 ) ;
117+ ctx . lineWidth = options . weight ;
118+ ctx . fillStyle = options . fillColor ;
119+ ctx . fillText ( layer . _text , p . x , p . y ) ;
112120 ctx . strokeStyle = options . color ;
113- ctx . strokeText ( layer . _text , 0 , 0 ) ;
114- ctx . rotate ( - options . rotation ) ;
115- ctx . translate ( - p . x , - p . y ) ;
121+ ctx . strokeText ( layer . _text , p . x , p . y ) ;
122+ ctx . rotate ( options . rotation ) ;
116123 }
117124} ) ;
118125L . SVG . Renderer . include ( {
119126 _getTextWidth : function ( layer ) {
120- return layer . _path . getComputedTextLength ( ) ;
127+ return layer . _path . getComputedTextLength ( ) || 0 ;
121128 } ,
122129
123130 _initPath : function ( layer ) {
@@ -146,8 +153,8 @@ L.SVG.Renderer.include({
146153 _updateText : function ( layer ) {
147154 var path = layer . _path ,
148155 options = layer . options ,
149- offsetX = options . offsetX || 0 ,
150- offsetY = options . offsetY || 0 ,
156+ offsetX = options . offsetX || 1 ,
157+ offsetY = options . offsetY || 1 ,
151158 p = layer . _point . subtract ( L . point ( offsetX , offsetY ) ) ;
152159 path . setAttribute ( 'x' , p . x ) ;
153160 path . setAttribute ( 'y' , p . y ) ;
@@ -156,11 +163,14 @@ L.SVG.Renderer.include({
156163 path . setAttribute ( 'text-anchor' , options . textAlign === 'center' ? 'middle' : options . textAlign ) ;
157164 path . style . fontSize = options . fontSize ;
158165 path . style . fontFamily = options . fontFamily ;
166+ path . style . fontWeight = options . fontWeight || "bold" ;
159167 path . style . glyphOrientationVertical = options . rotation ;
160168 if ( options . stroke ) {
161169 path . setAttribute ( 'stroke' , options . color ) ;
170+ path . setAttribute ( 'stroke-linecap' , 'round' ) ;
171+ path . setAttribute ( 'stroke-linejoin' , 'round' ) ;
162172 path . setAttribute ( 'stroke-opacity' , options . opacity ) ;
163- path . setAttribute ( 'stroke-width' , options . weight / 10 ) ;
173+ path . setAttribute ( 'stroke-width' , options . weight > 1 ? options . weight / 10 : options . weight ) ;
164174 } else {
165175 path . setAttribute ( 'stroke' , 'none' ) ;
166176 }
@@ -171,5 +181,7 @@ L.SVG.Renderer.include({
171181 path . setAttribute ( 'fill' , 'none' ) ;
172182 }
173183 }
184+
185+
174186} ) ;
175187module . exports = L . TextSymbolizer ;
0 commit comments