This is how I create markers and add it to array of overlays:
let text = "1"
let url = URL(string: "http://texttopng.azurewebsites.net/Home/TextToPng?text=\(text)")!
let marker = CustomMarker(coordinate: label.location.coordinate, url: url)
but when I try to do a snapshot:
_ = Snapshot(options: options, accessToken: nil).image { image, error in
//error: Error Domain=MBStaticErrorDomain Code=-1 "Marker overlays must be png, jpg, or webp" UserInfo={NSLocalizedFailureReason=Marker overlays must be png, jpg, or webp}
}
Why it happens like this?
This is what I have tried:
let image = UIImage(named: "icon-card")!
let png = UIImagePNGRepresentation(image)!
let newurl = png.write(withName: "\(text).png")
let marker = CustomMarker(coordinate: label.location.coordinate, url: newurl)
extension Data {
func write(withName name: String) -> URL {
let url = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent(name)
try! write(to: url, options: .atomicWrite)
return url
}
}
I'd like to share my code and it works without any issues:
I used your
extension
forData
for saving ofjpg
fileand as result I have a shapshot like this: I guess you can try use my code or part of it and check with your environment. I use
MapboxStatic.swift (0.11.0)
Mapbox pod