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

feat: Upgrading to latest version of MapLibre iOS #31

Merged
merged 5 commits into from
Aug 14, 2024
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
4 changes: 2 additions & 2 deletions .github/workflows/build_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ jobs:
xcodebuild_and_test:
runs-on: macos-latest
steps:
- uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 #v4.1.1
with:
persist-credentials: false

- name: Build and test
run: xcodebuild test -scheme "AmplifyMapLibreAdapter-Package" -destination "platform=iOS Simulator,name=iPhone 11 Pro" | xcpretty --simple --color --report junit && exit ${PIPESTATUS[0]}
run: xcodebuild test -scheme "AmplifyMapLibreAdapter-Package" -destination "platform=iOS Simulator,name=iPhone 15 Pro" | xcpretty --simple --color --report junit && exit ${PIPESTATUS[0]}
2 changes: 1 addition & 1 deletion HostApp/HostApp/CompositeParentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import SwiftUI
import CoreLocation
import AmplifyMapLibreAdapter
import AmplifyMapLibreUI
import Mapbox
import MapLibre
import Amplify

// swiftlint:disable:next type_name
Expand Down
2 changes: 1 addition & 1 deletion HostApp/HostApp/Views/AMLMapCompositeView_View.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import SwiftUI
import CoreLocation
import AmplifyMapLibreAdapter
import AmplifyMapLibreUI
import Mapbox
import MapLibre
import Amplify

// swiftlint:disable:next type_name
Expand Down
6 changes: 3 additions & 3 deletions HostApp/HostApp/Views/AMLMapView_View.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import SwiftUI
import AmplifyMapLibreAdapter
import AmplifyMapLibreUI
import CoreLocation
import Mapbox
import MapLibre
import Amplify
import Combine

Expand Down Expand Up @@ -97,8 +97,8 @@ struct AMLMapView_View_Previews: PreviewProvider {
}

