This demo contains code to generate edge icons for turfs and to automatically place them on the map. It generates an 8-directional edge icon for each icon state. You can specify a custom mask icon to determine how exactly one turf will blend into the next.

Here's an example. This is the map without edges:

And this is the same map with the edges generated by this demo:

All you have to do is generate the edge icon state and set the edge_layer var for each turf.

I just updated the demo to change the way edges are added. The old code is still in there, it's just commented out, in case you want to use the old method. The change removes some redundant edges, for example:

+---+ | 1 | +---+ | 2 | +---+

If you're adding edges around both of those tiles, turf 1 would get edges on 7 sides (all but south) and turf 2 would get edges on all sides but north. The northeast overlay added to turf 2 would overlap turf 1's southeast overlay.

With this update, turf 1 would only get 5 edges (west, northwest, north, northeast, and east) so it doesn't have any overlays that overlap turf 2's edge overlays.