addLayer now returns the index of the new layer.