function renderXYZTemplate(template, z, x, y, maxY) {
  return template
    .replace(zRegEx, z.toString())
    .replace(xRegEx, x.toString())
    .replace(yRegEx, y.toString())
    .replace(dashYRegEx, function () {
      if (maxY === undefined) {
        throw new Error(
          'If the URL template has a {-y} placeholder, the grid extent must be known',
        );
      }
      return (maxY - y).toString();
    });
}
@param {string} template The URL template.  Should have `{x}`, `{y}`, and `{z}` placeholders.  If
the template has a `{-y}` placeholder, the `maxY` parameter must be supplied.
@param {number} z The tile z coordinate.
@param {number} x The tile x coordinate.
@param {number} y The tile y coordinate.
@param {number} [maxY] The maximum y coordinate at the given z level.
@return {string} The URL.