MTBoundingBox

public struct MTBoundingBox : Codable, Equatable, Sendable

A bounding box in WGS84 coordinates.

  • Undocumented

    Declaration

    Swift

    public let minLon: Double
  • Undocumented

    Declaration

    Swift

    public let minLat: Double
  • Undocumented

    Declaration

    Swift

    public let maxLon: Double
  • Undocumented

    Declaration

    Swift

    public let maxLat: Double
  • Returns true if the bounding box spans across the antimeridian (180th meridian).

    Declaration

    Swift

    public var crossesAntimeridian: Bool { get }
  • Undocumented

    Declaration

    Swift

    public init(minLon: Double, minLat: Double, maxLon: Double, maxLat: Double)
  • Checks if this bounding box intersects with another bounding box.

    Declaration

    Swift

    public func intersects(with other: MTBoundingBox) -> Bool

    Parameters

    other

    The other bounding box to check against.

    Return Value

    true if the bounding boxes intersect, otherwise false.

Normalization & Dateline Splitting

  • The maximum latitude limit for Web Mercator projection.

    Declaration

    Swift

    public static let maxWebMercatorLat: Double
  • Normalizes a longitude to the standard range [-180, 180].

    Declaration

    Swift

    public static func normalizeLongitude(_ longitude: Double) -> Double

    Parameters

    longitude

    The raw longitude.

    Return Value

    A normalized longitude.

  • Clamps a latitude to the Web Mercator valid range (-85.0511… to 85.0511…).

    Declaration

    Swift

    public static func clampLatitude(_ latitude: Double) -> Double

    Parameters

    latitude

    The raw latitude.

    Return Value

    A clamped latitude.

  • Normalizes the bounding box coordinates and splits it into two if it crosses the antimeridian (Dateline).

    Declaration

    Swift

    public func normalizedAndSplit() -> [MTBoundingBox]

    Return Value

    An array containing one normalized bounding box, or two if it crosses the antimeridian.

Interoperability & Helper Utilities

  • Initializes a bounding box from an MTBounds instance.

    Declaration

    Swift

    public init(bounds: MTBounds)

    Parameters

    bounds

    The source MTBounds.

  • Creates a bounding box from an array of coordinates.

    Declaration

    Swift

    public init?(coordinates: [CLLocationCoordinate2D])

    Parameters

    coordinates

    An array of coordinates (e.g. forming a polygon or line).

    Return Value

    A bounding box enclosing all coordinates, or nil if the array is empty.

  • Returns an equivalent MTBounds instance.

    Declaration

    Swift

    public var bounds: MTBounds { get }
  • Expands the bounding box outward by a given distance in meters.

    Declaration

    Swift

    public func expanded(byMeters meters: Double) -> MTBoundingBox

    Parameters

    meters

    The distance in meters to expand.

    Return Value

    A new expanded bounding box.

  • Expands the bounding box outward by a given percentage.

    Declaration

    Swift

    public func expanded(by percentage: Double) -> MTBoundingBox

    Parameters

    percentage

    The percentage to expand (e.g., 0.1 for a 10% buffer).

    Return Value

    A new expanded bounding box.

  • Calculates the approximate surface area in square kilometers.

    Declaration

    Swift

    public var areaInSquareKilometers: Double { get }
  • Estimates the exact number of tiles required for this bounding box within the specified zoom range.

    Declaration

    Swift

    public func estimatedTileCount(zoomRange: MTOfflineZoomRange) -> Int

    Parameters

    zoomRange

    The min and max zoom levels.

    Return Value

    The total tile count.

  • Estimates the number of tiles required per zoom level for this bounding box.

    Declaration

    Swift

    public func estimatedTileCountPerZoom(zoomRange: MTOfflineZoomRange) -> [Int : Int]

    Parameters

    zoomRange

    The min and max zoom levels.

    Return Value

    A dictionary mapping each zoom level to its tile count.

  • Creates a bounding box that contains all the given coordinates.

    Declaration

    Swift

    public init(from coordinates: [CLLocationCoordinate2D])

    Parameters

    coordinates

    The coordinates to include.