World Map and Place_label Node

john's Avatar

john

21 Mar, 2023 04:46 AM

Attached is a demo of a new node, place_label, which automatically sizes and places names into arbitrary shapes - in this case 176 different oddly-shaped countries. It can also serve as an example of map-making in Nodebox.

Place_label takes three inputs, a shape, the label text, and a font. It returns a reasonably large textpath, sized and positioned to fit entirely within that shape. If the label text contains more than one word it may break the label into multiple lines. Two additional options let you increase the margin around the label and limit its maximum height.

The first screenshot shows how challenging this can be. In this case, place_label was given the shape of Indonesia which consists of multiple contours (islands), each highly complex. Here the label nicely fills the largest contour in the approximate center.

The second screenshot shows a world map with labels for 176 different countries with varying text lengths and a wide variety of shapes. Place_label does a remarkably good job. It can be a bit slow for multiple shapes, though: the node took over 30 seconds to compute all 176 labels on the world map. Simpler shapes are faster; it can place labels into a thousand circles in under a minute.

Placing labels into arbitrary shapes is not an exact science. My algorithm is a compromise between speed and precision. In some cases reasonable minds could differ on the most aesthetically pleasing size and placement. If you peer inside the node you will find at the top a fudge factor called "tune"which, in extreme cases, can alter the horizontal placement and size of the label. If you are unhappy with the placement you can try changing this value, but doing so will only rarely make any significant improvement overall.

This demo also shows how to color and label an SVG map. The SVG in this case, worldLow.svg, is free for non-commercial use (see Read Me in folder). The map is now at least ten years old, so may be somewhat out of date. But you could use similar techniques with other map files.

Place_label will be included in the next rev of the Cartan Node Library. Please give it a try and report back how well it works for your labeling needs.

Enjoy!

John

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Already uploaded files

  • Map_highlight_screenshot.png 574 KB
  • Map_full_screenshot.png 919 KB
  • World_Map.zip 476 KB

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

Recent Discussions

18 Nov, 2024 11:24 PM
18 Nov, 2024 09:01 PM
07 Nov, 2024 10:53 AM
02 Nov, 2024 11:22 AM
01 Nov, 2024 12:41 AM

 

01 Oct, 2024 07:59 AM
30 Sep, 2024 11:37 PM
30 Sep, 2024 11:11 AM
30 Sep, 2024 02:37 AM
28 Sep, 2024 10:33 AM
26 Sep, 2024 06:41 AM