extension AMLMapView_View {
private func didSelectFeature(_ mapView: MGLMapView, _ pointFeature: MGLPointFeature) {
let camera = MGLMapCamera(
private func didSelectFeature(_ mapView: MLNMapView, _ pointFeature: MLNPointFeature) {
let camera = MLNMapCamera(
lookingAtCenter: pointFeature.coordinate,
altitude: mapView.camera.altitude,
pitch: mapView.camera.pitch,
Expand Down
2 changes: 1 addition & 1 deletion HostApp/HostApp/Views/AMLMapView_ViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//

import SwiftUI
import Mapbox
import MapLibre
import Amplify
import AmplifyMapLibreAdapter
import AmplifyMapLibreUI
Expand Down
2 changes: 1 addition & 1 deletion HostApp/HostApp/Views/SimpleAMLMapView_View.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import SwiftUI
import AmplifyMapLibreAdapter
import AmplifyMapLibreUI
import CoreLocation
import Mapbox
import MapLibre
import Amplify
import Combine

Expand Down
72 changes: 18 additions & 54 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,107 +6,71 @@
"repositoryURL": "https://github.com/aws-amplify/amplify-swift.git",
"state": {
"branch": null,
"revision": "5268948fdd0323bb5ef2a487c36d4b64b2a31c83",
"version": "2.12.0"
"revision": "99c72db23217c8944dda92a9be26f7c0d0d5de3f",
"version": "2.37.0"
}
},
{
"package": "AmplifyUtilsNotifications",
"repositoryURL": "https://github.com/aws-amplify/amplify-swift-utils-notifications.git",
"state": {
"branch": null,
"revision": "f970384ad1035732f99259255cd2f97564807e41",
"version": "1.1.0"
}
},
{
"package": "AppSyncRealTimeClient",
"repositoryURL": "https://github.com/aws-amplify/aws-appsync-realtime-client-ios.git",
"state": {
"branch": null,
"revision": "b036e83716789c13a3480eeb292b70caa54114f2",
"version": "3.1.0"
"revision": "959eec669ba97c7d923b963c3e66ca8a0b2737f6",
"version": "1.1.1"
}
},
{
"package": "aws-crt-swift",
"repositoryURL": "https://github.com/awslabs/aws-crt-swift",
"state": {
"branch": null,
"revision": "6feec6c3787877807aa9a00fad09591b96752376",
"version": "0.6.1"
"revision": "0d0a0cf2e2cb780ceeceac190b4ede94f4f96902",
"version": "0.26.0"
}
},
{
"package": "aws-sdk-swift",
"repositoryURL": "https://github.com/awslabs/aws-sdk-swift.git",
"state": {
"branch": null,
"revision": "24bae88a2391fe75da8a940a544d1ef6441f5321",
"version": "0.13.0"
"revision": "47922c05dd66be717c7bce424651a534456717b7",
"version": "0.36.2"
}
},
{
"package": "MapLibre GL Native",
"package": "MapLibre Native",
"repositoryURL": "https://github.com/maplibre/maplibre-gl-native-distribution",
"state": {
"branch": null,
"revision": "d524c18d8c572db72c753f88492c36b9749725e1",
"version": "5.12.0"
"revision": "6579f48fe126ce2916f7b5d0c84c1869d790c4e4",
"version": "6.4.1"
}
},
{
"package": "smithy-swift",
"repositoryURL": "https://github.com/awslabs/smithy-swift",
"repositoryURL": "https://github.com/smithy-lang/smithy-swift",
"state": {
"branch": null,
"revision": "7b28da158d92cd06a3549140d43b8fbcf64a94a6",
"version": "0.15.0"
"revision": "8a5b0105c1b8a1d26a9435fb0af3959a7f5de578",
"version": "0.41.1"
}
},
{
"package": "SQLite.swift",
"repositoryURL": "https://github.com/stephencelis/SQLite.swift.git",
"state": {
"branch": null,
"revision": "5f5ad81ac0d0a0f3e56e39e646e8423c617df523",
"version": "0.13.2"
}
},
{
"package": "Starscream",
"repositoryURL": "https://github.com/daltoniam/Starscream",
"state": {
"branch": null,
"revision": "df8d82047f6654d8e4b655d1b1525c64e1059d21",
"version": "4.0.4"
}
},
{
"package": "swift-collections",
"repositoryURL": "https://github.com/apple/swift-collections",
"state": {
"branch": null,
"revision": "937e904258d22af6e447a0b72c0bc67583ef64a2",
"version": "1.0.4"
"revision": "a95fc6df17d108bd99210db5e8a9bac90fe984b8",
"version": "0.15.3"
}
},
{
"package": "swift-log",
"repositoryURL": "https://github.com/apple/swift-log.git",
"state": {
"branch": null,
"revision": "32e8d724467f8fe623624570367e3d50c5638e46",
"version": "1.5.2"
}
},
{
"package": "XMLCoder",
"repositoryURL": "https://github.com/MaxDesiatov/XMLCoder.git",
"state": {
"branch": null,
"revision": "b1e944cbd0ef33787b13f639a5418d55b3bed501",
"version": "0.17.1"
"revision": "9cb486020ebf03bfa5b5df985387a14a98744537",
"version": "1.6.1"
}
}
]
Expand Down
6 changes: 3 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ let package = Package(

// MapLibre
.package(
name: "MapLibre GL Native",
name: "MapLibre Native",
url: "https://github.com/maplibre/maplibre-gl-native-distribution",
.exact("5.12.0")
.exact("6.4.1")
)
],
targets: [
Expand All @@ -40,7 +40,7 @@ let package = Package(
.product(name: "Amplify", package: "Amplify"),
.product(name: "AWSCognitoAuthPlugin", package: "Amplify"),
.product(name: "AWSLocationGeoPlugin", package: "Amplify"),
.product(name: "Mapbox", package: "MapLibre GL Native")
.product(name: "MapLibre", package: "MapLibre Native")
]
),
.target(
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The AmplifyMapLibreAdapter is a library that combines the Amplify Geo category a

- Brokers communication between Amplify and MapLibre by providing functions and extensions that simplify using Amplify Geo with MapLibre.

- Provide SwiftUI support for MapLibre that adds `AMLMapView` (Amplify MapLibre MapView) and `AMLMapCompositeView` Views around MapLibre's MGLMapView. This introduces SwiftUI support to the MapLibre SDK for iOS. It provides a subset of MGLMapView functionality that can be used for displaying and interacting with a map; providing APIs to track state changes, inject custom implementations for user interaction, and define settings.
- Provide SwiftUI support for MapLibre that adds `AMLMapView` (Amplify MapLibre MapView) and `AMLMapCompositeView` Views around MapLibre's MLNMapView. This introduces SwiftUI support to the MapLibre SDK for iOS. It provides a subset of MLNMapView functionality that can be used for displaying and interacting with a map; providing APIs to track state changes, inject custom implementations for user interaction, and define settings.

## Usage

Expand All @@ -33,7 +33,7 @@ Swift Pacakge Manager is distributed with Xcode. To add AmplifyMapLibreAdapter t
6. Enter the AmplifyMapLibreAdapter GitHub repo URL (`https://github.com/aws-amplify/amplify-ios-maplibre`) in the search bar labeled **Search or Enter Package URL**.
7. Click **Add Package** and select your desired **Dependency Rule**
8. Select the targets you would like to add.
- **AmplifyMapLibreAdapter** will allow you to create a `MGLMapView` configured to work with Amplify Geo.
- **AmplifyMapLibreAdapter** will allow you to create a `MLNMapView` configured to work with Amplify Geo.
- **AmplifyMapLibreUI** provides SwiftUI Map Views, `AMLMapView` and `AMLMapCompositeView`. Additionally, it also provides other map related UI components with applicable functionality, such as a `AMLSearchBar`, `AMLPlaceList`, `AMLMapControlView`, and more. All of which seamlessly integrate with Amplify Geo.

## Reporting Bugs/Feature Requests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,23 @@ import Foundation
import Amplify
import AWSLocationGeoPlugin
import AWSClientRuntime
import InternalAmplifyCredentials

extension AWSMapURLProtocol {
struct GeoConfig {
let regionName: String
let credentialsProvider: CredentialsProvider
let credentialsProvider: CredentialsProviding
let hostName: String

init?() {
guard let plugin = try? Amplify.Geo.getPlugin(for: "awsLocationGeoPlugin") as? AWSLocationGeoPlugin else {
assertionFailure(AWSMapURLProtocolError.configurationError.localizedDescription)
return nil
}
self.credentialsProvider = plugin.authService.getCredentialsProvider()
guard let credentiaslProvider = plugin.authService as? AWSAuthCredentialsProviderBehavior else {
return nil
}
self.credentialsProvider = credentiaslProvider.getCredentialsProvider()
self.regionName = plugin.pluginConfig.regionName
self.hostName = "maps.geo.\(regionName).amazonaws.com"
}
Expand Down
7 changes: 4 additions & 3 deletions Sources/AmplifyMapLibreAdapter/AWSMapURLProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ class AWSMapURLProtocol: URLProtocol {

let requestBuilder = SdkHttpRequestBuilder()
.withHost(host)
.withPath(originalURLComponents.path)
.withPath(originalURLComponents.path.urlPercentEncoding(encodeForwardSlash: false))
.withMethod(.get)
.withPort(443)
.withProtocol(.https)
.withHeader(name: "host", value: host)

Task {
var signedRequest = request
signedRequest.url = originalURLComponents.url
Expand All @@ -105,7 +105,8 @@ class AWSMapURLProtocol: URLProtocol {
signingRegion: geoConfig.regionName,
date: Date(),
expiration: 60,
signingAlgorithm: .sigv4) else {
signingAlgorithm: .sigv4)
else {
completionHandler(.failure(AWSMapURLProtocolError.signatureError))
return
}
Expand Down
28 changes: 14 additions & 14 deletions Sources/AmplifyMapLibreAdapter/AmplifyMapLibre.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,34 @@

import Foundation
import CoreLocation
import Mapbox
import MapLibre
import Amplify
import AWSLocationGeoPlugin

public class AmplifyMapLibre {

/// Creates an instance of MGLMapView configured to work with Amplify and Amazon
/// Creates an instance of MLNMapView configured to work with Amplify and Amazon
/// Location Service using the default map
@MainActor public class func createMap() async throws -> MGLMapView {
AWSMapURLProtocol.register(sessionConfig: MGLNetworkConfiguration.sharedManager.sessionConfiguration)
@MainActor public class func createMap() async throws -> MLNMapView {
AWSMapURLProtocol.register(sessionConfig: MLNNetworkConfiguration.sharedManager.sessionConfiguration)
let map = try await Amplify.Geo.defaultMap()
return MGLMapView(frame: .zero, styleURL: map.styleURL)
return MLNMapView(frame: .zero, styleURL: map.styleURL)
}

/// Creates an instance of MGLMapView configured to work with Amplify and Amazon
/// Creates an instance of MLNMapView configured to work with Amplify and Amazon
/// Location Service using the specified MapStyle.
/// - Parameter mapStyle: The MapStyle for the map. (optional, default: The MapStyle
/// that corresponds to the default map in amplifyconfiguration.json)
/// - Returns: An instance of MGLMapView.
public class func createMap(_ mapStyle: Geo.MapStyle) -> MGLMapView {
AWSMapURLProtocol.register(sessionConfig: MGLNetworkConfiguration.sharedManager.sessionConfiguration)
return MGLMapView(frame: .zero, styleURL: mapStyle.styleURL)
/// - Returns: An instance of MLNMapView.
public class func createMap(_ mapStyle: Geo.MapStyle) -> MLNMapView {
AWSMapURLProtocol.register(sessionConfig: MLNNetworkConfiguration.sharedManager.sessionConfiguration)
return MLNMapView(frame: .zero, styleURL: mapStyle.styleURL)
}

/// Convert a Place array to an MGLPointFeature array that is ready to be displayed on a map.
/// Convert a Place array to an MLNPointFeature array that is ready to be displayed on a map.
/// - Parameter places: Place array to convert.
/// - Returns: MGLPointFeature array.
public class func createFeatures(_ places: [Geo.Place]) -> [MGLPointFeature] {
places.map(MGLPointFeature.init)
/// - Returns: MLNPointFeature array.
public class func createFeatures(_ places: [Geo.Place]) -> [MLNPointFeature] {
places.map(MLNPointFeature.init)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

import Foundation
import Amplify
import Mapbox
import MapLibre

public extension Geo.BoundingBox {
/// Initialize a BoundingBox from a MGLCoordinateBounds
/// Initialize a BoundingBox from a MLNCoordinateBounds
/// - Parameter bounds: The CLLocationCoordinate2D to use to initialize the
/// Location.
init(_ bounds: MGLCoordinateBounds) {
init(_ bounds: MLNCoordinateBounds) {
let southwest = Geo.Coordinates(bounds.sw)
let northeast = Geo.Coordinates(bounds.ne)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

import Foundation
import Amplify
import Mapbox
import MapLibre

public extension Geo.SearchArea {
/// Creates a SearchArea that only returns places within the provided
/// MGLCoordinateBounds.
/// MLNCoordinateBounds.
/// - Parameter bounds: The bounds for the search area.
/// - Returns: The SearchArea.
static func within(_ bounds: MGLCoordinateBounds) -> Geo.SearchArea {
static func within(_ bounds: MLNCoordinateBounds) -> Geo.SearchArea {
.within(Geo.BoundingBox(bounds))
}
}
Loading
Loading