private function addLayersToStack($layers, &$stack)
    {
        foreach ($layers as $layer) {
            if ($layer instanceof LayerGroup) {
                $this->addLayersToStack($layer->getLayers(), $stack);
            }

            $stack[] = $layer;
        }
    }