err- sorry, the formatting messed up somehow.
Make the Z component of your map come first. So that you have a bunch of 2d arrays with respect to a Z-component Array.
In other words, your map is of the form Map[z][x][y].
Now, when you want to draw something, you simply pass Map[z] into your grid-drawing function. The grid-drawing function expects a 2d array of x and y coordinates- Map[z] is a 2d array, whereas Map is a 3d array. Get it?
Edited with tags >_<.