Skip to content

Commit

Permalink
feat: Upgrading to MapLibre 6.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ruisebas committed May 14, 2024
1 parent 87a4cdf commit b17775f
Show file tree
Hide file tree
Showing 30 changed files with 233 additions and 230 deletions.
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
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
2 changes: 1 addition & 1 deletion Sources/AmplifyMapLibreAdapter/AWSMapURLProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class AWSMapURLProtocol: URLProtocol {

let requestBuilder = SdkHttpRequestBuilder()
.withHost(host)
.withPath(originalURLComponents.path)
.withPath(originalURLComponents.path.urlPercentEncoding(encodeForwardSlash: false))
.withMethod(.get)
.withPort(443)
.withProtocol(.https)
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))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
//

import Foundation
import Mapbox
import MapLibre
import Amplify

public extension MGLPointFeature {
/// Initialize an MGLPointFeature with the title and coordinates of a given Geo.Place
/// - Parameter place: The Geo.Place from which to initialize the MGLPointFeature.
public extension MLNPointFeature {
/// Initialize an MLNPointFeature with the title and coordinates of a given Geo.Place
/// - Parameter place: The Geo.Place from which to initialize the MLNPointFeature.
convenience init(_ place: Geo.Place) {
self.init()
title = place.label
Expand All @@ -24,8 +24,8 @@ public extension MGLPointFeature {
}
}

// MARK: MGLPointFeature+Geo.Place property
public extension MGLPointFeature {
// MARK: MLNPointFeature+Geo.Place property
public extension MLNPointFeature {
var amlGeoPlace: Geo.Place? {
get {
guard let coordinates = attributes[\.coordinates],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
//

import Foundation
import Mapbox
import MapLibre

public extension MGLPointFeature {
/// Initialize an MGLPointFeature with a given title and coordinates
public extension MLNPointFeature {
/// Initialize an MLNPointFeature with a given title and coordinates
/// - Parameters:
/// - title: The feature title.
/// - coordinates: The feature coordinates.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import SwiftUI
import CoreLocation
import Mapbox
import MapLibre
import Amplify
import AmplifyMapLibreAdapter

Expand Down
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

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

import Foundation
import CoreLocation
import Mapbox
import MapLibre
import SwiftUI

public extension AMLMapCompositeView {
Expand Down Expand Up @@ -84,7 +84,7 @@ public extension AMLMapCompositeView {

/// Provide an SwiftUI view that represents a point on a map.
///
/// - Important: Because the underlying `MGLMapView` consumes `UIImage`s,
/// - Important: Because the underlying `MLNMapView` consumes `UIImage`s,
/// this method turns a `SwiftUI` view into a `UIImage`.
/// There may be hidden cost to using this. If you experience performance and / or
/// rendering issues, please use the `featureImage(_:)` view modifier instead.
Expand All @@ -108,13 +108,13 @@ public extension AMLMapCompositeView {
/// The default implementation pans the feature to the center of the screen and presents an `AMLCalloutView`.
/// Defining an implementation here will override this behavior.
///
/// - Parameter implementation: Closure provided a `MGLMapView` and `MGLPointFeature`.
/// - Parameter implementation: Closure provided a `MLNMapView` and `MLNPointFeature`.
/// Define your desired behavior on the `mapView` using information from the `pointFeature` as needed.
/// - Returns: An instance of `AMLMapCompositeView`.
func featureTapped(
_ implementation: @escaping (
_ mapView: MGLMapView,
_ pointFeature: MGLPointFeature
_ mapView: MLNMapView,
_ pointFeature: MLNPointFeature
) -> Void
) -> AMLMapCompositeView {
viewModel.mapSettings.proxyDelegate.featureTapped = implementation
Expand All @@ -126,30 +126,30 @@ public extension AMLMapCompositeView {
/// The default implementation zooms in on the map.
/// Defining an implementation here will override this behavior.
///
/// - Parameter implementation: Closure provided a `MGLMapView` and `MGLPointFeatureCluster`.
/// - Parameter implementation: Closure provided a `MLNMapView` and `MLNPointFeatureCluster`.
/// Define your desired behavior on the `mapView` using information from the `pointFeatureCluster` as needed.
/// - Returns: An instance of `AMLMapCompositeView`.
func featureClusterTapped(
_ implementation: @escaping (
_ mapView: MGLMapView,
_ pointFeatureCluster: MGLPointFeatureCluster
_ mapView: MLNMapView,
_ pointFeatureCluster: MLNPointFeatureCluster
) -> Void
) -> AMLMapCompositeView {
viewModel.mapSettings.proxyDelegate.clusterTapped = implementation
return self
}

/// Set the position of the compass on the `MGLMapView`.
/// - Parameter position: `MGLOrnamentPosition` defining the location.
/// Set the position of the compass on the `MLNMapView`.
/// - Parameter position: `MLNOrnamentPosition` defining the location.
/// - Returns: An instance of `AMLMapCompositeView`.
func compassPosition(_ position: MGLOrnamentPosition) -> AMLMapCompositeView {
func compassPosition(_ position: MLNOrnamentPosition) -> AMLMapCompositeView {
viewModel.mapSettings.compassPosition = position
return self
}

/// Set whether the map features should cluster.
/// - Parameter shouldCluster: Features displayed on the map should cluster.
/// Corresponds to the `MGLShapeSourceOption` `.clustered`.
/// Corresponds to the `MLNShapeSourceOption` `.clustered`.
/// - Returns: An instance of `AMLMapCompositeView`.
func shouldCluster(_ shouldCluster: Bool) -> AMLMapCompositeView {
viewModel.mapSettings.clusteringBehavior.shouldCluster = shouldCluster
Expand All @@ -158,7 +158,7 @@ public extension AMLMapCompositeView {

/// Specifies the maximum zoom level at which to cluster points if clustering is enabled.
/// - Parameter maxZoom: The maximum zoom level of clustering.
/// Corresponds to `MGLShapeSourceOption` `.maximumZoomLevelForClustering`.
/// Corresponds to `MLNShapeSourceOption` `.maximumZoomLevelForClustering`.
/// - Returns: An instance of `AMLMapCompositeView`.
func maximumClusterZoomLevel(_ maxZoom: Int) -> AMLMapCompositeView {
viewModel.mapSettings.clusteringBehavior.maximumZoomLevel = maxZoom
Expand All @@ -167,7 +167,7 @@ public extension AMLMapCompositeView {

/// Set the fill color of the circle cluster.
/// - Parameter color: The fill color of the circle cluster.
/// Sets the `MGLCircleStyleLayer` `circleColor` property.
/// Sets the `MLNCircleStyleLayer` `circleColor` property.
/// - Returns: An instance of `AMLMapCompositeView`.
func clusterColor(_ color: UIColor) -> AMLMapCompositeView {
viewModel.mapSettings.clusteringBehavior.clusterColor = color
Expand All @@ -176,7 +176,7 @@ public extension AMLMapCompositeView {

/// The text color of the number displayed in the circle cluster.
/// - Parameter color: The color of text displaying the number within a cluster.
/// Sets the `MGLSymbolStyleLayer` `textColor` property.
/// Sets the `MLNSymbolStyleLayer` `textColor` property.
/// - Returns: An instance of `AMLMapCompositeView`.
func clusterNumberColor(_ color: UIColor) -> AMLMapCompositeView {
viewModel.mapSettings.clusteringBehavior.clusterNumberColor = color
Expand All @@ -195,7 +195,7 @@ public extension AMLMapCompositeView {

/// Set the radius of each cluster if clustering is enabled.
/// - Parameter radius: The cluster radius.
/// Corresponds to the `MGLShapeSourceOption` `.clusterRadius`.
/// Corresponds to the `MLNShapeSourceOption` `.clusterRadius`.
/// - Returns: An instance of `AMLMapCompositeView`.
func clusterRadius(_ radius: Int) -> AMLMapCompositeView {
viewModel.mapSettings.clusteringBehavior.clusterRadius = radius
Expand Down
Loading

0 comments on commit b17775f

Please sign in to comment.