Auto calculate first and last layers in view