docs: function finalizeLayer(layer, layerIds, glStyle, path, map) {
    let minZoom = 24;
    let maxZoom = 0;
    const glLayers = glStyle.layers;
    for (let i = 0, ii = glLayers.length; i < ii; ++i) {
      const glLayer = glLayers[i];
      if (layerIds.indexOf(glLayer.id) !== -1) {
        minZoom = Math.min('minzoom' in glLayer ? glLayer.minzoom : 0, minZoom);
        maxZoom = Math.max('maxzoom' in glLayer ? glLayer.maxzoom : 24, maxZoom);
      }
    }
    return new Promise(function(resolve, reject) {
      const setStyle = function() {
        const source = layer.getSource();
        if (!source || source.getState() === 'error') {
          reject(new Error('Error accessing data for source ' + layer.get('mapbox-source')));
          return;
        }
        if (typeof source.getTileGrid === 'function') {
          const tileGrid = source.getTileGrid();
          if (tileGrid) {
            const sourceMinZoom = tileGrid.getMinZoom();
            if (minZoom > 0 || sourceMinZoom > 0) {
              layer.setMaxResolution(Math.min(defaultResolutions[minZoom], tileGrid.getResolution(sourceMinZoom)) + 1e-9);
            }
            if (maxZoom < 24) {
              layer.setMinResolution(defaultResolutions[maxZoom] + 1e-9);
            }
          }
        }
        if (source instanceof VectorSource || source instanceof VectorTileSource) {
          applyStyle(layer, glStyle, layerIds, path).then(function() {
            layer.setVisible(true);
            resolve();
          }, function(e) {
            reject(e);
          });
        } else {
          resolve();
        }
      };
  
      layer.set('mapbox-layers', layerIds);
      if (map.getLayers().getArray().indexOf(layer) === -1) {
        map.addLayer(layer);
      }
  
      if (layer.getSource()) {
        setStyle();
      } else {
        layer.once('change:source', setStyle);
      }
    });
  }