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

Turf update v0.5.0 #427

Merged
merged 6 commits into from
Jun 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ commands:
name: Restore cache
keys:
- carthage-v1-{{ .Environment.CIRCLE_JOB }}-{{ checksum "Cartfile.resolved" }}
- carthage-v1-{{ .Environment.CIRCLE_JOB }} # used if checksum fails

save-cache:
steps:
Expand Down
2 changes: 1 addition & 1 deletion Cartfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
github "raphaelmor/Polyline" ~> 4.2
github "mapbox/turf-swift" ~> 0.4
github "mapbox/turf-swift" ~> 0.5
2 changes: 1 addition & 1 deletion Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
binary "https://www.mapbox.com/ios-sdk/Mapbox-iOS-SDK.json" "5.9.0"
github "linksmt/OHHTTPStubs" "563f48d3fab84ef04639649c770b00f4fa502cca"
github "mapbox/turf-swift" "v0.4.0"
github "mapbox/turf-swift" "v0.5.0"
github "raphaelmor/Polyline" "v4.2.1"
2 changes: 1 addition & 1 deletion MapboxDirections.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ Pod::Spec.new do |s|
s.swift_version = "5.0"

s.dependency "Polyline", "~> 4.2"
s.dependency "Turf", "~> 0.4"
s.dependency "Turf", "~> 0.5"

