Giter VIP home page Giter VIP logo

mapboxstatic.swift's Introduction

MapboxStatic

CircleCI Carthage compatible CocoaPods

MapboxStatic.swift makes it easy to connect your iOS, macOS, tvOS, or watchOS application to the Mapbox Static Images API. Quickly generate a map snapshot – a static map image with overlays – by fetching it synchronously or asynchronously over the Web using first-class Swift or Objective-C data types.

A snapshot is a flattened PNG or JPEG image, ideal for use in a table or image view, user notification, sharing service, printed document, or anyplace else you’d like a quick, custom map without the overhead of an interactive view. A static map is created in a single HTTP request. Overlays are added server-side.

MapboxStatic.swift pairs well with MapboxDirections.swift, MapboxGeocoder.swift, the Mapbox Maps SDK for iOS, and the Mapbox Maps SDK for macOS SDK. If you’re already using the maps SDK for iOS or macOS for other purposes, consider using an MGLMapSnapshotter object instead of MapboxStatic.swift to produce static images that take advantage of caching and offline packs.

v0.12.0 was the last version of MapboxStatic to support the Legacy Static Images API.

System requirements

  • One of the following package managers:
    • CocoaPods 1.10 or above
    • Carthage 0.19 or above (run this script instead of carthage if using Xcode 12)
    • Swift Package Manager 5.3 or above
  • Xcode 12.0 or above
  • One of the following operating systems:
    • iOS 12.0 or above
    • macOS 10.14 or above
    • tvOS 12.0 or above
    • watchOS 5.0 or above

Installation

Carthage

Specify the following dependency in your Carthage Cartfile:

github "mapbox/MapboxStatic.swift" ~> 0.12

CocoaPods

In your CocoaPods Podfile:

pod 'MapboxStatic.swift', '~> 0.12'

Swift Package Manager

To install MapboxStatic using the Swift Package Manager, add the following package to the dependencies in your Package.swift file:

.package(url: "https://github.com/mapbox/MapboxStatic.swift.git", from: "0.12.0"),

Then import MapboxStatic or @import MapboxStatic;.

This repository includes an example iOS application written in Swift, as well as Swift playgrounds for iOS and macOS. To run them, you need to use Carthage 0.19 or above to install the dependencies. Open the playgrounds inside of MapboxStatic.xcworkspace. More examples are available in the Mapbox API Documentation.

Usage

To generate a snapshot from a Mapbox-hosted style, you’ll need its style URL. You can either choose a Mapbox-designed style or design one yourself in Mapbox Studio. You can use the same style within the Mapbox Maps SDK for iOS or macOS.

You’ll also need an access token with the styles:tiles scope enabled in order to use this library. You can specify your access token inline or by setting the MGLMapboxAccessToken key in your application’s Info.plist file.

The examples below are each provided in Swift (denoted with main.swift) and Objective-C (main.m). For further details, see the MapboxStatic.swift API reference.

Basics

The main static map class is Snapshot in Swift or MBSnapshot in Objective-C. To create a basic snapshot, create a SnapshotOptions object, specifying snapshot camera (viewpoint) and point size:

// main.swift
import MapboxStatic

let camera = SnapshotCamera(
    lookingAtCenter: CLLocationCoordinate2D(latitude: 45.52, longitude: -122.681944),
    zoomLevel: 12)
let options = SnapshotOptions(
    styleURL: URL(string: "<#your mapbox: style URL#>")!,
    camera: camera,
    size: CGSize(width: 200, height: 200))
let snapshot = Snapshot(
    options: options,
    accessToken: "<#your access token#>")
// main.m
@import MapboxStatic;

NSURL *styleURL = [NSURL URLWithString:@"<#your mapbox: style URL#>"];
MBSnapshotCamera *camera = [MBSnapshotCamera cameraLookingAtCenterCoordinate:CLLocationCoordinate2DMake(45.52, -122.681944)
                                                                   zoomLevel:12];
