Changed a inner function to a public one

1. Changed a inner function to a public one
2. Changed to use dynamic zIndex for layer