Last active
January 11, 2018 14:34
-
-
Save 1ec5/d4fe50958800d06e506695bc370766d7 to your computer and use it in GitHub Desktop.
Swift wrapper for Mapbox Static API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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