Skip to content

fix(Swift): Addressing some gaps in Geo Gen2 doc pages #7573

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

Merged
merged 3 commits into from
May 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
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ Amplify's `geo` category enables you to search by places, addresses, and coordin
```ts title="amplify/backend.ts"
import { defineBackend } from "@aws-amplify/backend";
import { Policy, PolicyStatement } from "aws-cdk-lib/aws-iam";
import { CfnPlaceIndex } from "aws-cdk-lib/aws-location";
// highlight-next-line
import { CfnMap, CfnPlaceIndex } from "aws-cdk-lib/aws-location";
import { auth } from "./auth/resource";
import { data } from "./data/resource";

Expand All @@ -47,6 +48,44 @@ const backend = defineBackend({

const geoStack = backend.createStack("geo-stack");

// create a location services map
const map = new CfnMap(geoStack, "Map", {
mapName: "myMap",
description: "Map",
configuration: {
style: "VectorEsriNavigation",
},
pricingPlan: "RequestBasedUsage",
tags: [
{
key: "name",
value: "myMap",
},
],
});


// create an IAM policy to allow interacting with geo resource
const myGeoPolicy = new Policy(geoStack, "GeoPolicy", {
policyName: "myGeoPolicy",
statements: [
new PolicyStatement({
actions: [
"geo:GetMapTile",
"geo:GetMapSprites",
"geo:GetMapGlyphs",
"geo:GetMapStyleDescriptor",
],
resources: [map.attrArn],
}),
],
});

// apply the policy to the authenticated and unauthenticated roles
backend.auth.resources.authenticatedUserIamRole.attachInlinePolicy(myGeoPolicy);
backend.auth.resources.unauthenticatedUserIamRole.attachInlinePolicy(myGeoPolicy);

// highlight-start
// create a location services place index
const myIndex = new CfnPlaceIndex(geoStack, "PlaceIndex", {
dataSource: "Here",
Expand Down Expand Up @@ -82,14 +121,26 @@ const myIndexPolicy = new Policy(geoStack, "IndexPolicy", {
// attach the policy to the authenticated and unauthenticated IAM roles
backend.auth.resources.authenticatedUserIamRole.attachInlinePolicy(myIndexPolicy);
backend.auth.resources.unauthenticatedUserIamRole.attachInlinePolicy(myIndexPolicy);
// highlight-end

// patch the place index resource to the expected output configuration
backend.addOutput({
geo: {
aws_region: geoStack.region,
maps: {
items: {
[map.mapName]: {
style: "VectorEsriNavigation",
},
},
default: map.mapName,
},
// highlight-start
search_indices: {
default: myIndex.indexName,
items: [myIndex.indexName],
},
// highlight-end
},
});
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,19 +391,19 @@ You can customize the feature images displayed on the `AMLMapView` or `AMLMapCom
{/* // spell-checker: disable */}

```swift
var body: some View {
AMLMapView(mapState: mapState)
.featureImage {
let image = UIImage(
systemName: "paperplane.circle.fill",
withConfiguration: UIImage.SymbolConfiguration(
font: .systemFont(ofSize: 22, weight: .medium)
)
)!
return image
}
.edgesIgnoringSafeArea(.all)
}
var body: some View {
AMLMapView(mapState: mapState)
.featureImage {
let image = UIImage(
systemName: "paperplane.circle.fill",
withConfiguration: UIImage.SymbolConfiguration(
font: .systemFont(ofSize: 22, weight: .medium)
)
)!
return image
}
.edgesIgnoringSafeArea(.all)
}
```

{/* // spell-checker: enable */}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -902,30 +902,6 @@ struct ContentView: View {

<Block name="UIKit">

<BlockSwitcher>
<Block name="Stable Release">

```swift
import AmplifyMapLibreAdapter
import Mapbox
import Amplify

var mapView: MGLMapView?

AmplifyMapLibre.createMap { result in
switch result {
case .failure(let error):
print(error)
case .success(let map):
mapView = map
}
}
```

</Block>

<Block name="Developer Preview">

```swift
import AmplifyMapLibreAdapter
import Mapbox
Expand All @@ -938,8 +914,6 @@ do {
print(error)
}
```
</Block>
</BlockSwitcher>

</Block>
</BlockSwitcher>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,21 +209,18 @@ dependencies {
<InlineFilter filters={['swift']}>
The Geo plugin is dependent on Cognito Auth.

<BlockSwitcher>

<Block name="Swift Package Manager">
1. To install the Amplify Libraries in your application, open your project in Xcode and select **File > Add Packages...**.

1. To install Amplify Geo and Authentication to your application, open your project in Xcode and select **File > Add Packages...**.
2. Enter the **Amplify Library for Swift** GitHub repo URL (`https://github.com/aws-amplify/amplify-swift`) into the search bar and click **Add Package**.

1. Enter the **Amplify Library for Swift** GitHub repo URL (`https://github.com/aws-amplify/amplify-swift`) into the search bar and and hit **Enter** Wait for the result to load. You'll see the repository rules for which version of amplify-ios-mapLibre you want Swift Package Manager to install.
<Callout>

1. Choose the dependency rule **Up to Next Major Version**, as it will use the latest compatible version of the dependency, then click **Add Package**.
**Note:** **Up to Next Major Version** should be selected from the **Dependency Rule** dropdown.

1. Lastly, choose **AWSLocationGeoPlugin**, **AWSCognitoAuthPlugin**, and **Amplify**. Then click Finish.
</Callout>

</Block>
3. Lastly, add **AWSLocationGeoPlugin**, **AWSCognitoAuthPlugin**, and **Amplify** to your target. Then click **Add Package**.

</BlockSwitcher>
</InlineFilter>

## Initialize Amplify Geo
Expand Down Expand Up @@ -340,12 +337,23 @@ Initialized Amplify
</InlineFilter>

<InlineFilter filters={['swift']}>
To initialize the Amplify Geo, use the `Amplify.addPlugin()` method to add the AWSLocationGeoPlugin. Next, finish configuring Amplify by calling `Amplify.configure()`.
<Callout warning>
Make sure to generate the `amplify_outputs.json` file by running the following command:

```bash title="Terminal" showLineNumbers={false}
npx ampx sandbox
```
Comment on lines +341 to +345
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be moved outside the swift block? I think we should keep the prose relatively the same across platforms (with a few exceptions) for maintainability and a concise UX

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could explore doing that in the future as a docs clean up, but right now each platform is doing its own thing

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

platform-specific callouts were (mostly) cleaned up when content was ported into this new structure. swift has the callout to move the file into the project, which is fine, but prose should be relatively the same


Next, move the file to your project. You can do this by dragging and dropping the file into your Xcode project.
</Callout>

To initialize Amplify Geo, use the `Amplify.add(plugin:)` method to add the AWS Location Geo plugin. Next, finish configuring Amplify by calling `Amplify.configure(with:)`.

Open the main file of the application - `AppDelegate.swift` or `<YOUR_APP_NAME>App.swift` depending on the app's life cycle - and **add the following** import statements at the top of the file:

```swift
import Amplify
import AWSCognitoAuthPlugin
import AWSLocationGeoPlugin
```

Expand Down
Loading