Cast layer as integer to make sure sorting behaves correctly

This resolves #674.
Merge pull request #1013 from math1985/tunnel-order-3

Cast layer as integer to make sure sorting behaves correctly