@@ -127,14 +127,7 @@ else if (isLine) {
127127 paintLegendText (origin , opts , text , textRenderer );
128128
129129 // normalize symbol sizes
130- double maxSize = 0 ;
131- if (isPoint ) {
132- for (Styling s : stylings ) {
133- if (s instanceof PointStyling ) {
134- maxSize = max (((PointStyling ) s ).graphic .size , maxSize );
135- }
136- }
137- }
130+ double maxSize = calculateMaxSize (isPoint );
138131
139132 if (rule == null ) {
140133 for (Styling s : stylings ) {
@@ -146,6 +139,21 @@ else if (isLine) {
146139 paintRule (isPoint , maxSize , opts , geom );
147140 }
148141
142+ private double calculateMaxSize (boolean isPoint ) {
143+ double maxSize = 0 ;
144+ if (isPoint ) {
145+ for (Styling s : stylings ) {
146+ if (s instanceof PointStyling ) {
147+ maxSize = max (((PointStyling ) s ).graphic .size , maxSize );
148+ }
149+ }
150+ }
151+ if (maxSize > 0 )
152+ return maxSize ;
153+ // fallback to default size 6 to avoid infinite legend size if maxSize is 0
154+ return 6 ;
155+ }
156+
149157 private void paintRule (boolean isPoint , double maxSize , LegendOptions opts , Geometry geom ) {
150158 LinkedList <Symbolizer <?>> syms = new LinkedList <Symbolizer <?>>();
151159 rule .evaluate (syms , null , null );
@@ -159,6 +167,10 @@ private void paintRule(boolean isPoint, double maxSize, LegendOptions opts, Geom
159167 if (styling instanceof PointStyling && isPoint ) {
160168 PointStyling ps = ((PointStyling ) styling ).copy ();
161169 ps .uom = Metre ;
170+ // fallback to default size 6 to avoid infinite legend size if maxSize
171+ // is 0
172+ if (ps .graphic .size <= 0 )
173+ ps .graphic .size = 6 ;
162174 ps .graphic .size = ps .graphic .size / maxSize * min (opts .baseWidth , opts .baseHeight );
163175 styling = ps ;
164176 }
0 commit comments