Order tunnels by layer

This makes sure that the group-by on layer for tunnels works correctly,
and that tunnels are correctly stacked per layer.

This is a rebase of #525.