MBSnapshotOptions *options = [[MBSnapshotOptions alloc] initWithStyleURL:styleURL
                                                                  camera:camera
                                                                    size:CGSizeMake(200, 200)];
MBSnapshot *snapshot = [[MBSnapshot alloc] initWithOptions:options
                                               accessToken:@"<#your access token#>"];

Then, you can either retrieve an image synchronously (blocking the calling thread):

// main.swift
imageView.image = snapshot.image
// main.m
imageView.image = snapshot.image;

Or you can pass a completion handler to update the UI thread after the image is retrieved:

// main.swift
snapshot.image { (image, error) in
    imageView.image = image
}
// main.m
[snapshot imageWithCompletionHandler:^(UIImage * _Nullable image, NSError * _Nullable error) {
    imageView.image = image;
}];

If you're using your own HTTP library or routines, you can also retrieve a snapshot’s URL property.

// main.swift
let imageURL = snapshot.url
// main.m
NSURL *imageURL = snapshot.url;

Overlays

Overlays are where things get interesting! You can add Maki markers, custom marker imagery, GeoJSON geometries, and even paths made of bare coordinates.

You add overlays to the overlays field in the SnapshotOptions or MBSnapshotOptions object. Here are some versions of our snapshot with various overlays added.

Marker

// main.swift
let markerOverlay = Marker(
    coordinate: CLLocationCoordinate2D(latitude: 45.52, longitude: -122.681944),
    size: .medium,
    iconName: "cafe"
)
markerOverlay.color = .brown
// main.m
MBMarker *markerOverlay = [[MBMarker alloc] initWithCoordinate:CLLocationCoordinate2DMake(45.52, -122.681944)
                                                          size:MBMarkerSizeMedium
                                                      iconName:@"cafe"];
#if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_WATCH
    markerOverlay.color = [UIColor brownColor];
#elif TARGET_OS_MAC
    markerOverlay.color = [NSColor brownColor];
#endif

Custom marker

// main.swift
let customMarker = CustomMarker(
    coordinate: CLLocationCoordinate2D(latitude: 45.522, longitude: -122.69),
    url: URL(string: "https://www.mapbox.com/help/img/screenshots/rocket.png")!
)
// main.m
NSURL *url = [NSURL URLWithString:@"https://www.mapbox.com/help/img/screenshots/rocket.png"];
MBCustomMarker *customMarker = [[MBCustomMarker alloc] initWithCoordinate:CLLocationCoordinate2DMake(45.522, -122.69)
                                                                      url:url];

GeoJSON

// main.swift
let geoJSONOverlay: GeoJSON

do {
    let geoJSONURL = URL(string: "http://git.io/vCv9U")!
    let geoJSONString = try String(contentsOf: geoJSONURL, encoding: .utf8)
    geoJSONOverlay = GeoJSON(objectString: geoJSONString)
}
// main.m
NSURL *geoJSONURL = [NSURL URLWithString:@"http://git.io/vCv9U"];
NSString *geoJSONString = [[NSString alloc] initWithContentsOfURL:geoJSONURL
                                                         encoding:NSUTF8StringEncoding
                                                            error:NULL];
MBGeoJSON *geoJSONOverlay = [[MBGeoJSON alloc] initWithObjectString:geoJSONString];

Path

// main.swift
let path = Path(
    coordinates: [
        CLLocationCoordinate2D(
            latitude: 45.52475063103141, longitude: -122.68209457397461
        ),
        CLLocationCoordinate2D(
            latitude: 45.52451009822193, longitude: -122.67488479614258
        ),
        CLLocationCoordinate2D(
            latitude: 45.51681250530043, longitude: -122.67608642578126
        ),
        CLLocationCoordinate2D(
            latitude: 45.51693278828882, longitude: -122.68999099731445
        ),
        CLLocationCoordinate2D(
            latitude: 45.520300607576864, longitude: -122.68964767456055
        ),
        CLLocationCoordinate2D(
            latitude: 45.52475063103141, longitude: -122.68209457397461
        )
    ]
)
path.strokeWidth = 2
path.strokeColor = .black
#if os(macOS)
    path.fillColor = NSColor.red.withAlphaComponent(0.25)
