Skip to content

Instantly share code, notes, and snippets.

@1ec5
Last active January 11, 2018 14:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 1ec5/d4fe50958800d06e506695bc370766d7 to your computer and use it in GitHub Desktop.
Save 1ec5/d4fe50958800d06e506695bc370766d7 to your computer and use it in GitHub Desktop.
Swift wrapper for Mapbox Static API
import UIKit
import CoreLocation
struct ServerSideSnapshot {
let MaximumDimension: CGFloat = 1280
var size: CGSize
var centerCoordinate: CLLocationCoordinate2D
var zoomLevel: Double
var direction: CLLocationDirection
var pitch: CGFloat
var style: Style
var showsAttribution: Bool
var showsLogo: Bool
var URL: NSURL? {
guard let styleID = style.identifier else {
return nil
}
let width = Int(min(round(size.width), MaximumDimension))
let height = Int(min(round(size.height), MaximumDimension))
let scaleFactor = Int(round(UIScreen.mainScreen().scale))
let scaleSuffix = scaleFactor != 1 ? "@\(scaleFactor)x" : ""
let accessToken = style.accessToken ?? SiriusDefaultStyleAccessToken
return NSURL(string: "https://api.mapbox.com/styles/v1/\(styleID)/static/\(centerCoordinate.longitude),\(centerCoordinate.latitude),\(zoomLevel),\(direction),\(pitch)/\(width)x\(height)\(scaleSuffix)?access_token=\(accessToken)")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment