Improve the country labeling
- Set a maximum font size - Try to label polygons that are too small for the full name with the 2-letter contry code
This commit is contained in:
parent
bc3e6a1436
commit
492395840d
19
qsomap.py
19
qsomap.py
|
@ -10,6 +10,7 @@ import random
|
|||
import argparse
|
||||
|
||||
LABEL_MIN_FONT_SIZE = 2
|
||||
LABEL_MAX_FONT_SIZE = 40
|
||||
|
||||
|
||||
def map_azimuthal_equidistant(lat, lon, ref_lat, ref_lon, R=1):
|
||||
|
@ -347,23 +348,35 @@ def svg_add_country_names(doc, simplegeodata, map_radius):
|
|||
'fill': v['label_color']
|
||||
}
|
||||
|
||||
label = v['name']
|
||||
|
||||
# rotate text by 90 degrees if polygon is higher than wide
|
||||
if h > w:
|
||||
font_size = h / len(v['name'])
|
||||
font_size = h / len(label)
|
||||
rotate = True
|
||||
else:
|
||||
font_size = w / len(v['name'])
|
||||
font_size = w / len(label)
|
||||
rotate = False
|
||||
|
||||
if font_size < LABEL_MIN_FONT_SIZE:
|
||||
# try again with 2-letter country code
|
||||
label = k
|
||||
font_size = min(LABEL_MIN_FONT_SIZE*2,
|
||||
(h if rotate else w) / len(label))
|
||||
|
||||
if font_size < LABEL_MIN_FONT_SIZE:
|
||||
print('.', end='', flush=True)
|
||||
continue # too small
|
||||
else:
|
||||
print('!', end='', flush=True)
|
||||
else:
|
||||
print('#', end='', flush=True)
|
||||
|
||||
font_size = min(LABEL_MAX_FONT_SIZE, font_size)
|
||||
|
||||
kwargs['font-size'] = font_size
|
||||
|
||||
txt = doc.text(v['name'], (center_x, center_y),
|
||||
txt = doc.text(label, (center_x, center_y),
|
||||
**kwargs)
|
||||
|
||||
if rotate:
|
||||
|
|
Loading…
Reference in a new issue