#else
    path.fillColor = UIColor.red.withAlphaComponent(0.25)
#endif
// main.m
CLLocationCoordinate2D coordinates[] = {
    CLLocationCoordinate2DMake(45.52475063103141, -122.68209457397461),
    CLLocationCoordinate2DMake(45.52451009822193, -122.67488479614258),
    CLLocationCoordinate2DMake(45.51681250530043, -122.67608642578126),
    CLLocationCoordinate2DMake(45.51693278828882, -122.68999099731445),
    CLLocationCoordinate2DMake(45.520300607576864, -122.68964767456055),
    CLLocationCoordinate2DMake(45.52475063103141, -122.68209457397461),
};
MBPath *path = [[MBPath alloc] initWithCoordinates:coordinates
                                             count:sizeof(coordinates) / sizeof(coordinates[0])];
path.strokeWidth = 2;
#if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_WATCH
    path.strokeColor = [UIColor blackColor];
    path.fillColor = [[UIColor redColor] colorWithAlphaComponent:0.25];
#elif TARGET_OS_MAC
    path.strokeColor = [NSColor blackColor];
    path.fillColor = [[NSColor redColor] colorWithAlphaComponent:0.25];
#endif

Other options

Rotation and tilt

To rotate and tilt a snapshot, set its camera’s heading and pitch:

// main.swift
let camera = SnapshotCamera(
    lookingAtCenter: CLLocationCoordinate2D(latitude: 45.52, longitude: -122.681944),
    zoomLevel: 13)
camera.heading = 45
camera.pitch = 60
let options = SnapshotOptions(
    styleURL: URL(string: "<#your mapbox: style URL#>")!,
    camera: camera,
    size: CGSize(width: 200, height: 200))
let snapshot = Snapshot(
    options: options,
    accessToken: "<#your access token#>")
// main.m
NSURL *styleURL = [NSURL URLWithString:@"<#your mapbox: style URL#>"];
MBSnapshotCamera *camera = [MBSnapshotCamera cameraLookingAtCenterCoordinate:CLLocationCoordinate2DMake(45.52, -122.681944)
                                                                   zoomLevel:13];
camera.heading = 45;
camera.pitch = 60;
MBSnapshotOptions *options = [[MBSnapshotOptions alloc] initWithStyleURL:styleURL
                                                                  camera:camera
                                                                    size:CGSizeMake(200, 200)];
MBSnapshot *snapshot = [[MBSnapshot alloc] initWithOptions:options
                                               accessToken:@"<#your access token#>"];

Auto-fitting features

If you’re adding overlays to a snapshot, leave out the center coordinate and zoom level to automatically calculate the center and zoom level that best shows them off.

// main.swift

let options = SnapshotOptions(
    styleURL: URL(string: "<#your mapbox: style URL#>")!,
    size: CGSize(width: 500, height: 300))
options.overlays = [path, geojsonOverlay, markerOverlay, customMarker]
// main.m
NSURL *styleURL = [NSURL URLWithString:@"<#your mapbox: style URL#>"];
MBSnapshotOptions *options = [[MBSnapshotOptions alloc] initWithStyleURL:styleURL
                                                                    size:CGSizeMake(500, 300)];
options.overlays = @[path, geojsonOverlay, markerOverlay, customMarker];

Attribution

Be sure to attribute your map properly in your application. You can also find out more about where Mapbox’s map data comes from.

Tests

To run the included unit tests, you need to use Carthage 0.19 or above to install the dependencies.

  1. carthage bootstrap
  2. open MapboxStatic.xcodeproj
  3. Go to Product ‣ Test.

mapboxstatic.swift's People

Contributors

1ec5 avatar captainbarbosa avatar frederoni avatar friedbunny avatar gabrielgarza avatar heystenson avatar hyerra avatar incanus avatar maximalien avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mapboxstatic.swift's Issues