end
10 changes: 0 additions & 10 deletions MapboxDirections.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
35D92FF0218203AB000C78CB /* 2018-10-16-Liechtenstein.tar in Resources */ = {isa = PBXBuildFile; fileRef = 35D92FEF218203AA000C78CB /* 2018-10-16-Liechtenstein.tar */; };
35D92FF1218203AB000C78CB /* 2018-10-16-Liechtenstein.tar in Resources */ = {isa = PBXBuildFile; fileRef = 35D92FEF218203AA000C78CB /* 2018-10-16-Liechtenstein.tar */; };
35D92FF2218203AB000C78CB /* 2018-10-16-Liechtenstein.tar in Resources */ = {isa = PBXBuildFile; fileRef = 35D92FEF218203AA000C78CB /* 2018-10-16-Liechtenstein.tar */; };
35DBF005217DF0D90009D2AE /* CoordinateBounds.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35DBF004217DF0D90009D2AE /* CoordinateBounds.swift */; };
35DBF006217DF0D90009D2AE /* CoordinateBounds.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35DBF004217DF0D90009D2AE /* CoordinateBounds.swift */; };
35DBF007217DF0D90009D2AE /* CoordinateBounds.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35DBF004217DF0D90009D2AE /* CoordinateBounds.swift */; };
35DBF008217DF0D90009D2AE /* CoordinateBounds.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35DBF004217DF0D90009D2AE /* CoordinateBounds.swift */; };
35DBF00F217E17A30009D2AE /* HTTPURLResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35DBF00E217E17A30009D2AE /* HTTPURLResponse.swift */; };
35DBF010217E17A30009D2AE /* HTTPURLResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35DBF00E217E17A30009D2AE /* HTTPURLResponse.swift */; };
35DBF011217E17A30009D2AE /* HTTPURLResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35DBF00E217E17A30009D2AE /* HTTPURLResponse.swift */; };
Expand Down Expand Up @@ -354,7 +350,6 @@
35828C9D217A003F00ED546E /* OfflineDirections.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OfflineDirections.swift; sourceTree = "<group>"; };
35CC310A2285739700EA1966 /* WalkingOptionsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WalkingOptionsTests.swift; sourceTree = "<group>"; };
35D92FEF218203AA000C78CB /* 2018-10-16-Liechtenstein.tar */ = {isa = PBXFileReference; lastKnownFileType = archive.tar; path = "2018-10-16-Liechtenstein.tar"; sourceTree = "<group>"; };
35DBF004217DF0D90009D2AE /* CoordinateBounds.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoordinateBounds.swift; sourceTree = "<group>"; };
35DBF00E217E17A30009D2AE /* HTTPURLResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTTPURLResponse.swift; sourceTree = "<group>"; };
35DBF013217E199E0009D2AE /* OfflineDirectionsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OfflineDirectionsTests.swift; sourceTree = "<group>"; };
35DBF018217F38A30009D2AE /* versions.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = versions.json; sourceTree = "<group>"; };
Expand Down Expand Up @@ -634,7 +629,6 @@
C5DAAC9E20191683001F9261 /* MapMatching */,
C51538CB1E807FF00093FF3E /* AttributeOptions.swift */,
C58EA7A91E9D7EAD008F98CE /* Congestion.swift */,
35DBF004217DF0D90009D2AE /* CoordinateBounds.swift */,
DD6254731AE70CB700017857 /* Directions.swift */,
43EBD3AC23DBC06800B09D05 /* DirectionsCredentials.swift */,
4392557523440EC2006EEE88 /* DirectionsError.swift */,
Expand Down Expand Up @@ -1223,7 +1217,6 @@
C5DAACA220195AB2001F9261 /* MatchOptions.swift in Sources */,
43D6617123DBA58E0062BFFE /* (null) in Sources */,
DA1A10CC1D00F969009F82FA /* Waypoint.swift in Sources */,
35DBF006217DF0D90009D2AE /* CoordinateBounds.swift in Sources */,
DAD06E3D23A00A01001A917D /* QuickLook.swift in Sources */,
DA1A10CA1D00F969009F82FA /* RouteOptions.swift in Sources */,
DA1A10C81D00F969009F82FA /* Route.swift in Sources */,
Expand Down Expand Up @@ -1302,7 +1295,6 @@
C5DAACA320195AB2001F9261 /* MatchOptions.swift in Sources */,
43D6617223DBA58E0062BFFE /* (null) in Sources */,
DA1A10F21D010247009F82FA /* Waypoint.swift in Sources */,
35DBF007217DF0D90009D2AE /* CoordinateBounds.swift in Sources */,
DAD06E3E23A00A02001A917D /* QuickLook.swift in Sources */,
DA1A10F01D010247009F82FA /* RouteOptions.swift in Sources */,
DA1A10EE1D010247009F82FA /* Route.swift in Sources */,
Expand Down Expand Up @@ -1381,7 +1373,6 @@
C5DAACA420195AB3001F9261 /* MatchOptions.swift in Sources */,
43D6617323DBA58E0062BFFE /* (null) in Sources */,
DA1A11091D0103A3009F82FA /* Waypoint.swift in Sources */,
35DBF008217DF0D90009D2AE /* CoordinateBounds.swift in Sources */,
DAD06E3F23A00A02001A917D /* QuickLook.swift in Sources */,
DA1A11071D0103A3009F82FA /* RouteOptions.swift in Sources */,
DA1A11051D0103A3009F82FA /* Route.swift in Sources */,
Expand Down Expand Up @@ -1428,7 +1419,6 @@
DAC05F181CFC075300FA0071 /* Route.swift in Sources */,
43D6617023DBA58E0062BFFE /* (null) in Sources */,
C59094BF203B800300EB2417 /* DirectionsOptions.swift in Sources */,
35DBF005217DF0D90009D2AE /* CoordinateBounds.swift in Sources */,
DAD06E3C23A00A01001A917D /* QuickLook.swift in Sources */,
C5434B8C200695A50069E887 /* MatchOptions.swift in Sources */,
DAA76D681DD127CB0015EC78 /* LaneIndication.swift in Sources */,
Expand Down
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"repositoryURL": "https://github.com/mapbox/turf-swift.git",
"state": {
"branch": null,
"revision": "40079b9133402b1fd57a9845f8785cca19beb472",
"version": "0.3.0"
"revision": "985b4bdb7256c2f8adad10353b3338a466391469",
"version": "0.5.0"
}
}
]
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let package = Package(
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/raphaelmor/Polyline.git", from: "4.2.1"),
.package(url: "https://github.com/mapbox/turf-swift.git", from: "0.2.0")
.package(url: "https://github.com/mapbox/turf-swift.git", from: "0.5.0")
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
Expand Down
109 changes: 0 additions & 109 deletions Sources/MapboxDirections/CoordinateBounds.swift

This file was deleted.

33 changes: 33 additions & 0 deletions Sources/MapboxDirections/Extensions/Codable.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Foundation
import Polyline
import Turf
import CoreLocation

extension LineString {
/**
Expand Down Expand Up @@ -58,3 +59,35 @@ extension PolyLineString: Codable {
}
}
}

struct CLLocationCoordinate2DCodable: Codable {
var latitude: CLLocationDegrees
var longitude: CLLocationDegrees
var decodedCoordinates: CLLocationCoordinate2D {
return CLLocationCoordinate2D(latitude: latitude,
longitude: longitude)
}

func encode(to encoder: Encoder) throws {
var container = encoder.unkeyedContainer()
try container.encode(longitude)
try container.encode(latitude)
}

init(from decoder: Decoder) throws {
var container = try decoder.unkeyedContainer()
longitude = try container.decode(CLLocationDegrees.self)
latitude = try container.decode(CLLocationDegrees.self)
}

init(_ coordinate: CLLocationCoordinate2D) {
latitude = coordinate.latitude
longitude = coordinate.longitude
}
}

extension CLLocationCoordinate2D {
var codableCoordinates: CLLocationCoordinate2DCodable {
return CLLocationCoordinate2DCodable(self)
}
}
6 changes: 6 additions & 0 deletions Sources/MapboxDirections/Extensions/GeoJSON.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ import CoreLocation
import Polyline
import Turf

extension BoundingBox: CustomStringConvertible {
public var description: String {
return "\(southWest.longitude),\(southWest.latitude);\(northEast.longitude),\(northEast.latitude)"
}
}

extension LineString {
init(polyLineString: PolyLineString) throws {
switch polyLineString {
Expand Down
7 changes: 4 additions & 3 deletions Sources/MapboxDirections/OfflineDirections.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import Turf

public typealias OfflineVersion = String
public typealias OfflineDownloaderCompletionHandler = (_ location: URL?,_ response: URLResponse?, _ error: Error?) -> Void
Expand All @@ -24,7 +25,7 @@ public protocol OfflineDirectionsProtocol {
- parameter version: The version to download. Version is represented as a String (yyyy-MM-dd-x)
- parameter completionHandler: A closure of type `OfflineDownloaderCompletionHandler` which will be called when the request completes
*/
func downloadTiles(in coordinateBounds: CoordinateBounds, version: OfflineVersion, completionHandler: @escaping OfflineDownloaderCompletionHandler) -> URLSessionDownloadTask
func downloadTiles(in coordinateBounds: BoundingBox, version: OfflineVersion, completionHandler: @escaping OfflineDownloaderCompletionHandler) -> URLSessionDownloadTask
}

extension Directions: OfflineDirectionsProtocol {
Expand All @@ -45,7 +46,7 @@ extension Directions: OfflineDirectionsProtocol {
- parameter version: A version obtained from `availableVersionsURL`.
- returns: The URL to generate and download the tile pack that covers the coordinate bounds.
*/
public func tilesURL(for coordinateBounds: CoordinateBounds, version: OfflineVersion) -> URL {
public func tilesURL(for coordinateBounds: BoundingBox, version: OfflineVersion) -> URL {
let url = credentials.host.appendingPathComponent("route-tiles/v1").appendingPathComponent(coordinateBounds.description)
var components = URLComponents(url: url, resolvingAgainstBaseURL: true)
components?.queryItems = [URLQueryItem(name: "version", value: version),
Expand Down Expand Up @@ -91,7 +92,7 @@ extension Directions: OfflineDirectionsProtocol {
- parameter completionHandler: A closure of type `OfflineDownloaderCompletionHandler` which will be called when the request completes
*/
@discardableResult
public func downloadTiles(in coordinateBounds: CoordinateBounds,
public func downloadTiles(in coordinateBounds: BoundingBox,
version: OfflineVersion,
completionHandler: @escaping OfflineDownloaderCompletionHandler) -> URLSessionDownloadTask {
let url = tilesURL(for: coordinateBounds, version: version)
Expand Down
16 changes: 3 additions & 13 deletions Tests/MapboxDirectionsTests/OfflineDirectionsTests.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import XCTest
#if !SWIFT_PACKAGE
import OHHTTPStubs
import Turf
@testable import MapboxDirections

class OfflineDirectionsTests: XCTestCase {
Expand Down Expand Up @@ -34,22 +35,11 @@ class OfflineDirectionsTests: XCTestCase {

wait(for: [versionsExpectation], timeout: 2)
}

func testCoordinateBounds() {
let bounds = CoordinateBounds(coordinates: [CLLocationCoordinate2D(latitude: 37.7890, longitude: -122.4337),
CLLocationCoordinate2D(latitude: 37.7881, longitude: -122.4318)])
XCTAssertEqual(bounds.southWest.latitude, 37.7881)
XCTAssertEqual(bounds.southWest.longitude, -122.4337)
XCTAssertEqual(bounds.northEast.latitude, 37.7890)
XCTAssertEqual(bounds.northEast.longitude, -122.4318)
XCTAssertEqual(bounds.description, "-122.4337,37.7881;-122.4318,37.789")
}

func testDownloadTiles() {
let directions = Directions(credentials: BogusCredentials)

let bounds = CoordinateBounds(coordinates: [CLLocationCoordinate2D(latitude: 37.7890, longitude: -122.4337),
CLLocationCoordinate2D(latitude: 37.7881, longitude: -122.4318)])
let bounds = BoundingBox(CLLocationCoordinate2D(latitude: 37.7890, longitude: -122.4337),
CLLocationCoordinate2D(latitude: 37.7881, longitude: -122.4318))

let version = "2018-10-16"
let downloadExpectation = self.expectation(description: "Download tile expectation")
Expand Down