Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace StaticMap with Snapshot and SnapshotOptions #19

Merged
merged 5 commits into from
May 12, 2016
Merged

Conversation

1ec5
Copy link
Contributor

@1ec5 1ec5 commented May 12, 2016

This PR overhauls the code and API to ever-so-vaguely resemble MapKit’s MKMapSnapshotter API. A SnapshotOptions object and access token are passed into the Snapshot initializer, which builds a URL request and can fetch the image either synchronously or asynchronously. If no access token is passed into the Snapshot initializer, it is read from the Info.plist, just like the Mapbox iOS SDK does.

I considered reimplementing the URL request logic atop RequestKit, for consistency with MapboxGeocoder.swift and MapboxDirections.swift. However, this library would benefit very little from RequestKit, and RequestKit would make it difficult for client code to load the image synchronously or get at the request URL, both being use cases highlighted in the readme.

Instead of setting an autoFitFeatures parameter, auto-fitting is enabled when the center coordinate is absent – Null Island is no longer the default center point.

This PR also increases usage of NSURL and NSURLComponents to ensure correct URL handling and adds an optional NSError to the completion handler, in case things go awry.

/cc @tmcw @friedbunny

1ec5 added 2 commits May 12, 2016 00:03
Overhauled the code to ever-so-vaguely resemble MapKit’s MKMapSnapshotter API. A SnapshotOptions object and access token are passed into the Snapshot initializer, which builds a URL request and can fetch the image either synchronously or asynchronously. Instead of setting an “autoFitFeatures” parameter, auto-fitting is enabled when the center coordinate is absent – Null Island is no longer the default center point.

If no access token is passed into the Snapshot initializer, it is read from the Info.plist, just like the Mapbox iOS SDK does.

Increased usage of NSURL and NSURLComponents to ensure correct URL handling. Added an optional NSError to the completion handler, in case things go awry.
Return the task so that client code has an opportunity to cancel the request.
@1ec5 1ec5 self-assigned this May 12, 2016
1ec5 added 3 commits May 12, 2016 00:16
The code correctly handles 3× by requesting a 2× image, so no assertion is needed.
@1ec5 1ec5 merged commit 111150a into master May 12, 2016
@1ec5 1ec5 deleted the 1ec5-options branch May 12, 2016 07:27
1ec5 added a commit to mapbox/MapboxGeocoder.swift that referenced this pull request May 20, 2016
Rewrote the library to more closely parallel mapbox/MapboxStatic.swift#19. Removed the class prefix from Swift but kept it for Objective-C. The goal is no longer to be a (poor) drop-in replacement for MapKit’s MKDirections API but rather to be as idiomatic as possible in Swift and Objective-C, with a priority on Swift. Symbols conform to platform naming conventions but in some cases eschew MapKit terminology in favor of Geocoding API terminology, so that api-documentation makes sense in the context of this library.

Removed the dependency on RequestKit. This library chooses reasonable default networking behavior; if you need anything more sophisticated, you can access the URL request information to use with a custom NSURLSession. Geocoder no longer needs to be strongly held in order for the request to finish. Instead, the request is made against the shared URL session; to use a custom URL session, make the request yourself using the URL returned by the URLForGeocoding(options:) property. Removed the cancelGeocode() method; instead, directly cancel the NSURLSessionDataTask returned by geocode(options:completionHandler:).

Added a shared (singleton) Geocoder object. Use the shared object if you’ve set your Mapbox access token in the MGLMapboxAccessToken key of your application’s Info.plist file. Otherwise, create a Geocoder object with the access token explicitly. A single geocoder object can handle multiple requests concurrently (since it just passes the requests off to the shared URL session).

Unified geocodeAddressString(_:completionHandler:) and reverseGeocodeLocation(_:completionHandler:) into a single geocode(options:completionHandler:) method that takes a GeocodeOptions object. There are two subclasses of GeocodeOptions, ForwardGeocodeOptions and ReverseGeocodeOptions, that support all the options exposed by the Geocoding API. Effectively, this change adds support for the Geocoding API’s autocomplete and bbox options. Added an attribution parameter to the completion handler that contains required legal notices. The access_token parameter is now the last URL parameter instead of the first.

