MTTileURLTemplate

public struct MTTileURLTemplate

A helper struct for validating and building tile URLs from string templates.

  • Checks if a given template string contains the required minimum tokens.

    Declaration

    Swift

    public static func isValid(template: String) -> Bool

    Parameters

    template

    The URL template string.

    Return Value

    true if it contains {z}, {x}, and either {y} or {-y}.

  • Builds a full tile URL from a template string for given coordinates and scheme.

    This method seamlessly handles the {-y} token which implies a TMS-style inverted Y-axis, even if the scheme passed is explicitly XYZ. If {-y} is present, it will invert the Y coordinate.

    Declaration

    Swift

    public static func buildURL(template: String, z: Int, x: Int, y: Int, scheme: MTOfflineTileScheme = .xyz) -> URL?

    Parameters

    template

    The URL template string (e.g., https://example.com/tiles/{z}/{x}/{y}.pbf).

    z

    The zoom level.

    x

    The X coordinate.

    y

    The Y coordinate.

    scheme

    The coordinate scheme (.xyz or .tms).

    Return Value

    A valid URL if the template is correctly formatted, nil otherwise.