given how often we use this layer counting, we should probably prepare a pull request for Leaflet that returns this number directly. Fine for this patch though.