Provide an enum for common styles

The SnapshotOptions(styleURL:, camera:, size:) takes a style parameter which we need to specify a URL for. It would be nice if an enum could be created so we can specify something like satelliteStyleURL kind of like how the Mapbox SDK has it. This way users don't have to remember to update to the latest version.

Objective-C example

There should be an example for working with this library in Objective-C. If Objective-C support is lacking, we should make sure it works. This would be a prerequisite for combining the library with MapboxGeocoder.swift and MapboxDirections.swift.

/cc @friedbunny

I need some help, this is not an issue

I don't know who else to ask help so I'm trying here sorry but this is how works...

I'm using Mapbox for tracking device and I need to display clustered positions like we have on default Apple maps. I'm reading this sample but this is totally fair away my reality here.
https://docs.mapbox.com/ios/maps/examples/clustering/

I get my positions from a service, not a geoJSON file, so that approach simple doesn't work for us. I need to display clustered when zooming out because we have a lot of positions but we still need do declutter it when tap, as I said, exactly like Apple Maps does.

Can you provide me samples for doing it? I just can't find anyone else that understand the documentation right now.

MBSnapshot is implemented in both MobileBackup and MapboxStatic

Hello, Mapbox team!
I've encountered a following issue on iOS 13.5:

objc[5073]: Class MBSnapshot is implemented in both /System/Library/PrivateFrameworks/MobileBackup.framework/MobileBackup (0x1f4d85af8) and /private/var/[redacted]/Frameworks/MapboxStatic.framework/MapboxStatic (0x109100ee8). One of the two will be used. Which one is undefined.

Can you please rename your class somehow to have either a three-letter prefix or a different name? From the Guidelines looks like that Apple has reserved a two-letter prefixes for their own frameworks :/

Snapshot conflicts with MBSnapshot in MobileBackup

The Snapshot class has an Objective-C name of MBSnapshot, which conflicts with an identically named class in the private MobileBackup framework:

