Fixed a bug in switching between layers in cross domain API.