@@ -140,16 +140,16 @@ describe('Geometry.Marker', function () {
140140 var marker1 = new maptalks . Marker (
141141 center . sub ( 0.009 , 0 ) ,
142142 {
143- 'symbol' : {
144- 'markerType' : 'ellipse' ,
145- 'markerWidth' : 28 ,
146- 'markerHeight' : 40 ,
147- 'markerDx' : 0 ,
148- 'markerDy' : 100000 ,
149- 'markerOpacity' : 1
150- }
143+ 'symbol' : {
144+ 'markerType' : 'ellipse' ,
145+ 'markerWidth' : 28 ,
146+ 'markerHeight' : 40 ,
147+ 'markerDx' : 0 ,
148+ 'markerDy' : 100000 ,
149+ 'markerOpacity' : 1
150+ }
151151 }
152- ) . addTo ( vlayer ) ;
152+ ) . addTo ( vlayer ) ;
153153 } ) ;
154154
155155 it ( 'can be text' , function ( ) {
@@ -875,4 +875,38 @@ describe('Geometry.Marker', function () {
875875 expect ( newCoords ) . to . be . eql ( [ 118.62842615841328 , 32.17932019575247 ] ) ;
876876 } ) ;
877877 } ) ;
878+
879+ //https://github.com/maptalks/issues/issues/422
880+ it ( 'marker size when textSize missing' , function ( done ) {
881+ const texts = [ 'Maptalks' , 'Hello\nWorld' , Math . random ( ) * 100 , '中国人' , '没有设置textSize时' , '没有设置textSize时\nmarker的getSize方法返回的值不正确 ' ] ;
882+ function createMaker ( text , textSize ) {
883+ const symbol = {
884+ textName : text ,
885+ textFill : 'red' ,
886+ textSize : textSize
887+ } ;
888+ if ( ! symbol . textSize ) {
889+ delete symbol . textSize ;
890+ }
891+ return new maptalks . Marker ( map . getCenter ( ) , {
892+ symbol
893+ } ) ;
894+ }
895+
896+ function getMarkerWidth ( marker ) {
897+ return Math . round ( marker . getSize ( ) . width ) ;
898+ }
899+
900+ texts . forEach ( text => {
901+ layer . clear ( ) ;
902+ const marker1 = createMaker ( text , 14 ) ;
903+ marker1 . addTo ( layer ) ;
904+ const marker2 = createMaker ( text ) ;
905+ marker2 . addTo ( layer ) ;
906+ const w1 = getMarkerWidth ( marker1 ) ;
907+ const w2 = getMarkerWidth ( marker2 ) ;
908+ expect ( w1 ) . to . be . eql ( w2 ) ;
909+ } ) ;
910+ done ( ) ;
911+ } ) ;
878912} ) ;
0 commit comments