Closed pkluz closed 7 years ago
The path should contain 000000
, not #000000
.
/cc @frederoni
I can't reproduce this using v0.9. @pkluz, what version are you using?
Straight from the Podfile:pod 'MapboxStatic.swift', '~> 0.9.0'
This works perfectly:
let preferredBounds = viewModel.preferredBounds
let camera = SnapshotCamera(lookingAtCenter: preferredBounds.midpoint, zoomLevel: 12.25)
guard let url = URL(string: Constants.mapboxTheme) else { return }
let options = SnapshotOptions(styleURL: url, camera: camera, size: contentSize)
let snapshot = Snapshot(options: options, accessToken: Constants.mapboxAPIKey)
snapshot.image { [weak self] image, error in
imageView.image = image
}
This does not:
let preferredBounds = viewModel.preferredBounds
let camera = SnapshotCamera(lookingAtCenter: preferredBounds.midpoint, zoomLevel: 12.25)
guard let url = URL(string: Constants.mapboxTheme) else { return }
let options = SnapshotOptions(styleURL: url, camera: camera, size: contentSize)
let snapshot = Snapshot(options: options, accessToken: Constants.mapboxAPIKey)
let path = Path(coordinates: [
CLLocationCoordinate2D(latitude: 35.012579, longitude: 135.778078),
CLLocationCoordinate2D(latitude: 35.012853, longitude: 135.773099),
CLLocationCoordinate2D(latitude: 35.014601, longitude: 135.769167)
])
path.strokeWidth = 2
path.strokeColor = .black
options.overlays = [ path ]
snapshot.image { [weak self] image, error in
imageView.image = image
}
Have not yet tried this with different coordinates, although I'm not sure how this'd relate to a stray #
in the URL. I did have MapBox issues in the past though where US coordinates worked perfectly, but it had issues with rendering pins in say Japan correctly... although as said, I doubt that's related to the crash here
#
in the URL is most likely the issue but I can't reproduce using your code.
This seems to work perfectly fine.
Can you check your Podfile.lock
to make sure you're actually running v0.9.0? If you have an outdated version you might have to run pod repo update
prior to pod update
.
Locked to 0.9.0:
- MapboxStatic.swift (~> 0.9.0)
So, I found the issue and it's as follows:
You define a typealias
in Color.swift
:
#if os(OSX)
import Cocoa
typealias Color = NSColor
#else
import UIKit
typealias Color = UIColor
#endif
Then you define an extension on that typealias
here:
internal extension Color { ... }
A different dependency of mine however, literally implements a platform independent type called Color
. That type is concrete, namely a struct
. And it also happens to provide a method toHexString()
, which happens to return the string with a prepended #
. Your extension implementation is never called. Swift seems to prefer concrete types while looking up the methods to dispatch to.
I think this can be mitigated by defining a more uniquely named typealias
on your end or scoping it inside a namespace... What do you think?
Adding final
to MapboxStatic's toHexString()
would prevent this issue.
Given the following code:
When attempting to load the image asynchronously, the application crashes in
Snapshot.swift
here:The
URL(...)
that is being force unwrapped isnil
.The values used are all present and (except for the API key) look as follows:
options.path
=components.percentEncodedQuery!
=(key is valid and works elsewhere, replaced characters with X's)
apiEndpoint
=Do you have any guidance? Running on
Xcode 8.3.2
, and deploying toiOS 10.2