My commit doesn't work as expected it seems.

What I don't like too much in your changes is that toggleLayer look at item.selectedOpen. It looks like duplication to me, as toggleLayer already checks whether the layer is the map already, and it's a preview layer.