diff --git a/SampleApp/AutocompleteTableVC.swift b/SampleApp/AutocompleteTableVC.swift index 1a25325..5fed2cc 100644 --- a/SampleApp/AutocompleteTableVC.swift +++ b/SampleApp/AutocompleteTableVC.swift @@ -52,15 +52,15 @@ class AutocompleteTableVC: SampleTableViewController, UISearchResultsUpdating, U func updateSearchResults(for searchController: UISearchController) { if let searchText = searchController.searchBar.text, searchController.searchBar.text?.isEmpty == false { - var geoPoint = GeoPoint(latitude: 40.7312973034393, longitude: -73.99896644276561) + var geoPoint = Pelias.GeoPoint(latitude: 40.7312973034393, longitude: -73.99896644276561) if let location = currentLocation { - geoPoint = GeoPoint(latitude: location.coordinate.latitude, longitude: location.coordinate.longitude) + geoPoint = Pelias.GeoPoint(latitude: location.coordinate.latitude, longitude: location.coordinate.longitude) } let config = PeliasAutocompleteConfig(searchText: searchText, focusPoint: geoPoint, completionHandler: { (autocompleteResponse) -> Void in self.results = autocompleteResponse.parsedMapItems() self.tableView.reloadData() }) - PeliasSearchManager.sharedInstance.autocompleteQuery(config) + _ = PeliasSearchManager.sharedInstance.autocompleteQuery(config) } } diff --git a/SampleApp/RoutingViewController.swift b/SampleApp/RoutingViewController.swift index 21e7c13..6ac39a5 100644 --- a/SampleApp/RoutingViewController.swift +++ b/SampleApp/RoutingViewController.swift @@ -112,7 +112,7 @@ class RoutingViewController: UIViewController, RoutingSearchDelegate { } private func requestRoute() { - guard let routingController = try? MapzenRoutingController.controller() else { return } + guard let routingController = try? RoutingController.controller() else { return } routingController.updateLocale(routingLocale) guard let currentLocation = LocationManager.sharedManager.currentLocation, let destination = destination else { return } diff --git a/SampleApp/SearchPinsViewController.swift b/SampleApp/SearchPinsViewController.swift index 43b3cc7..b8cc7f5 100644 --- a/SampleApp/SearchPinsViewController.swift +++ b/SampleApp/SearchPinsViewController.swift @@ -29,7 +29,7 @@ class SearchPinsViewController: SampleMapViewController, UITextFieldDelegate { } func textFieldDidEndEditing(_ textField: UITextField) { - let geopoint = GeoPoint(location: LocationManager.sharedManager.currentLocation) + let geopoint = Pelias.GeoPoint(location: LocationManager.sharedManager.currentLocation) var searchConfig = PeliasSearchConfig(searchText: textField.text!) { [unowned self] (response) in guard let newAnnotations = response.parsedMapItems(target: self, action: #selector(self.annotationClicked(annotation:))) else { return } do { diff --git a/ios-sdk.xcodeproj/project.pbxproj b/ios-sdk.xcodeproj/project.pbxproj index f9045dd..0e306c0 100644 --- a/ios-sdk.xcodeproj/project.pbxproj +++ b/ios-sdk.xcodeproj/project.pbxproj @@ -9,6 +9,8 @@ /* Begin PBXBuildFile section */ 7D2FB7671E6103D500CB82CF /* DictionaryExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2FB7661E6103D500CB82CF /* DictionaryExtensions.swift */; }; 7D2FB7691E64E66B00CB82CF /* DictionaryExtensionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2FB7681E64E66B00CB82CF /* DictionaryExtensionsTests.swift */; }; + 7D4122721E84621A009520B7 /* SearchConfigs.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D4122711E84621A009520B7 /* SearchConfigs.swift */; }; + 7D4122741E84834C009520B7 /* SearchConfigsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D4122731E84834C009520B7 /* SearchConfigsTests.swift */; }; 7D503BCC1E77457A00FDDC4F /* SampleMapViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D503BCB1E77457A00FDDC4F /* SampleMapViewController.swift */; }; 7D503BCE1E77468B00FDDC4F /* SampleTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D503BCD1E77468B00FDDC4F /* SampleTableViewController.swift */; }; 7D503BD01E78944300FDDC4F /* TestTGMarkerPickResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D503BCF1E78944300FDDC4F /* TestTGMarkerPickResult.swift */; }; @@ -26,17 +28,23 @@ 7D9EBCD51E6E0CA200303E1B /* building-grid.gif in CopyFiles */ = {isa = PBXBuildFile; fileRef = 7D9EBBE21E6DFBAF00303E1B /* building-grid.gif */; }; 7D9EBCD81E6E0D9B00303E1B /* refill@2x.png in CopyFiles */ = {isa = PBXBuildFile; fileRef = 7D9EBC171E6DFBAF00303E1B /* refill@2x.png */; }; 7D9EBCDA1E6E0D9B00303E1B /* walkabout@2x.png in CopyFiles */ = {isa = PBXBuildFile; fileRef = 7D9EBC351E6DFBAF00303E1B /* walkabout@2x.png */; }; + 7DB181441E81B472001F9B49 /* SearchDataConverter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB1813E1E81B472001F9B49 /* SearchDataConverter.swift */; }; + 7DB181451E81B472001F9B49 /* SearchDataObjects.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB1813F1E81B472001F9B49 /* SearchDataObjects.swift */; }; + 7DB181491E81B681001F9B49 /* SearchResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB181481E81B681001F9B49 /* SearchResponse.swift */; }; + 7DB181531E81B73A001F9B49 /* SearchDataConverterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB181521E81B73A001F9B49 /* SearchDataConverterTests.swift */; }; + 7DB181551E81B745001F9B49 /* SearchDataObjectsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB181541E81B745001F9B49 /* SearchDataObjectsTests.swift */; }; + 7DB181571E81B77B001F9B49 /* SearchResponseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB181561E81B77B001F9B49 /* SearchResponseTests.swift */; }; 7DC7F0941E70C26B009E722B /* TestLocationManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DC7F0931E70C26B009E722B /* TestLocationManager.swift */; }; 7DC7F0981E71E138009E722B /* TestAnnotationTarget.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DC7F0971E71E138009E722B /* TestAnnotationTarget.swift */; }; 7DC7F09A1E7204BE009E722B /* MapzenManagerExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DC7F0991E7204BE009E722B /* MapzenManagerExtensions.swift */; }; 7DC7F09C1E72066B009E722B /* TestMapzenManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DC7F09B1E72066B009E722B /* TestMapzenManager.swift */; }; - 7DC7F0A21E770443009E722B /* MapzenRoutingControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DC7F0A11E770443009E722B /* MapzenRoutingControllerTests.swift */; }; + 7DC7F0A21E770443009E722B /* RoutingControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DC7F0A11E770443009E722B /* RoutingControllerTests.swift */; }; 7DF0AA2E1E5520ED00B0406E /* TestTGMapViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DF0AA2D1E5520ED00B0406E /* TestTGMapViewController.swift */; }; AC586709D7E7D4C22AA9474D /* Pods_ios_sdk.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 99B3EC60450343448FA4E699 /* Pods_ios_sdk.framework */; }; C8F52AC1BCE46BB17E1CE0A5 /* Pods_ios_sdkTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5A3EA87256F2EA6D0C43260A /* Pods_ios_sdkTests.framework */; }; DB188EEA1E2846600054DEFD /* MapzenManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB188EE91E2846600054DEFD /* MapzenManager.swift */; }; DB188EEC1E28492A0054DEFD /* MapzenManagerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB188EEB1E28492A0054DEFD /* MapzenManagerTests.swift */; }; - DB188EEE1E290D310054DEFD /* MapzenRoutingController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB188EED1E290D310054DEFD /* MapzenRoutingController.swift */; }; + DB188EEE1E290D310054DEFD /* RoutingController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB188EED1E290D310054DEFD /* RoutingController.swift */; }; DB188EF01E2C44F40054DEFD /* RouteDisplayViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB188EEF1E2C44F40054DEFD /* RouteDisplayViewController.swift */; }; DB22E59A1DA45D73004264E0 /* RoutingSearchVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB22E5991DA45D73004264E0 /* RoutingSearchVC.swift */; }; DB22E59C1DA46640004264E0 /* RoutingResultTableVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB22E59B1DA46640004264E0 /* RoutingResultTableVC.swift */; }; @@ -94,6 +102,8 @@ 5A3EA87256F2EA6D0C43260A /* Pods_ios_sdkTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_ios_sdkTests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 7D2FB7661E6103D500CB82CF /* DictionaryExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DictionaryExtensions.swift; sourceTree = ""; }; 7D2FB7681E64E66B00CB82CF /* DictionaryExtensionsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DictionaryExtensionsTests.swift; sourceTree = ""; }; + 7D4122711E84621A009520B7 /* SearchConfigs.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SearchConfigs.swift; sourceTree = ""; }; + 7D4122731E84834C009520B7 /* SearchConfigsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SearchConfigsTests.swift; sourceTree = ""; }; 7D503BCB1E77457A00FDDC4F /* SampleMapViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SampleMapViewController.swift; sourceTree = ""; }; 7D503BCD1E77468B00FDDC4F /* SampleTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SampleTableViewController.swift; sourceTree = ""; }; 7D503BCF1E78944300FDDC4F /* TestTGMarkerPickResult.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestTGMarkerPickResult.swift; sourceTree = ""; }; @@ -118,11 +128,17 @@ 7D9EBC421E6DFBAF00303E1B /* walkabout-style-more-labels.yaml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "walkabout-style-more-labels.yaml"; sourceTree = ""; }; 7D9EBC511E6DFBAF00303E1B /* refill@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "refill@2x.png"; sourceTree = ""; }; 7D9EBC5C1E6DFBAF00303E1B /* zinc-style-more-labels.yaml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "zinc-style-more-labels.yaml"; sourceTree = ""; }; + 7DB1813E1E81B472001F9B49 /* SearchDataConverter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SearchDataConverter.swift; sourceTree = ""; }; + 7DB1813F1E81B472001F9B49 /* SearchDataObjects.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SearchDataObjects.swift; sourceTree = ""; }; + 7DB181481E81B681001F9B49 /* SearchResponse.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SearchResponse.swift; sourceTree = ""; }; + 7DB181521E81B73A001F9B49 /* SearchDataConverterTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SearchDataConverterTests.swift; sourceTree = ""; }; + 7DB181541E81B745001F9B49 /* SearchDataObjectsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SearchDataObjectsTests.swift; sourceTree = ""; }; + 7DB181561E81B77B001F9B49 /* SearchResponseTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SearchResponseTests.swift; sourceTree = ""; }; 7DC7F0931E70C26B009E722B /* TestLocationManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestLocationManager.swift; sourceTree = ""; }; 7DC7F0971E71E138009E722B /* TestAnnotationTarget.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestAnnotationTarget.swift; sourceTree = ""; }; 7DC7F0991E7204BE009E722B /* MapzenManagerExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MapzenManagerExtensions.swift; sourceTree = ""; }; 7DC7F09B1E72066B009E722B /* TestMapzenManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestMapzenManager.swift; sourceTree = ""; }; - 7DC7F0A11E770443009E722B /* MapzenRoutingControllerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MapzenRoutingControllerTests.swift; sourceTree = ""; }; + 7DC7F0A11E770443009E722B /* RoutingControllerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RoutingControllerTests.swift; sourceTree = ""; }; 7DF0AA2D1E5520ED00B0406E /* TestTGMapViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestTGMapViewController.swift; sourceTree = ""; }; 92C35E8790FB3255237B1E77 /* Pods.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 99B3EC60450343448FA4E699 /* Pods_ios_sdk.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_ios_sdk.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -130,7 +146,7 @@ B96DEBA552AA3AAEA9CDF6F4 /* Pods-ios-sdk.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ios-sdk.debug.xcconfig"; path = "Pods/Target Support Files/Pods-ios-sdk/Pods-ios-sdk.debug.xcconfig"; sourceTree = ""; }; DB188EE91E2846600054DEFD /* MapzenManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MapzenManager.swift; sourceTree = ""; }; DB188EEB1E28492A0054DEFD /* MapzenManagerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MapzenManagerTests.swift; sourceTree = ""; }; - DB188EED1E290D310054DEFD /* MapzenRoutingController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MapzenRoutingController.swift; sourceTree = ""; }; + DB188EED1E290D310054DEFD /* RoutingController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RoutingController.swift; sourceTree = ""; }; DB188EEF1E2C44F40054DEFD /* RouteDisplayViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RouteDisplayViewController.swift; sourceTree = ""; }; DB22E5991DA45D73004264E0 /* RoutingSearchVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RoutingSearchVC.swift; sourceTree = ""; }; DB22E59B1DA46640004264E0 /* RoutingResultTableVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RoutingResultTableVC.swift; sourceTree = ""; }; @@ -386,10 +402,14 @@ 7DC7F0931E70C26B009E722B /* TestLocationManager.swift */, 7DC7F09B1E72066B009E722B /* TestMapzenManager.swift */, 7DC7F0971E71E138009E722B /* TestAnnotationTarget.swift */, - 7DC7F0A11E770443009E722B /* MapzenRoutingControllerTests.swift */, + 7DC7F0A11E770443009E722B /* RoutingControllerTests.swift */, 7D7D49941E7709A1006074EB /* TestUrlSession.swift */, 7D7D49921E7708E5006074EB /* TestSessionDataTask.swift */, 7D503BCF1E78944300FDDC4F /* TestTGMarkerPickResult.swift */, + 7DB181521E81B73A001F9B49 /* SearchDataConverterTests.swift */, + 7DB181541E81B745001F9B49 /* SearchDataObjectsTests.swift */, + 7DB181561E81B77B001F9B49 /* SearchResponseTests.swift */, + 7D4122731E84834C009520B7 /* SearchConfigsTests.swift */, ); path = "ios-sdkTests"; sourceTree = ""; @@ -397,16 +417,20 @@ DBC84EA51C985B6D00EE80D8 /* src */ = { isa = PBXGroup; children = ( + 7DB1813E1E81B472001F9B49 /* SearchDataConverter.swift */, + 7DB1813F1E81B472001F9B49 /* SearchDataObjects.swift */, 7D7847231E6775EA000D56CA /* dimensions */, DBC869911D3663C700DDC4FE /* PeliasMapkitExtensions.swift */, DB70FEA81DE3425800249509 /* MapViewController.swift */, DB5B31501DE4A173005EB816 /* LocationManager.swift */, DBFB759E1E2046D100CF6173 /* TangramExtensions.swift */, DB188EE91E2846600054DEFD /* MapzenManager.swift */, - DB188EED1E290D310054DEFD /* MapzenRoutingController.swift */, + DB188EED1E290D310054DEFD /* RoutingController.swift */, 7D2FB7661E6103D500CB82CF /* DictionaryExtensions.swift */, 7D7DAE201E60EEA300FFCA6F /* ApplicationExtensions.swift */, 7DC7F0991E7204BE009E722B /* MapzenManagerExtensions.swift */, + 7DB181481E81B681001F9B49 /* SearchResponse.swift */, + 7D4122711E84621A009520B7 /* SearchConfigs.swift */, ); path = src; sourceTree = ""; @@ -629,6 +653,7 @@ buildActionMask = 2147483647; files = ( DBFB759F1E2046D100CF6173 /* TangramExtensions.swift in Sources */, + 7DB181491E81B681001F9B49 /* SearchResponse.swift in Sources */, DBFB759D1E20345500CF6173 /* SearchPinsViewController.swift in Sources */, 7D7DAE211E60EEA300FFCA6F /* ApplicationExtensions.swift in Sources */, 7D7847251E6775EA000D56CA /* Dimensions.swift in Sources */, @@ -637,9 +662,10 @@ DB22E59E1DA473CA004264E0 /* RouteDirectionCell.swift in Sources */, DB5B31511DE4A173005EB816 /* LocationManager.swift in Sources */, DBC869921D3663C700DDC4FE /* PeliasMapkitExtensions.swift in Sources */, - DB188EEE1E290D310054DEFD /* MapzenRoutingController.swift in Sources */, + DB188EEE1E290D310054DEFD /* RoutingController.swift in Sources */, DB70FEA91DE3425800249509 /* MapViewController.swift in Sources */, 7D503BCC1E77457A00FDDC4F /* SampleMapViewController.swift in Sources */, + 7DB181451E81B472001F9B49 /* SearchDataObjects.swift in Sources */, DB22E59A1DA45D73004264E0 /* RoutingSearchVC.swift in Sources */, DBBF368B1D64DA6A0069D769 /* RoutingViewController.swift in Sources */, 7DC7F09A1E7204BE009E722B /* MapzenManagerExtensions.swift in Sources */, @@ -648,7 +674,9 @@ 7D503BCE1E77468B00FDDC4F /* SampleTableViewController.swift in Sources */, DB22E59C1DA46640004264E0 /* RoutingResultTableVC.swift in Sources */, DBC869901D3662DD00DDC4FE /* AutocompleteTableVC.swift in Sources */, + 7D4122721E84621A009520B7 /* SearchConfigs.swift in Sources */, DB7A33D81C8F8E8B009CC743 /* AppDelegate.swift in Sources */, + 7DB181441E81B472001F9B49 /* SearchDataConverter.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -657,14 +685,18 @@ buildActionMask = 2147483647; files = ( 7D7DAE1D1E60C5C900FFCA6F /* TestApplication.swift in Sources */, + 7D4122741E84834C009520B7 /* SearchConfigsTests.swift in Sources */, 7DC7F0941E70C26B009E722B /* TestLocationManager.swift in Sources */, 7DC7F0981E71E138009E722B /* TestAnnotationTarget.swift in Sources */, + 7DB181551E81B745001F9B49 /* SearchDataObjectsTests.swift in Sources */, 7DF0AA2E1E5520ED00B0406E /* TestTGMapViewController.swift in Sources */, + 7DB181571E81B77B001F9B49 /* SearchResponseTests.swift in Sources */, DB188EEC1E28492A0054DEFD /* MapzenManagerTests.swift in Sources */, 7DC7F09C1E72066B009E722B /* TestMapzenManager.swift in Sources */, 7D7D49951E7709A1006074EB /* TestUrlSession.swift in Sources */, - 7DC7F0A21E770443009E722B /* MapzenRoutingControllerTests.swift in Sources */, + 7DC7F0A21E770443009E722B /* RoutingControllerTests.swift in Sources */, 7D503BD01E78944300FDDC4F /* TestTGMarkerPickResult.swift in Sources */, + 7DB181531E81B73A001F9B49 /* SearchDataConverterTests.swift in Sources */, DBCBC5BF1E0AE1CF0045B345 /* MapViewControllerTests.swift in Sources */, 7D2FB7691E64E66B00CB82CF /* DictionaryExtensionsTests.swift in Sources */, 7D7D49931E7708E5006074EB /* TestSessionDataTask.swift in Sources */, @@ -797,6 +829,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + DEFINES_MODULE = NO; DEVELOPMENT_TEAM = LTQC954SPQ; ENABLE_BITCODE = NO; FRAMEWORK_SEARCH_PATHS = ( @@ -829,6 +862,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution"; + DEFINES_MODULE = NO; DEVELOPMENT_TEAM = LTQC954SPQ; ENABLE_BITCODE = NO; FRAMEWORK_SEARCH_PATHS = ( diff --git a/ios-sdkTests/MapzenManagerTests.swift b/ios-sdkTests/MapzenManagerTests.swift index 75bc96d..7f47745 100644 --- a/ios-sdkTests/MapzenManagerTests.swift +++ b/ios-sdkTests/MapzenManagerTests.swift @@ -45,7 +45,7 @@ class MapzenManagerTests: XCTestCase { MapzenManager.sharedManager.apiKey = nil //Tests - XCTAssertThrowsError(try MapzenRoutingController.controller()) { (error) -> Void in + XCTAssertThrowsError(try RoutingController.controller()) { (error) -> Void in let error = error as NSError XCTAssertTrue(error.code == MZError.apiKeyNotSet.rawValue) } @@ -57,7 +57,7 @@ class MapzenManagerTests: XCTestCase { //Tests do { - let _ = try MapzenRoutingController.controller() + let _ = try RoutingController.controller() } catch { XCTFail() } diff --git a/ios-sdkTests/MapzenRoutingControllerTests.swift b/ios-sdkTests/RoutingControllerTests.swift similarity index 90% rename from ios-sdkTests/MapzenRoutingControllerTests.swift rename to ios-sdkTests/RoutingControllerTests.swift index 51938e6..540f9c6 100644 --- a/ios-sdkTests/MapzenRoutingControllerTests.swift +++ b/ios-sdkTests/RoutingControllerTests.swift @@ -1,5 +1,5 @@ // -// MapzenRoutingControllerTests.swift +// RoutingControllerTests.swift // ios-sdk // // Created by Sarah Lensing on 3/13/17. @@ -10,14 +10,14 @@ import XCTest @testable import ios_sdk @testable import OnTheRoad -class MapzenRoutingControllerTests : XCTestCase { +class RoutingControllerTests : XCTestCase { let testSessionManager : TestUrlSession = TestUrlSession() - var router : MapzenRoutingController? = nil + var router : RoutingController? = nil override func setUp() { MapzenManager.sharedManager.apiKey = "testKey" - try? router = MapzenRoutingController.controller(sessionManager: testSessionManager) + try? router = RoutingController.controller(sessionManager: testSessionManager) } func testRouterSendCurrentLocaleLanguageByDefault() { diff --git a/ios-sdkTests/SearchConfigsTests.swift b/ios-sdkTests/SearchConfigsTests.swift new file mode 100644 index 0000000..c74da30 --- /dev/null +++ b/ios-sdkTests/SearchConfigsTests.swift @@ -0,0 +1,111 @@ +// +// SearchConfigsTests.swift +// ios-sdk +// +// Created by Sarah Lensing on 3/23/17. +// Copyright © 2017 Mapzen. All rights reserved. +// + +import XCTest +@testable import ios_sdk + +class AutocompleteConfigTests: XCTestCase { + + var config: AutocompleteConfig = AutocompleteConfig.init(searchText: "test", focusPoint: GeoPoint.init(latitude: 70.0, longitude: 40.0), completionHandler: { (response) in }) + + func testFocusPointIsCorrect() { + XCTAssertEqual(GeoPoint(latitude: 70.0, longitude: 40.0), config.focusPoint) + } + + func testSearchTestIsCorrect() { + XCTAssertEqual("test", config.searchText) + } + +} + +class PlaceConfigTests: XCTestCase { + + var config: PlaceConfig = PlaceConfig.init(places: [PlaceQueryItem.init(placeId: "123", dataSource: .openStreetMap, layer: .address)], completionHandler: { (response) in }) + + func testPlacesAreCorrect() { + XCTAssertEqual(config.places.count, 1) + XCTAssertEqual(PlaceQueryItem.init(placeId: "123", dataSource: .openStreetMap, layer: .address), config.places.first) + } +} + +class ReverseConfigTests: XCTestCase { + + var config: ReverseConfig = ReverseConfig.init(point: GeoPoint.init(latitude: 70.0, longitude: 40.0), completionHandler: { (response) in }) + + func testPointIsCorrect() { + XCTAssertEqual(GeoPoint(latitude: 70.0, longitude: 40.0), config.point) + } + + func testNumOfResults() { + config.numberOfResults = 8 + XCTAssertEqual(8, config.numberOfResults) + } + + func testBoundaryCountry() { + config.boundaryCountry = "US" + XCTAssertEqual("US", config.boundaryCountry) + } + + func testDataSources() { + config.dataSources = [.geoNames, .openAddresses] + XCTAssertEqual([.geoNames, .openAddresses], config.dataSources!) + } + + func testLayers() { + config.layers = [.address, .country] + XCTAssertEqual([.address, .country], config.layers!) + } +} + +class SearchConfigTests: XCTestCase { + + var config: SearchConfig = SearchConfig.init(searchText: "test", completionHandler: { (response) in }) + + func testSearchTextIsCorrect() { + XCTAssertEqual("test", config.searchText) + } + + func testNumOfResults() { + config.numberOfResults = 8 + XCTAssertEqual(8, config.numberOfResults) + } + + func testBoundaryCountry() { + config.boundaryCountry = "US" + XCTAssertEqual("US", config.boundaryCountry) + } + + func testBoundaryRect() { + let rect = SearchRect(minLatLong: GeoPoint(latitude: 70.0, longitude: 40.0), maxLatLong: GeoPoint(latitude: 75.0, longitude: 40.0)) + config.boundaryRect = rect + XCTAssertEqual(rect, config.boundaryRect) + } + + func testBoundaryCircle() { + let circle = SearchCircle(center: GeoPoint(latitude: 70.0, longitude: 40.0), radius: 10) + config.boundaryCircle = circle + XCTAssertEqual(circle, config.boundaryCircle) + } + + func testFocusPoint() { + let point = GeoPoint(latitude: 70.0, longitude: 40.0) + config.focusPoint = point + XCTAssertEqual(point, config.focusPoint) + } + + func testDataSources() { + config.dataSources = [.geoNames, .openAddresses] + XCTAssertEqual([.geoNames, .openAddresses], config.dataSources!) + } + + func testLayers() { + config.layers = [.address, .country] + XCTAssertEqual([.address, .country], config.layers!) + } +} + diff --git a/ios-sdkTests/SearchDataConverterTests.swift b/ios-sdkTests/SearchDataConverterTests.swift new file mode 100644 index 0000000..e11015b --- /dev/null +++ b/ios-sdkTests/SearchDataConverterTests.swift @@ -0,0 +1,154 @@ +// +// SearchDataConverterTests.swift +// ios-sdk +// +// Created by Sarah Lensing on 3/21/17. +// Copyright © 2017 Mapzen. All rights reserved. +// + +import XCTest +@testable import ios_sdk +import Pelias + +class SearchDataConverterTests: XCTestCase { + + func testUnwrapSearchSources() { + let sources = [SearchSource.geoNames, SearchSource.openAddresses, SearchSource.openStreetMap, SearchSource.quattroshapes] + let unwrapped = SearchDataConverter.unwrapSearchSources(sources) + XCTAssertTrue(unwrapped.contains(.GeoNames)) + XCTAssertTrue(unwrapped.contains(.OpenAddresses)) + XCTAssertTrue(unwrapped.contains(.OpenStreetMap)) + XCTAssertTrue(unwrapped.contains(.Quattroshapes)) + XCTAssertEqual(unwrapped.count, 4) + } + + func testUnwrapSearchSource() { + XCTAssertEqual(SearchDataConverter.unwrapSearchSource(.openStreetMap), .OpenStreetMap) + XCTAssertEqual(SearchDataConverter.unwrapSearchSource(.openAddresses), .OpenAddresses) + XCTAssertEqual(SearchDataConverter.unwrapSearchSource(.quattroshapes), .Quattroshapes) + XCTAssertEqual(SearchDataConverter.unwrapSearchSource(.geoNames), .GeoNames) + } + + func testWrapSearchSources() { + let sources = [Pelias.SearchSource.GeoNames, Pelias.SearchSource.OpenAddresses, Pelias.SearchSource.OpenStreetMap, Pelias.SearchSource.Quattroshapes] + let wrapped = SearchDataConverter.wrapSearchSources(sources) + XCTAssertTrue(wrapped.contains(.geoNames)) + XCTAssertTrue(wrapped.contains(.openAddresses)) + XCTAssertTrue(wrapped.contains(.openStreetMap)) + XCTAssertTrue(wrapped.contains(.quattroshapes)) + XCTAssertEqual(wrapped.count, 4) + + } + + func testWrapSearchSource() { + XCTAssertEqual(SearchDataConverter.wrapSearchSource(.OpenStreetMap), .openStreetMap) + XCTAssertEqual(SearchDataConverter.wrapSearchSource(.OpenAddresses), .openAddresses) + XCTAssertEqual(SearchDataConverter.wrapSearchSource(.Quattroshapes), .quattroshapes) + XCTAssertEqual(SearchDataConverter.wrapSearchSource(.GeoNames), .geoNames) + } + + func testUnwrapLayerFilters() { + let layers = [ios_sdk.LayerFilter.venue, LayerFilter.address, LayerFilter.country, LayerFilter.region, LayerFilter.locality, LayerFilter.localadmin, LayerFilter.neighbourhood, LayerFilter.coarse] + let unwrapped = SearchDataConverter.unwrapLayerFilters(layers) + XCTAssertTrue(unwrapped.contains(.venue)) + XCTAssertTrue(unwrapped.contains(.address)) + XCTAssertTrue(unwrapped.contains(.country)) + XCTAssertTrue(unwrapped.contains(.region)) + XCTAssertTrue(unwrapped.contains(.locality)) + XCTAssertTrue(unwrapped.contains(.localadmin)) + XCTAssertTrue(unwrapped.contains(.neighbourhood)) + XCTAssertTrue(unwrapped.contains(.coarse)) + XCTAssertEqual(unwrapped.count, 8) + } + + func testUnwrapLayerFilter() { + XCTAssertEqual(SearchDataConverter.unwrapLayerFilter(.venue), .venue) + XCTAssertEqual(SearchDataConverter.unwrapLayerFilter(.address), .address) + XCTAssertEqual(SearchDataConverter.unwrapLayerFilter(.country), .country) + XCTAssertEqual(SearchDataConverter.unwrapLayerFilter(.region), .region) + XCTAssertEqual(SearchDataConverter.unwrapLayerFilter(.locality), .locality) + XCTAssertEqual(SearchDataConverter.unwrapLayerFilter(.localadmin), .localadmin) + XCTAssertEqual(SearchDataConverter.unwrapLayerFilter(.neighbourhood), .neighbourhood) + XCTAssertEqual(SearchDataConverter.unwrapLayerFilter(.coarse), .coarse) + } + + func testWrapLayerFilters() { + let layers = [Pelias.LayerFilter.venue, LayerFilter.address, LayerFilter.country, LayerFilter.region, LayerFilter.locality, LayerFilter.localadmin, LayerFilter.neighbourhood, LayerFilter.coarse] + let wrapped = SearchDataConverter.wrapLayerFilters(layers) + XCTAssertTrue(wrapped.contains(.venue)) + XCTAssertTrue(wrapped.contains(.address)) + XCTAssertTrue(wrapped.contains(.country)) + XCTAssertTrue(wrapped.contains(.region)) + XCTAssertTrue(wrapped.contains(.locality)) + XCTAssertTrue(wrapped.contains(.localadmin)) + XCTAssertTrue(wrapped.contains(.neighbourhood)) + XCTAssertTrue(wrapped.contains(.coarse)) + XCTAssertEqual(wrapped.count, 8) + } + + func testWrapLayerFilter() { + XCTAssertEqual(SearchDataConverter.wrapLayerFilter(.venue), .venue) + XCTAssertEqual(SearchDataConverter.wrapLayerFilter(.address), .address) + XCTAssertEqual(SearchDataConverter.wrapLayerFilter(.country), .country) + XCTAssertEqual(SearchDataConverter.wrapLayerFilter(.region), .region) + XCTAssertEqual(SearchDataConverter.wrapLayerFilter(.locality), .locality) + XCTAssertEqual(SearchDataConverter.wrapLayerFilter(.localadmin), .localadmin) + XCTAssertEqual(SearchDataConverter.wrapLayerFilter(.neighbourhood), .neighbourhood) + XCTAssertEqual(SearchDataConverter.wrapLayerFilter(.coarse), .coarse) + } + + func testWrapPoint() { + let point = Pelias.GeoPoint(latitude: 70.0, longitude: 40.0) + let wrapped = SearchDataConverter.wrapPoint(point) + XCTAssertEqual(point, wrapped.point) + } + + func testUnwrapPoint() { + let point = ios_sdk.GeoPoint(latitude: 70.0, longitude: 40.0) + let unwrapped = SearchDataConverter.unwrapPoint(point) + XCTAssertEqual(point.point, unwrapped) + } + + func testUnwrapQueryItems() { + let items = [PlaceQueryItem.init(placeId: "id", dataSource: .geoNames, layer: .address), + PlaceQueryItem.init(placeId: "anotherid", dataSource: .quattroshapes, layer: .region)] + let unwrapped = SearchDataConverter.unwrapQueryItems(items) + XCTAssertEqual(unwrapped[0].placeId, "id") + XCTAssertEqual(unwrapped[0].dataSource, .GeoNames) + XCTAssertEqual(unwrapped[0].layer, .address) + XCTAssertEqual(unwrapped[1].placeId, "anotherid") + XCTAssertEqual(unwrapped[1].dataSource, .Quattroshapes) + XCTAssertEqual(unwrapped[1].layer, .region) + XCTAssertEqual(unwrapped.count, 2) + } + + func testUnwrapQueryItem() { + let item = PlaceQueryItem.init(placeId: "id", dataSource: .openStreetMap, layer: .venue) + let unwrapped = SearchDataConverter.unwrapQueryItem(item) + XCTAssertEqual(unwrapped.placeId, "id") + XCTAssertEqual(unwrapped.dataSource, .OpenStreetMap) + XCTAssertEqual(unwrapped.layer, .venue) + } + + func testWrapQueryItems() { + let items = [PeliasPlaceQueryItem.init(placeId: "id", dataSource: .GeoNames, layer: .address), + PeliasPlaceQueryItem.init(placeId: "anotherid", dataSource: .Quattroshapes, layer: .region)] + let wrapped = SearchDataConverter.wrapQueryItems(items) + XCTAssertEqual(wrapped[0].placeId, "id") + XCTAssertEqual(wrapped[0].dataSource, .geoNames) + XCTAssertEqual(wrapped[0].layer, .address) + XCTAssertEqual(wrapped[1].placeId, "anotherid") + XCTAssertEqual(wrapped[1].dataSource, .quattroshapes) + XCTAssertEqual(wrapped[1].layer, .region) + XCTAssertEqual(wrapped.count, 2) + } + + func testWrapQueryItem() { + let item = PeliasPlaceQueryItem.init(placeId: "id", dataSource: .OpenStreetMap, layer: .venue) + let wrapped = SearchDataConverter.wrapQueryItem(item) + XCTAssertEqual(wrapped.placeId, "id") + XCTAssertEqual(wrapped.dataSource, .openStreetMap) + XCTAssertEqual(wrapped.layer, .venue) + } + +} diff --git a/ios-sdkTests/SearchDataObjectsTests.swift b/ios-sdkTests/SearchDataObjectsTests.swift new file mode 100644 index 0000000..1cbc22c --- /dev/null +++ b/ios-sdkTests/SearchDataObjectsTests.swift @@ -0,0 +1,47 @@ +// +// MapzenSearchDataObjectsTests.swift +// ios-sdk +// +// Created by Sarah Lensing on 3/21/17. +// Copyright © 2017 Mapzen. All rights reserved. +// + +import XCTest +@testable import ios_sdk +import Pelias + +class MapzenSearchDataObjectsTests: XCTestCase { + + func testSearchRect() { + let min = ios_sdk.GeoPoint(latitude: 70.0, longitude: 40.0) + let max = ios_sdk.GeoPoint(latitude: 80.0, longitude: 50.0) + let searchRect = SearchRect(minLatLong: min, maxLatLong: max) + let rect = SearchBoundaryRect(minLatLong: SearchDataConverter.unwrapPoint(min), maxLatLong: SearchDataConverter.unwrapPoint(max)) + XCTAssertEqual(searchRect.rect, rect) + XCTAssertEqual(searchRect, SearchRect(minLatLong: min, maxLatLong: max)) + } + + func testSearchCircle() { + let center = ios_sdk.GeoPoint(latitude: 70.0, longitude: 40.0) + let searchCircle = SearchCircle(center: center, radius: 8) + let circle = SearchBoundaryCircle(center: SearchDataConverter.unwrapPoint(center), radius: 8) + XCTAssertEqual(searchCircle.circle, circle) + XCTAssertEqual(searchCircle, SearchCircle(center: center, radius: 8)) + } + + func testGeoPoint() { + let point = ios_sdk.GeoPoint(latitude: 70.0, longitude: 40.0) + let peliasPoint = Pelias.GeoPoint(latitude: 70.0, longitude: 40.0) + XCTAssertEqual(point.point, peliasPoint) + XCTAssertEqual(point, GeoPoint(latitude: 70.0, longitude: 40.0)) + } + + func testPlaceQueryItem() { + let item = PlaceQueryItem(placeId: "id", dataSource: .geoNames, layer: .address) + let peliasItem = PeliasPlaceQueryItem(placeId: "id", dataSource: .GeoNames, layer: .address) + XCTAssertEqual(item.peliasItem.placeId, peliasItem.placeId) + XCTAssertEqual(item.peliasItem.dataSource, peliasItem.dataSource) + XCTAssertEqual(item.peliasItem.layer, peliasItem.layer) + XCTAssertEqual(item, PlaceQueryItem(placeId: "id", dataSource: .geoNames, layer: .address)) + } +} diff --git a/ios-sdkTests/SearchResponseTests.swift b/ios-sdkTests/SearchResponseTests.swift new file mode 100644 index 0000000..f8b59d6 --- /dev/null +++ b/ios-sdkTests/SearchResponseTests.swift @@ -0,0 +1,43 @@ +// +// SearchResponseTests.swift +// ios-sdk +// +// Created by Sarah Lensing on 3/21/17. +// Copyright © 2017 Mapzen. All rights reserved. +// + +import XCTest +@testable import ios_sdk +import Pelias + +class SearchResponseTests: XCTestCase { + let data = Data() + let urlResponse = URLResponse() + let error = NSError(domain:"Test", code: 1, userInfo: nil) + var response: SearchResponse? + + override func setUp() { + response = SearchResponse(PeliasResponse(data: data, response: urlResponse, error: error)) + } + + func testData() { + XCTAssertEqual(response?.peliasResponse.data, data) + XCTAssertEqual(response?.data, data) + } + + func testResponse() { + XCTAssertEqual(response?.peliasResponse.response, urlResponse) + XCTAssertEqual(response?.response, urlResponse) + } + + func testError() { + let error = NSError(domain:"Test", code: 1, userInfo: nil) + XCTAssertEqual(response?.peliasResponse.error, error) + XCTAssertEqual(response?.error, error) + } + + func testEquals() { + let otherResponse = SearchResponse(PeliasResponse(data: Data(), response: urlResponse, error: NSError(domain:"Test", code: 1, userInfo: nil))) + XCTAssertEqual(response, otherResponse) + } +} diff --git a/src/LocationManager.swift b/src/LocationManager.swift index d8351b3..d3bb320 100644 --- a/src/LocationManager.swift +++ b/src/LocationManager.swift @@ -35,6 +35,7 @@ import OnTheRoad - Note: The class is expected to be used as a singleton. As such, access to the class is via the `sharedManager` object. */ +@objc(MZLocationManager) open class LocationManager: NSObject, CLLocationManagerDelegate { /// The singleton access object. diff --git a/src/MapViewController.swift b/src/MapViewController.swift index 73f1f5d..0400f45 100644 --- a/src/MapViewController.swift +++ b/src/MapViewController.swift @@ -193,6 +193,7 @@ public protocol MapTileLoadDelegate : class { MapViewController wraps the underlying `TGMapViewController` from Tangram-es and handles adding it to the view hierarchy. It exposes this in the `tgViewController` property and allows for additional customization there using the Tangram-es iOS framework. Documentation on that is available [here](https://mapzen.com/documentation/tangram/iOS-API/). */ +@objc(MZMapViewController) open class MapViewController: UIViewController, LocationManagerDelegate { //Error Domains for NSError Appeasement diff --git a/src/PeliasMapkitExtensions.swift b/src/PeliasMapkitExtensions.swift index 1f44bf1..8651344 100644 --- a/src/PeliasMapkitExtensions.swift +++ b/src/PeliasMapkitExtensions.swift @@ -111,9 +111,9 @@ public extension PeliasPlaceQueryItem { - Returns: An optional place query item */ - init?(annotation: PeliasMapkitAnnotation, layer: LayerFilter) { + init?(annotation: PeliasMapkitAnnotation, layer: Pelias.LayerFilter) { guard let place = annotation.data?[PeliasIDKey] as? String else { return nil } - guard let source = SearchSource(rawValue: annotation.data?[PeliasDataSourceKey] as? String ?? "") else { return nil } + guard let source = Pelias.SearchSource(rawValue: annotation.data?[PeliasDataSourceKey] as? String ?? "") else { return nil } self.init(placeId: place, dataSource: source, layer: layer) } } @@ -201,12 +201,12 @@ public extension SearchBoundaryRect { let maxCoordinate = MKCoordinateForMapPoint(mapPointMax) //We use the origin point latitude for max, and subsequently the computed maxLat for pelias's minimum, because pelias wants lower left and upper right points of the rect. - self.maxLatLong = GeoPoint(latitude: minCoordinate.latitude, longitude: maxCoordinate.longitude) - self.minLatLong = GeoPoint(latitude: maxCoordinate.latitude, longitude: minCoordinate.longitude) + self.maxLatLong = Pelias.GeoPoint(latitude: minCoordinate.latitude, longitude: maxCoordinate.longitude) + self.minLatLong = Pelias.GeoPoint(latitude: maxCoordinate.latitude, longitude: minCoordinate.longitude) } } -public extension GeoPoint { +public extension Pelias.GeoPoint { /** Creates a GeoPoint based of CoreLocation data diff --git a/src/MapzenRoutingController.swift b/src/RoutingController.swift similarity index 77% rename from src/MapzenRoutingController.swift rename to src/RoutingController.swift index 718f8b5..074c79d 100644 --- a/src/MapzenRoutingController.swift +++ b/src/RoutingController.swift @@ -1,5 +1,5 @@ // -// MapzenRoutingController.swift +// RoutingController.swift // ios-sdk // // Created by Matt Smollinger on 1/13/17. @@ -10,10 +10,11 @@ import UIKit import OnTheRoad /** - `MapzenRoutingController` is a subclass of On The Road's routing controller and is the main access point in the SDK for querying for routes. + `RoutingController` is a subclass of On The Road's routing controller and is the main access point in the SDK for querying for routes. - Note: The routing controller provides API key management and as such is expected to be retrieved via the `controller()` function so everything gets setup correctly. */ -open class MapzenRoutingController: OTRRoutingController { +@objc(MZRoutingController) +open class RoutingController: OTRRoutingController { private static let kApiKey = "api_key" private static let kLanguageKey = "language" @@ -29,21 +30,21 @@ open class MapzenRoutingController: OTRRoutingController { } /// Static function that vends a properly configured routing controller. - open static func controller() throws -> MapzenRoutingController { + open static func controller() throws -> RoutingController { let session = URLSession.init(configuration: URLSessionConfiguration.default) - return try MapzenRoutingController.controller(sessionManager: session) + return try RoutingController.controller(sessionManager: session) } /** Static function that vends a properly configured routing controller given a session manager. Useful for testing - parameter sessionManager : URLSession object to use for requests */ - static func controller(sessionManager : URLSession) throws -> MapzenRoutingController { + static func controller(sessionManager : URLSession) throws -> RoutingController { guard let apiKey = MapzenManager.sharedManager.apiKey else { throw NSError(domain: MapViewController.MapzenGeneralErrorDomain, code: MZError.apiKeyNotSet.rawValue, userInfo: nil) } - let controller = MapzenRoutingController.init(sessionManager: sessionManager) + let controller = RoutingController.init(sessionManager: sessionManager) controller.urlQueryComponents.add(URLQueryItem(name: kApiKey, value: apiKey)) return controller } @@ -62,12 +63,12 @@ open class MapzenRoutingController: OTRRoutingController { return super.requestRoute(withLocations: locations, costingModel: costing, costingOption: costingOptions, directionsOptions: directionsOptions, callback: callback) } guard var allDirectionsOptions = directionsOptions else { - let defaultDirectionsOptions = [MapzenRoutingController.kLanguageKey : localeLanguage as NSObject] + let defaultDirectionsOptions = [RoutingController.kLanguageKey : localeLanguage as NSObject] return super.requestRoute(withLocations: locations, costingModel: costing, costingOption: costingOptions, directionsOptions: defaultDirectionsOptions, callback: callback) } - if !allDirectionsOptions.keys.contains(MapzenRoutingController.kLanguageKey) { - allDirectionsOptions[MapzenRoutingController.kLanguageKey] = localeLanguage as NSObject + if !allDirectionsOptions.keys.contains(RoutingController.kLanguageKey) { + allDirectionsOptions[RoutingController.kLanguageKey] = localeLanguage as NSObject } return super.requestRoute(withLocations: locations, costingModel: costing, costingOption: costingOptions, directionsOptions: allDirectionsOptions, callback: callback) diff --git a/src/SearchConfigs.swift b/src/SearchConfigs.swift new file mode 100644 index 0000000..5bad19f --- /dev/null +++ b/src/SearchConfigs.swift @@ -0,0 +1,224 @@ +// +// SearchConfigs.swift +// ios-sdk +// +// Created by Sarah Lensing on 3/23/17. +// Copyright © 2017 Mapzen. All rights reserved. +// + +import Foundation +import Pelias + +@objc(MZAutocompleteConfig) +public class AutocompleteConfig : NSObject { + let peliasConfig : PeliasAutocompleteConfig + + public var focusPoint: GeoPoint { + get { + return SearchDataConverter.wrapPoint(peliasConfig.focusPoint) + } + } + + public var searchText: String { + get { + return peliasConfig.searchText + } + } + + public init(searchText: String, focusPoint: GeoPoint, completionHandler: @escaping (SearchResponse) -> Void) { + let unwrappedPoint = SearchDataConverter.unwrapPoint(focusPoint) + peliasConfig = PeliasAutocompleteConfig(searchText: searchText, focusPoint: unwrappedPoint, completionHandler: { (response) in + let mapzenResponse = SearchResponse.init(response) + completionHandler(mapzenResponse) + }) + } +} + +@objc(MZPlaceConfig) +public class PlaceConfig : NSObject { + let peliasConfig: PeliasPlaceConfig + + public var places: [PlaceQueryItem] { + get { + return SearchDataConverter.wrapQueryItems(peliasConfig.places) + } + } + + public init(places: [PlaceQueryItem], completionHandler: @escaping (SearchResponse) -> Void) { + let unwrappedPlaces = SearchDataConverter.unwrapQueryItems(places) + peliasConfig = PeliasPlaceConfig(places: unwrappedPlaces, completionHandler: { (response) in + let mapzenResponse = SearchResponse.init(response) + completionHandler(mapzenResponse) + }) + } +} + +@objc(MZReverseConfig) +public class ReverseConfig : NSObject { + + var peliasConfig: PeliasReverseConfig + + public var point: GeoPoint { + get { + return SearchDataConverter.wrapPoint(peliasConfig.point) + } + } + + public var numberOfResults: Int? { + get { + return peliasConfig.numberOfResults + } + set { + peliasConfig.numberOfResults = newValue + } + } + + public var boundaryCountry: String? { + get { + return peliasConfig.boundaryCountry + } + set { + peliasConfig.boundaryCountry = newValue + } + } + + public var dataSources: [SearchSource]? { + get { + guard let sources = peliasConfig.dataSources else { return nil } + return SearchDataConverter.wrapSearchSources(sources) + } + set { + guard let sources = newValue else { + peliasConfig.dataSources = nil + return + } + peliasConfig.dataSources = SearchDataConverter.unwrapSearchSources(sources) + } + } + + public var layers: [LayerFilter]? { + get { + guard let layers = peliasConfig.layers else { return nil } + return SearchDataConverter.wrapLayerFilters(layers) + } + set { + guard let layers = newValue else { + peliasConfig.layers = nil + return + } + peliasConfig.layers = SearchDataConverter.unwrapLayerFilters(layers) + } + } + + public init(point: GeoPoint, completionHandler: @escaping (SearchResponse) -> Void) { + let unwrappedPoint = SearchDataConverter.unwrapPoint(point) + peliasConfig = PeliasReverseConfig(point: unwrappedPoint, completionHandler: { (peliasResponse) -> Void in + let mapzenResponse = SearchResponse.init(peliasResponse) + completionHandler(mapzenResponse) + }) + } +} + +@objc(MZSearchConfig) +open class SearchConfig: NSObject { + var peliasConfig: PeliasSearchConfig + + public var searchText: String { + get { + return peliasConfig.searchText; + } + set(text) { + peliasConfig.searchText = text + } + } + + public var numberOfResults: Int? { + get { + return peliasConfig.numberOfResults + } + set(num) { + peliasConfig.numberOfResults = num + } + } + + public var boundaryCountry: String? { + get { + return peliasConfig.boundaryCountry + } + set(text) { + peliasConfig.boundaryCountry = text + } + } + + public var boundaryRect: SearchRect? { + get { + if let rect = peliasConfig.boundaryRect{ + return SearchRect(boundaryRect: rect) + } + return nil + } + set (rectWrapper) { + peliasConfig.boundaryRect = rectWrapper?.rect + } + } + + public var boundaryCircle: SearchCircle? { + get { + if let circle = peliasConfig.boundaryCircle { + return SearchCircle(boundaryCircle: circle) + } + return nil + } + set(circleWrapper) { + peliasConfig.boundaryCircle = circleWrapper?.circle + } + } + + public var focusPoint: GeoPoint? { + get { + if let point = peliasConfig.focusPoint { + return GeoPoint(geoPoint: point) + } + return nil + } + set(pointWrapper) { + peliasConfig.focusPoint = pointWrapper?.point + } + } + + public var dataSources: [SearchSource]? { + get { + if let sources = peliasConfig.dataSources { + return SearchDataConverter.wrapSearchSources(sources) + } + return nil + } + set { + if let sources = newValue { + peliasConfig.dataSources = SearchDataConverter.unwrapSearchSources(sources) + } + } + } + + public var layers: [LayerFilter]? { + get { + if let layerArray = peliasConfig.layers { + return SearchDataConverter.wrapLayerFilters(layerArray) + } + return nil + } + set { + if let layerArray = newValue { + peliasConfig.layers = SearchDataConverter.unwrapLayerFilters(layerArray) + } + } + } + + public init(searchText: String, completionHandler: @escaping (SearchResponse) -> Void) { + peliasConfig = PeliasSearchConfig(searchText: searchText, completionHandler: { (peliasResponse) -> Void in + let mapzenResponse = SearchResponse.init(peliasResponse) + completionHandler(mapzenResponse) + }) + } +} + diff --git a/src/SearchDataConverter.swift b/src/SearchDataConverter.swift new file mode 100644 index 0000000..ff9141c --- /dev/null +++ b/src/SearchDataConverter.swift @@ -0,0 +1,153 @@ +// +// SearchDataConverter.swift +// ios-sdk +// +// Created by Sarah Lensing on 3/20/17. +// +// + +import Foundation +import Pelias + +class SearchDataConverter { + + static func unwrapSearchSources(_ sources: [SearchSource]) -> [Pelias.SearchSource] { + var newSources: [Pelias.SearchSource] = [] + for wrapper in sources { + newSources.append(unwrapSearchSource(wrapper)) + } + return newSources + } + + static func unwrapSearchSource(_ source: SearchSource) -> Pelias.SearchSource { + switch source { + case .openStreetMap: + return Pelias.SearchSource.OpenStreetMap + case .openAddresses: + return Pelias.SearchSource.OpenAddresses + case .quattroshapes: + return Pelias.SearchSource.Quattroshapes + case.geoNames: + return Pelias.SearchSource.GeoNames + } + } + + static func wrapSearchSources(_ sources: [Pelias.SearchSource]) -> [SearchSource] { + var newSources: [SearchSource] = [] + for wrapper in sources { + newSources.append(wrapSearchSource(wrapper)) + } + return newSources + } + + static func wrapSearchSource(_ source: Pelias.SearchSource) -> SearchSource { + switch source { + case Pelias.SearchSource.OpenStreetMap: + return SearchSource.openStreetMap + case Pelias.SearchSource.OpenAddresses: + return SearchSource.openAddresses + case Pelias.SearchSource.Quattroshapes: + return SearchSource.quattroshapes + case Pelias.SearchSource.GeoNames: + return SearchSource.geoNames + } + } + + static func unwrapLayerFilters(_ layers: [LayerFilter]) -> [Pelias.LayerFilter] { + var newLayers: [Pelias.LayerFilter] = [] + for wrapper in layers { + newLayers.append(unwrapLayerFilter(wrapper)) + } + return newLayers + } + + static func unwrapLayerFilter(_ layer: LayerFilter) -> Pelias.LayerFilter { + switch layer { + case .address: + return Pelias.LayerFilter.address + case .coarse: + return Pelias.LayerFilter.coarse + case .country: + return Pelias.LayerFilter.country + case .county: + return Pelias.LayerFilter.county + case .localadmin: + return Pelias.LayerFilter.localadmin + case .locality: + return Pelias.LayerFilter.locality + case .neighbourhood: + return Pelias.LayerFilter.neighbourhood + case .region: + return Pelias.LayerFilter.region + case .venue: + return Pelias.LayerFilter.venue + } + } + + static func wrapLayerFilters(_ layers: [Pelias.LayerFilter]) -> [LayerFilter] { + var newLayers: [LayerFilter] = [] + for wrapper in layers { + newLayers.append(wrapLayerFilter(wrapper)) + } + return newLayers + } + + static func wrapLayerFilter(_ layer: Pelias.LayerFilter) -> LayerFilter { + switch layer { + case .address: + return LayerFilter.address + case .coarse: + return LayerFilter.coarse + case .country: + return LayerFilter.country + case .county: + return LayerFilter.county + case .localadmin: + return LayerFilter.localadmin + case .locality: + return LayerFilter.locality + case .neighbourhood: + return LayerFilter.neighbourhood + case .region: + return LayerFilter.region + case .venue: + return LayerFilter.venue + } + } + + static func wrapPoint(_ point: Pelias.GeoPoint) -> GeoPoint { + return GeoPoint(geoPoint: point) + } + + static func unwrapPoint(_ point: GeoPoint) -> Pelias.GeoPoint { + return point.point + } + + static func unwrapQueryItems(_ items: [PlaceQueryItem]) -> [PeliasPlaceQueryItem] { + var newItems: [PeliasPlaceQueryItem] = [] + for wrapper in items { + newItems.append(unwrapQueryItem(wrapper)) + } + return newItems + } + + static func unwrapQueryItem(_ item: PlaceQueryItem) -> PeliasPlaceQueryItem { + let unwrappedSource = unwrapSearchSource(item.dataSource) + let unwrappedLayer = unwrapLayerFilter(item.layer) + return PeliasPlaceQueryItem(placeId: item.placeId, dataSource: unwrappedSource, layer: unwrappedLayer) + } + + static func wrapQueryItems(_ items: [PlaceAPIQueryItem]) -> [PlaceQueryItem] { + var newItems: [PlaceQueryItem] = [] + for wrapper in items { + newItems.append(wrapQueryItem(wrapper)) + } + return newItems + } + + static func wrapQueryItem(_ item: PlaceAPIQueryItem) -> PlaceQueryItem { + let wrappedSource = wrapSearchSource(item.dataSource) + let wrappedLayer = wrapLayerFilter(item.layer) + return PlaceQueryItem(placeId: item.placeId, dataSource: wrappedSource, layer: wrappedLayer) + } +} diff --git a/src/SearchDataObjects.swift b/src/SearchDataObjects.swift new file mode 100644 index 0000000..ab3ffb3 --- /dev/null +++ b/src/SearchDataObjects.swift @@ -0,0 +1,109 @@ +// +// SearchDataObjects.swift +// ios-sdk +// +// Created by Sarah Lensing on 3/20/17. +// +// + +import Foundation +import Pelias + +@objc(MZSearchRect) +public class SearchRect: NSObject { + let rect: SearchBoundaryRect + public init(minLatLong: GeoPoint, maxLatLong: GeoPoint) { + rect = SearchBoundaryRect(minLatLong: minLatLong.point, maxLatLong: maxLatLong.point) + } + + init(boundaryRect: SearchBoundaryRect) { + rect = boundaryRect + } + + public override func isEqual(_ object: Any?) -> Bool { + guard let otherRect = object as? SearchRect else { return false } + return otherRect.rect == rect + } +} + +@objc(MZSearchCircle) +public class SearchCircle: NSObject { + let circle: SearchBoundaryCircle + public init(center: GeoPoint, radius: Double) { + circle = SearchBoundaryCircle(center: center.point, radius: radius) + } + + init(boundaryCircle: SearchBoundaryCircle) { + circle = boundaryCircle + } + + public override func isEqual(_ object: Any?) -> Bool { + guard let otherCircle = object as? SearchCircle else { return false } + return otherCircle.circle == circle + } +} + +@objc(MZGeoPoint) +public class GeoPoint: NSObject { + let point: Pelias.GeoPoint + + public init(latitude: Double, longitude: Double) { + point = Pelias.GeoPoint(latitude: latitude, longitude: longitude) + } + + init(geoPoint: Pelias.GeoPoint) { + point = geoPoint + } + + public override func isEqual(_ object: Any?) -> Bool { + guard let otherPoint = object as? GeoPoint else { return false } + return otherPoint.point == point + } +} + +@objc(MZSearchSource) +public enum SearchSource: Int { + case openStreetMap = 1, openAddresses, quattroshapes, geoNames +} + +@objc(MZLayerFilter) +public enum LayerFilter: Int { + case venue = 1, address, country, region, county, locality, localadmin, neighbourhood, coarse +} + +@objc(MZPlaceQueryItem) +public class PlaceQueryItem: NSObject { + + let peliasItem: PeliasPlaceQueryItem + + public var placeId: String { + get { + return peliasItem.placeId + } + } + + public var dataSource: SearchSource { + get { + return SearchDataConverter.wrapSearchSource(peliasItem.dataSource) + } + } + + public var layer: LayerFilter { + get { + return SearchDataConverter.wrapLayerFilter(peliasItem.layer) + } + } + + public init(placeId: String, dataSource: SearchSource, layer: LayerFilter) { + let unwrappedSource = SearchDataConverter.unwrapSearchSource(dataSource) + let unwrappedLayer = SearchDataConverter.unwrapLayerFilter(layer) + peliasItem = PeliasPlaceQueryItem(placeId: placeId, dataSource: unwrappedSource, layer: unwrappedLayer) + } + + public override func isEqual(_ object: Any?) -> Bool { + guard let otherItem = object as? PlaceQueryItem else { return false } + return otherItem.peliasItem.dataSource == peliasItem.dataSource && + otherItem.peliasItem.layer == peliasItem.layer && + otherItem.placeId == peliasItem.placeId + } +} diff --git a/src/SearchResponse.swift b/src/SearchResponse.swift new file mode 100644 index 0000000..50fb921 --- /dev/null +++ b/src/SearchResponse.swift @@ -0,0 +1,53 @@ +// +// SearchResponse.swift +// ios-sdk +// +// Created by Sarah Lensing on 3/21/17. +// Copyright © 2017 Mapzen. All rights reserved. +// + +import Foundation +import Pelias + +@objc(MZSearchResponse) +public class SearchResponse : NSObject { + let peliasResponse: PeliasResponse + + //TODO + // private lazy var internalParsedError: MapzenSearchError? + + public var data: Data? { + get { + return peliasResponse.data + } + } + + public var response: URLResponse? { + get { + return peliasResponse.response + } + } + + public var error: NSError? { + get { + return peliasResponse.error + } + } + + //TODO: create wrapper + // public var parsedResponse: PeliasSearchResponse? { + + //TODO: + // public var parsedError: MapzenSearchError? { + + init(_ response: PeliasResponse) { + peliasResponse = response + } + + public override func isEqual(_ object: Any?) -> Bool { + guard let response = object as? SearchResponse else { return false } + return response.peliasResponse.data == peliasResponse.data && + response.peliasResponse.response == peliasResponse.response && + response.peliasResponse.error == peliasResponse.error + } +}