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(geo): add region to Amazon Location Service MapStyle #8736

Merged
merged 1 commit into from
Aug 11, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions packages/geo/__tests__/Geo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,11 @@ describe('Geo', () => {

const maps = [];
const availableMaps = awsConfig.geo.amazon_location_services.maps.items;
const region = awsConfig.geo.amazon_location_services.region;

for (const mapName in availableMaps) {
const style = availableMaps[mapName].style;
maps.push({ mapName, style });
maps.push({ mapName, style, region });
}

expect(geo.getAvailableMaps()).toEqual(maps);
Expand Down Expand Up @@ -179,7 +181,8 @@ describe('Geo', () => {
const mapName = awsConfig.geo.amazon_location_services.maps.default;
const style =
awsConfig.geo.amazon_location_services.maps.items[mapName].style;
const testMap = { mapName, style };
const region = awsConfig.geo.amazon_location_services.region;
const testMap = { mapName, style, region };

const defaultMapsResource = geo.getDefaultMap();
expect(defaultMapsResource).toEqual(testMap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,10 @@ describe('AmazonLocationServicesProvider', () => {

const maps = [];
const availableMaps = awsConfig.geo.amazon_location_services.maps.items;
const region = awsConfig.geo.amazon_location_services.region;
for (const mapName in availableMaps) {
const style = availableMaps[mapName].style;
maps.push({ mapName, style });
maps.push({ mapName, style, region });
}

expect(provider.getAvailableMaps()).toEqual(maps);
Expand Down Expand Up @@ -136,7 +137,9 @@ describe('AmazonLocationServicesProvider', () => {
const mapName = awsConfig.geo.amazon_location_services.maps.default;
const style =
awsConfig.geo.amazon_location_services.maps.items[mapName].style;
const testMap = { mapName, style };
const region = awsConfig.geo.amazon_location_services.region;

const testMap = { mapName, style, region };

const defaultMapsResource = provider.getDefaultMap();
expect(defaultMapsResource).toEqual(testMap);
Expand Down
24 changes: 15 additions & 9 deletions packages/geo/src/Providers/AmazonLocationServicesProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
* and limitations under the License.
*/
import camelcaseKeys from 'camelcase-keys';
import { ConsoleLogger as Logger, Credentials, getAmplifyUserAgent } from '@aws-amplify/core';
import {
ConsoleLogger as Logger,
Credentials,
getAmplifyUserAgent,
} from '@aws-amplify/core';
import {
Place as PlaceResult,
SearchPlaceIndexForTextCommandInput,
Expand All @@ -27,7 +31,7 @@ import {
SearchByCoordinatesOptions,
GeoProvider,
Place,
MapStyle,
AmazonLocationServiceMapStyle,
Coordinates,
} from '../types';

Expand Down Expand Up @@ -81,31 +85,32 @@ export class AmazonLocationServicesProvider implements GeoProvider {

/**
* Get the map resources that are currently available through the provider
* @returns {MapStyle[]}- Array of available map resources
* @returns {AmazonLocationServiceMapStyle[]}- Array of available map resources
*/
public getAvailableMaps(): MapStyle[] {
public getAvailableMaps(): AmazonLocationServiceMapStyle[] {
if (!this._config.maps) {
throw new Error(
"No map resources found in amplify config, run 'amplify add geo' to create them and ensure to run `amplify push` after"
);
}

const mapStyles: MapStyle[] = [];
const mapStyles: AmazonLocationServiceMapStyle[] = [];
const availableMaps = this._config.maps.items;
const region = this._config.region;

for (const mapName in availableMaps) {
const style = availableMaps[mapName].style;
mapStyles.push({ mapName, style });
mapStyles.push({ mapName, style, region });
}

return mapStyles;
}

/**
* Get the map resource set as default in amplify config
* @returns {MapStyle} - Map resource set as the default in amplify config
* @returns {AmazonLocationServiceMapStyle} - Map resource set as the default in amplify config
*/
public getDefaultMap(): MapStyle {
public getDefaultMap(): AmazonLocationServiceMapStyle {
if (!this._config.maps) {
throw new Error(
"No map resources found in amplify config, run 'amplify add geo' to create them and ensure to run `amplify push` after"
Expand All @@ -119,8 +124,9 @@ export class AmazonLocationServicesProvider implements GeoProvider {

const mapName = this._config.maps.default;
const style = this._config.maps.items[mapName].style;
const region = this._config.region;

return { mapName, style };
return { mapName, style, region };
}

/**
Expand Down
5 changes: 5 additions & 0 deletions packages/geo/src/types/AmazonLocationServicesProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { MapStyle } from './Geo';

export interface AmazonLocationServiceMapStyle extends MapStyle {
region: string;
}
1 change: 1 addition & 0 deletions packages/geo/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './Geo';
export * from './Provider';
export * from './AmazonLocationServicesProvider';