diff --git a/platform/darwin/src/MLNPolyline.h b/platform/darwin/src/MLNPolyline.h index f2c4d6fda..bf42171d0 100644 --- a/platform/darwin/src/MLNPolyline.h +++ b/platform/darwin/src/MLNPolyline.h @@ -52,7 +52,10 @@ NS_ASSUME_NONNULL_BEGIN geometry in GeoJSON. #### Related examples - TODO: Annotation models, learn how to add an `MLNPolyine` object to your map. + + - + + TODO: Annotation models, learn how to add an `MLNPolyine` object to your map. */ MLN_EXPORT @interface MLNPolyline : MLNMultiPoint diff --git a/platform/ios/MapLibre.docc/GettingStarted.md b/platform/ios/MapLibre.docc/GettingStarted.md index 6a821a8a0..be2665a6f 100644 --- a/platform/ios/MapLibre.docc/GettingStarted.md +++ b/platform/ios/MapLibre.docc/GettingStarted.md @@ -32,13 +32,13 @@ To use MapLibre with SwiftUI we need to create a wrapper for the UIKit view that ```swift struct MapLibreMapView: UIViewRepresentable { - private let mapView = MLNMapView() - - func makeUIView(context: Context) -> some UIView { + + func makeUIView(context: Context) -> MLNMapView { + let mapView = MLNMapView() return mapView } - func updateUIView(_ uiView: UIViewType, context: Context) { + func updateUIView(_ mapView: MLNMapView, context: Context) { } } ``` diff --git a/platform/ios/MapLibre.docc/LineOnUserTap.md b/platform/ios/MapLibre.docc/LineOnUserTap.md new file mode 100644 index 000000000..776762b0b --- /dev/null +++ b/platform/ios/MapLibre.docc/LineOnUserTap.md @@ -0,0 +1,64 @@ +# Add Line on User Tap + +Demonstrating adding ``MLNPolyline`` annotations and responding to user input. + +## Overview + +This example draws a line from the tapped location to the center of the map. Handling the tap is done by the `Coordinator` class. It converts the location on the view to a geographic coordinate. It removes existing annotations before adding the new line. + +```swift +struct MapLibreMapView: UIViewRepresentable { + + func makeUIView(context: Context) -> MLNMapView { + let mapView = MLNMapView() + + // Add a single tap gesture recognizer + let singleTap = UITapGestureRecognizer( + target: context.coordinator, + action: #selector(Coordinator.handleMapTap(sender:))) + for recognizer in mapView.gestureRecognizers! where recognizer is UITapGestureRecognizer { + singleTap.require(toFail: recognizer) + } + mapView.addGestureRecognizer(singleTap) + return mapView + } + + func updateUIView(_ mapView: MLNMapView, context: Context) { + } + + func makeCoordinator() -> Coordinator { + Coordinator(self) + } + + class Coordinator: NSObject { + var parent: MapLibreMapView + + init(_ parent: MapLibreMapView) { + self.parent = parent + } + + @objc func handleMapTap(sender: UITapGestureRecognizer) { + guard let mapView = sender.view as? MLNMapView else { return } + + // Convert tap location (CGPoint) to geographic coordinate (CLLocationCoordinate2D). + let tapPoint: CGPoint = sender.location(in: mapView) + let tapCoordinate: CLLocationCoordinate2D = mapView.convert(tapPoint, toCoordinateFrom: nil) + print("You tapped at: \(tapCoordinate.latitude), \(tapCoordinate.longitude)") + + // Create an array of coordinates for our polyline, starting at the center of the map and ending at the tap coordinate. + var coordinates: [CLLocationCoordinate2D] = [mapView.centerCoordinate, tapCoordinate] + + // Remove any existing polyline(s) from the map. + if let existingAnnotations = mapView.annotations { + mapView.removeAnnotations(existingAnnotations) + } + + // Add a polyline with the new coordinates. + let polyline = MLNPolyline(coordinates: &coordinates, count: UInt(coordinates.count)) + mapView.addAnnotation(polyline) + } + } +} +``` + +![](polyline.gif) \ No newline at end of file diff --git a/platform/ios/MapLibre.docc/MapLibre.md b/platform/ios/MapLibre.docc/MapLibre.md index 578038d8b..51a797419 100644 --- a/platform/ios/MapLibre.docc/MapLibre.md +++ b/platform/ios/MapLibre.docc/MapLibre.md @@ -11,9 +11,10 @@ Powerful, free and open-source mapping toolkit with full control over data sourc [MapLibre Native](https://github.com/maplibre/maplibre-native) is a map rendering toolkit with support for iOS. It can be used as an alternative to MapKit. You have full control over the data sources used for rendering the map, as well as the styling. You can even participate in the development as MapLibre Native is free and open-source project. > Note: For information on creating and modifying map styles, see the [MapLibre Style Spec documentation](https://maplibre.org/maplibre-style-spec/). -## Essentials +## Guides - +- ## Topics diff --git a/platform/ios/scripts/docc.sh b/platform/ios/scripts/docc.sh index 2f83836fe..5a5183141 100755 --- a/platform/ios/scripts/docc.sh +++ b/platform/ios/scripts/docc.sh @@ -33,20 +33,7 @@ bazel build --//:renderer=metal //platform/darwin:generated_style_public_hdrs # download resources from S3 -resources=( - "AddPackageDependencies@2x.png" - "DemotilesScreenshot@2x.png" -) - -destination_dir="platform/ios/MapLibre.docc/Resources" - -for file in "${resources[@]}"; do - if [[ ! -f "$destination_dir/$file" ]]; then - aws s3 cp --no-sign-request "s3://maplibre-native/ios-documentation-resources/$file" "$destination_dir" - else - echo "Skipped: $file already exists in the destination directory" - fi -done +aws s3 sync --no-sign-request "s3://maplibre-native/ios-documentation-resources" "platform/ios/MapLibre.docc/Resources" public_headers=$(bazel query 'kind("source file", deps(//platform:ios-sdk, 2))' --output location | grep ".h$" | sed -r 's#.*/([^:]+).*#\1#') style_headers=$(bazel cquery --//:renderer=metal //platform/darwin:generated_style_public_hdrs --output=files)