code: @Nonnull
      private ReferencedEnvelope getFeatureBounds(
              final MfClientHttpRequestFactory clientHttpRequestFactory,
              final MapAttributeValues mapValues, final ExecutionContext context) {
          final MapfishMapContext mapContext = createMapContext(mapValues);
  
          String layerName = mapValues.zoomToFeatures.layer;
          ReferencedEnvelope bounds = new ReferencedEnvelope();
          for (MapLayer layer: mapValues.getLayers()) {
              context.stopIfCanceled();
  
              if ((!StringUtils.isEmpty(layerName) && layerName.equals(layer.getName())) ||
                      (StringUtils.isEmpty(layerName) && layer instanceof AbstractFeatureSourceLayer)) {
                  AbstractFeatureSourceLayer featureLayer = (AbstractFeatureSourceLayer) layer;
                  FeatureSource<?, ?> featureSource =
                          featureLayer.getFeatureSource(clientHttpRequestFactory, mapContext);
                  FeatureCollection<?, ?> features;
                  try {
                      features = featureSource.getFeatures();
                  } catch (IOException e) {
                      throw ExceptionUtils.getRuntimeException(e);
                  }
  
                  if (!features.isEmpty()) {
                      final ReferencedEnvelope curBounds = features.getBounds();
                      bounds.expandToInclude(curBounds);
                  }
              }
          }
  
          return bounds;
      }
docs: Get the bounding-box containing all features of all layers.