Replaced the Placemark.Scope enum with the PlacemarkScope bitmask, which is implemented in Objective-C so that Objective-C code can use it too. Using a bitmask prevents client code from specifying a scope multiple times. Renamed AdministrativeArea to Region, reflecting the Geocoding API result type.

For Placemark objects representing addresses and points of interest, the name property is no longer fully qualified; that is, it no longer contains the full administrative hierarchy. For the fully-qualified name, use the qualifiedName property. Properties such as country and postalCode return Placemark objects instead of strings; to get the name of e.g. the surrounding country, use the returned placemark object’s name property. A new qualifiers property returns the entire placemark hierarchy in indexer order, in case there’s any overlap between containing placemarks. Renamed ISOcountryCode to code; this property may be included in subnational placemarks, such as placemarks representing regions. Replaced the administrativeArea and subAdministrativeArea properties with administrativeRegion and district, respectively. Unlike the old subAdministrativeRegion property, district may be nil if it isn’t applicable. Renamed locality to place, and subLocality to neighborhood. Added a wikidataEntityIdentifier property corresponding to the Geocoding API’s wikidata property.

Removed the CLLocationCoordinate2D equality operator to avoid conflicts with client code that may define the same.

Upgraded Podfile to CocoaPods 1.0 format. Enabled code coverage gathering. Updated text fixtures and expectations.

Fixes #39, fixes #40.
1ec5 added a commit to mapbox/mapbox-directions-swift that referenced this pull request May 31, 2016
Rewrote the library to more closely parallel mapbox/MapboxGeocoder.swift#41 and mapbox/MapboxStatic.swift#19. Removed the class prefix from Swift but kept it for Objective-C. The goal is no longer to be a (poor) drop-in replacement for MapKit’s MKDirections API but rather to be as idiomatic as possible in Swift and Objective-C, with a priority on Swift. Symbols conform to platform naming conventions but in some cases eschew MapKit terminology in favor of Geocoding API terminology, so that api-documentation makes sense in the context of this library.

Removed the dependency on RequestKit. This library chooses reasonable default networking behavior; if you need anything more sophisticated, you can access the URL request information to use with a custom NSURLSession. Directions no longer needs to be strongly held in order for the request to finish. Instead, the request is made against the shared URL session; to use a custom URL session, make the request yourself using the URL returned by the URLForCalculatingDirections(options:) method. Removed the cancel() method; instead, directly cancel the NSURLSessionDataTask returned by calculateDirections(options:completionHandler:).

Added a shared (singleton) Directions object. Use the shared object if you’ve set your Mapbox access token in the MGLMapboxAccessToken key of your application’s Info.plist file. Otherwise, create a Directions object with the access token explicitly. A single directions object can handle multiple requests concurrently (since it just passes the requests off to the shared URL session).

Eliminated the separate APIs for calculating ETAs. Instead, all the options supported by the Directions API, including flags for including steps and the overview geometry, are now exposed through a new RouteOptions class. Effectively, this change adds support for the geometries, overview, radiuses, steps, and continue_straight query parameters and allows the heading accuracy of any waypoint to be customized. However, note that steps are no longer returned by default, and the overview geometry is simplified by default. The access_token parameter is now the last URL parameter instead of the first. Broke out MBDirectionsRequest.TransportType into three profile identifier constants. You always specify a profile identifier, not a transport type. That makes the desired mode of transportation more open-ended.

Removed the MBDirectionsResponse class in favor of passing the waypoints and routes from the response directly into the completion handler. Renamed Route.geometry to Route.coordinates. For Objective-C compatibility, all enums are backed by integer types instead of String, but they’re CustomStringConvertible to allow for the same expressiveness we’re used to in Swift.

Error handling is much more robust now. Various error conditions returned by the API cause the localized failure reason and recovery suggestion to be set in the NSError object that is passed into the completion handler.

Updated test fixtures and expectations for the v5 server-side API and the revamped client-side API, and updated examples.

Fixes #41, fixes #43, fixes #44.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant