I have a map of the world and I want to place text on top of each country. The text can be anywhere from 0 to 1000 symbols long, and can often be changed.
I'm looking for an algorithm to layout text on top of each country "nicely":
- Text ideally should not go outside of the country borders
- Placed somewhere near poloygon's centroid
- Should be visible when possible
I can change font size, and I can split it into multiple lines.
Currently I'm using naive centroid approach, but it requires lots of manual tweaking, and with changing text it can result in suboptimal placement:
Interactive version of the USA map is available here: http://what-people-google.anvaka.com/ (so that you can see labels placement drawbacks and better understand my use case).
One solution I had in mind was to approximate each country by largest posible axis aligned rectangle that can be embedded inside country shape. But maybe there is a better way to do it?