diff --git a/Example/ViewController.swift b/Example/ViewController.swift index 9660cf4..5b950cd 100644 --- a/Example/ViewController.swift +++ b/Example/ViewController.swift @@ -17,12 +17,25 @@ class ViewController: UIViewController { override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) + + let coordinates = [CLLocationCoordinate2D(latitude: 45.4562, longitude: -122.8793), + CLLocationCoordinate2D(latitude: 45.4562, longitude: -122.4645), + CLLocationCoordinate2D(latitude: 45.6582, longitude: -122.4645), + CLLocationCoordinate2D(latitude: 45.6582, longitude: -122.8793), + CLLocationCoordinate2D(latitude: 45.4562, longitude: -122.8793)] + + let path = Path(coordinates: coordinates) + path.fillColor = UIColor.red.withAlphaComponent(0.5) + path.strokeColor = UIColor.green.withAlphaComponent(0.5) let camera = SnapshotCamera(lookingAtCenter: CLLocationCoordinate2D(latitude: 45, longitude: -122), zoomLevel: 6) let options = SnapshotOptions( styleURL: URL(string: "mapbox://styles/mapbox/streets-v9")!, camera: camera, size: imageView.bounds.size) + + options.overlays.append(path) + _ = Snapshot(options: options, accessToken: accessToken).image { [weak self] (image, error) in if let error = error { print(error) diff --git a/MapboxStatic/Color.swift b/MapboxStatic/Color.swift index b6791cb..62d65cd 100644 --- a/MapboxStatic/Color.swift +++ b/MapboxStatic/Color.swift @@ -27,6 +27,19 @@ internal extension Color { return NSString(format: "%02x%02x%02x", Int(r), Int(g), Int(b)) as String } + + #if !os(macOS) + internal var alphaComponent: CGFloat { + var r: CGFloat = 0 + var g: CGFloat = 0 + var b: CGFloat = 0 + var a: CGFloat = 0 + + getRed(&r, green: &g, blue: &b, alpha: &a) + + return a + } + #endif convenience init(hexString: String) { var hexString = hexString.replacingOccurrences(of: "#", with: "") diff --git a/MapboxStatic/Overlay.swift b/MapboxStatic/Overlay.swift index 347bae5..833b2d2 100644 --- a/MapboxStatic/Overlay.swift +++ b/MapboxStatic/Overlay.swift @@ -328,20 +328,6 @@ open class Path: NSObject, Overlay { open var fillColor = UIColor(hexString: "555") #endif - /** - The stroke opacity of the overlay, expressed as a percentage such that 0.0 is completely transparent and 1.0 is completely opaque. - - By default, the overlay’s stroke is completely opaque. - */ - open var strokeOpacity: Double = 1 - - /** - The fill opacity of the overlay, expressed as a percentage such that 0.0 is completely transparent and 1.0 is completely opaque. - - By default, the overlay’s fill is completely transparent. - */ - open var fillOpacity: Double = 0 - /** Initializes a polyline overlay with the given vertices. @@ -437,9 +423,9 @@ open class Path: NSObject, Overlay { open override var description: String { let encodedPolyline = polylineEncode(coordinates).addingPercentEncoding(withAllowedCharacters: allowedCharacterSet)! - var description = "path-\(strokeWidth)+\(strokeColor.toHexString())-\(strokeOpacity)" - if fillOpacity > 0 { - description += "+\(fillColor.toHexString())-\(fillOpacity)" + var description = "path-\(strokeWidth)+\(strokeColor.toHexString())-\(strokeColor.alphaComponent)" + if fillColor.alphaComponent > 0 { + description += "+\(fillColor.toHexString())-\(fillColor.alphaComponent)" } description += "(\(encodedPolyline))" return description diff --git a/MapboxStaticTests/ClassicOverlayTests.swift b/MapboxStaticTests/ClassicOverlayTests.swift index b709310..8354b93 100644 --- a/MapboxStaticTests/ClassicOverlayTests.swift +++ b/MapboxStaticTests/ClassicOverlayTests.swift @@ -131,10 +131,8 @@ class ClassicOverlayTests: XCTestCase { ) ]) path.strokeWidth = 2 - path.strokeColor = .black - path.strokeOpacity = 0.75 - path.fillColor = .red - path.fillOpacity = 0.25 + path.strokeColor = Color.black.withAlphaComponent(0.75) + path.fillColor = Color.red.withAlphaComponent(0.25) let options = ClassicSnapshotOptions( mapIdentifiers: ["mapbox.streets"],