Check for undefined layer.map to avoid issue #272

Fixes issue #272, which occurs when resetting the map.