@objc(MBSnapshot)
open class Snapshot: NSObject {

The following message appeared at launch in a Swift application. The application’s implementation language didn’t matter, because @objc() affects the runtime class name in both languages.

objc[1573]: Class MBSnapshot is implemented in both /System/Library/PrivateFrameworks/MobileBackup.framework/MobileBackup (0x2411118a0) and /private/var/containers/Bundle/Application/5378C9A6-3281-4848-AED1-E0388600151B/….app/Frameworks/MapboxStatic.framework/MapboxStatic (0x1094c53c0). One of the two will be used. Which one is undefined.

Looks like we’ll need to give Snapshot a different name, such as MapSnapshot.

/cc @friedbunny @captainbarbosa @frederoni

.overview alternative?

On Mapbox 11 (SwiftUI) I'm using .overview to fit the camera to a specific region. How can I do the same with MapboxStatic?

viewport = .overview(
  geometry: Polygon([[
    LocationCoordinate2D(latitude: minLatitude, longitude: minLongitude),
    LocationCoordinate2D(latitude: minLatitude, longitude: maxLongitude),
    LocationCoordinate2D(latitude: maxLatitude, longitude: minLongitude),
    LocationCoordinate2D(latitude: maxLatitude, longitude: maxLongitude)
  ]])
)

Build universal framework target for Carthage

MapboxStatic.xcodeproj currently has four separate framework targets, one for each platform, plus corresponding test targets and schemes. To streamline development both locally and downstream, we should combine them into a single framework target and test target. Downstream, only Carthage uses the Xcode project; it has supported universal frameworks since v0.9. The CircleCI configuration needs to be updated to refer to the new combined scheme.

/ref mapbox/turf-swift#197 mapbox/mapbox-directions-swift#730

consider rename

The more I think about this library, the more I think it really fills a neat niche in iOS tools, since MapKit gives you nothing even close to this. That said, MapboxStatic is not a welcoming name, even if it is in line with our backend service.

Something like MapboxImage or MapImage could be better here, since it speaks to the produced result: a UIImage of a map.

Warning about redundant modifier in Xcode 10.2

The following compiler warning appears in MapboxStatic.swift when integrated into a Swift 4.2 application using CocoaPods 1.6.1 and built in Xcode 10.2:

/path/to/Pods/MapboxStatic.swift/MapboxStatic/Color.swift:32:5: warning: 'internal' modifier is redundant for property declared in an internal extension
    internal var alphaComponent: CGFloat {
    ^~~~~~~~~

/cc @frederoni @captainbarbosa

Documentation

We should add documentation strings to this library

Network error on WatchOS Device

On Apple Watch Device I've Network errors and the image is not loaded:

2023-05-05 12:02:52.574064+0200 Pin Vision Watch App[423:14134] Error getting network data status Error Domain=NSPOSIXErrorDomain Code=19 "Operation not supported by device"
2023-05-05 12:02:52.574407+0200 Pin Vision Watch App[423:14134] Task <C1C21836-E556-4D68-B493-977A1D301FB5>.<0> HTTP load failed, 0/0 bytes (error code: -1009 [1:50])
2023-05-05 12:02:52.574955+0200 Pin Vision Watch App[423:14131] NSURLConnection finished with error - code -1009

In simulator the image is loaded correctly without errors.

How can I load map images directly in Device?
Thanks!

Support OS X

On OS X, AppKit uses NSImage and NSColor instead of UIImage and UIColor. We should use Swift’s target conditional macros to switch between these types. A couple strategic typealiases could make these even easier.

/cc @tmcw

Rename map identifiers to tileset identifiers

Map IDs are being renamed to tileset IDs across the board. The only impacts to this library are the ClassicSnapshotOptions.mapIdentifiers property and associated initializer arguments:

@objc open var mapIdentifiers: [String]
@objc public init(mapIdentifiers: [String], size: CGSize) {

/cc @mapbox/maps-ios @brsbl

Path limit

Hi, is there a limit to coordinates array length to build a path overlay?
I need to draw about 3000 CLLocationCoordinate2D on the map, but i'm getting
MBStaticErrorDomain" - code: 18446744073709551615
when getting image from Snapshot object.
Until 1500 CLLocationCoordinate2D works well, I'm getting right the map.

Thank you.

Convert MapView camera zoom to SnapshotCamera zoomLevel

I have a mapView implemented and I want to snapshot this mapView
I read the document and create a SnapshotOption like this:

let center = mapView.cameraState.center
let zoom = mapView.cameraState.zoom
let snapshotCamera = SnapshotCamera(lookingAtCenter: center, zoomLevel: zoom > 20 ? 20 : zoom)
let options = SnapshotOptions(
    styleURL: styleURL,
    camera: snapshotCamera,
    size: mapView.bounds.size)
let snapshot = Snapshot(
    options: options,
    accessToken: "<accessToken>"
)
let image = snapshot.image

But it seems like the zoomLevel of SnapshotCamera is not the same with zoom level of MapView camera so the UIImage I received is zoomed more than I expected.
My question is how to convert MapView camera zoom to SnapshotCamera zoomLevel?
Thanks!

Static map display language

Hello, in our iOS app our static map is displayed in english, is there a way to display it in another language ?

Thanks

Read API base URL from Info.plist

If no host is passed into Snapshot(options:accessToken:host:), the fallback hostname should be either api.mapbox.com or api.mapbox.cn depending on the value of MGLMapboxAPIBaseURL in Info.plist:

baseURLComponents.host = host ?? "api.mapbox.com"

This would be consistent with how we read the access token out of Info.plist:

/// The Mapbox access token specified in the main application bundle’s Info.plist.
let defaultAccessToken = Bundle.main.object(forInfoDictionaryKey: "MGLMapboxAccessToken") as? String

/ref mapbox/MapboxGeocoder.swift#107
/cc @m-stephen

Add initializers to convert between Overlay and Turf GeoJSON types

Turf provides full strongly-typed support for GeoJSON, including conveniences like Codable conformance. The Overlay class should have convenience initializers for these types and vice versa. These conveniences would require pulling in Turf as a dependency and would not bridge to Objective-C.

Migrate to Swift 3

Hello,

i really need to work with the MapboxStatic.framework

When is do you plan the full support release for swift 3

Kind Regards
Alex

roll as framework

Including a raw Swift file is quick & easy, but this should be a framework for namespacing purposes, at least (e.g. JSON type).

Remove outdated assertions about server-enforced limits

We should remove assertions about server-enforced limits that are likely to change in the future and update any others that have changed.

The API now supports up to zoom level 22:

assert(0...20 ~= zoomLevel, "Zoom level must be between 0 and 20.")

The API no longer documents a limit to the number of overlays:

assert(overlays.count <= 100, "maximum number of overlays is 100")

The API still documents an image size limit, but we should probably remove this assertion in favor of a server-side error, in case the limit changes in the future:

assert(1...1_280 ~= size.width, "Width must be between 1 and 1,280 points.")
assert(1...1_280 ~= size.height, "Height must be between 1 and 1,280 points.")

/cc @ZiZasaurus

Path: always draw a polygon instead of a polyline

Hi,
I want to use the class Path to draw a polyline (my start point differs from my end point) and it doesn't work anymore, it's always a closes polygone being drawn. It's pretty weird because in your demo it works fine (polyline) in my playground and I copy the exact same code in my project, it's a polygon...

Not Possible to create a Polyline with MBPath anymore?

Before the upgrade from classic it was possible to use MBPath to create polylines, now they create a polygon instead by adding a line between the last and first points.

I've also verified that the path is being uploaded with out the final coordinate to close the polyline into a polygon

Bundle is damaged or missing necessary resources

I've been able to make the standard mapbox gl for macos work with my application, but am having an issue with the static sdk.

I built the xcode project and put the resulting framework in my target's link binary with libraries section.

Upon running the program I get a message saying the bundle is damaged or missing necessary resources, so I tried to add a copy files for the framework to the target as well as an appropriate runpath, but the problem persists.

The only difference that I can see between the static framework and the standard one in my target directory is that the static is missing a _codesign folder. Could this be part of the issue or am I looking in the wrong direction?

Avoid compiler error when built on unrecognized operating system

The user agent string construction code should accommodate unrecognized operating systems for consistency with mapbox/mapbox-directions-swift#486 and mapbox/mapbox-speech-swift#41:

let system: String
#if os(OSX)
system = "macOS"
#elseif os(iOS)
system = "iOS"
#elseif os(watchOS)
system = "watchOS"
#elseif os(tvOS)
system = "tvOS"
#elseif os(Linux)
system = "Linux"
#endif
let systemVersion = ProcessInfo().operatingSystemVersion
components.append("\(system)/\(systemVersion.majorVersion).\(systemVersion.minorVersion).\(systemVersion.patchVersion)")
let chip: String
#if arch(x86_64)
chip = "x86_64"
#elseif arch(arm)
chip = "arm"
#elseif arch(arm64)
chip = "arm64"
#elseif arch(i386)
chip = "i386"
#elseif os(watchOS) // Workaround for incorrect arch in machine.h for simulator ⌚️ gen 4
chip = "i386"
#else
chip = "unknown"
#endif
components.append("(\(chip))")

/cc @gwynne

Crashes at URL Construction

Given the following code:

let preferredBounds = viewModel.preferredBounds
let camera = SnapshotCamera(lookingAtCenter: preferredBounds.midpoint, zoomLevel: 12.0)

guard let url = URL(string: Constants.mapboxTheme) else { return .init(value: nil) }

let options = SnapshotOptions(styleURL: url, camera: camera, size: contentSize)
            
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 ]

let snapshot = Snapshot(options: options, accessToken: Constants.mapboxAPIKey)
...

When attempting to load the image asynchronously, the application crashes in Snapshot.swift here:

open var url: URL {
    var components = URLComponents()
    components.queryItems = params
    return URL(string: "\(options.path)?\(components.percentEncodedQuery!)", relativeTo: apiEndpoint)!
}

The URL(...) that is being force unwrapped is nil.

The values used are all present and (except for the API key) look as follows:

options.path =

/styles/v1/USER_NAME/cilwvi5hp007dcglv13toc5zd/static/path-2+#000000-1.0+#000555-1.0(skutE_dv%7BXu@b%5E%7DIpW)/135.7849645615,35.01171633755,12.0/375x240@2x

components.percentEncodedQuery! =

access_token=xx.eyXXXXXXXXN9ubWlsXXXXXXXXXXXNpbHdzcjAXXXXXXXXXXXXXXXXNTXXXXXXXXNoVBXXXXXXXXNwmaQ

(key is valid and works elsewhere, replaced characters with X's)

apiEndpoint =

https://api.mapbox.com

Do you have any guidance? Running on Xcode 8.3.2, and deploying to iOS 10.2

Localizated Labels

Hello,

is there a opportunity to change the label localization like in MapBox?

thanks

I got crash error when build example(swift)

dyld: Library not loaded: @rpath/Polyline.framework/Polyline
Referenced from: /Users/ouken/Library/Developer/Xcode/DerivedData/MapboxStatic-gdnazulaqdncxsdhkvisjiiehynv/Build/Products/Debug-iphonesimulator/MapboxStatic.framework/MapboxStatic
Reason: image not found

more unit test coverage

Lower priority for now since we've determined what we need to from writing the initial tests, but Xcode 7 shows some lack of coverage:

screen shot 2015-10-29 at 10 30 46 am

We should be exercising things like color-to-hex and vice-versa.

SPM support not working

A 0.10.1 version will need to be published before Swift Package Manager can be fully supported. This is because SPM checks out given release in the repository and Package.swift did not exist when 0.10.0 was published. A new version needs to be published that dependents can point to.

I would love to integrate Mapbox using SPM, but this is currently blocking.

Thank you!

[CFNetwork] Synchronous URL loading of https://api.mapbox.com/styles/v1/mapbox..... should not occur on this application's main thread as it may lead to UI unresponsiveness. Please switch to an asynchronous networking API such as URLSession.

Xcode show the warning when I tried to access to Snapshot#image:
[CFNetwork] Synchronous URL loading of https://api.mapbox.com/styles/v1/mapbox..... should not occur on this application's main thread as it may lead to UI unresponsiveness. Please switch to an asynchronous networking API such as URLSession.
The class emitted this warning is Snapshot
Screenshot 2023-07-06 at 16 39 58

Please help to check.
This is my sample code:

func takeSnapshot(mapView: MapView, passedLocations: [[CLLocation]]) -> UIImage? {
        var overlays = [Overlay]()
        overlays.append(contentsOf: markers.compactMap { marker in
            if let url = URL(string: marker.type.iconURL) {
                return CustomMarker(coordinate: marker.location.coordinate, url: url)
            }
            return nil
        })
        passedLocations.forEach { locations in
            let coordinates = locations.map { $0.coordinate }
            if coordinates.count >= 2 {
                let path = Path(
                    coordinates: coordinates
                )
                path.strokeColor = UIColor(red: 0.376, green: 0.439, blue: 0.941, alpha: 1)
                path.strokeWidth = 3
                path.fillColor = .clear
                overlays.append(path)
            }
        }

        let center = mapView.cameraState.center
        let zoom = mapView.cameraState.zoom
        let snapshotCamera = SnapshotCamera(lookingAtCenter: center, zoomLevel: zoom > 20 ? 20 : zoom)

        if let styleURL = URL(string: StyleURI.streets.rawValue) {
            let options = SnapshotOptions(
                styleURL: styleURL,
                camera: snapshotCamera,
                size: mapView.bounds.size)

            options.overlays = overlays
            let snapshot = Snapshot(
                options: options,
                accessToken: MapBoxResource.accessToken
            )
            return snapshot.image
        }
        return nil
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.