Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

amazon-location-helpers

Package Overview
Dependencies
Maintainers
2
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

amazon-location-helpers

Simplified use of Amazon Location Service.

  • 1.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
233
decreased by-7.17%
Maintainers
2
Weekly downloads
 
Created
Source

Amazon Location Helpers

amazon-location-helpers helps initialize MapLibre GL JS maps for use with Amazon Location Service. Given an Amazon Cognito Identity Pool ID (or provided an AWS Credentials object) and the name of a Map resource, this will fetch AWS credentials and initialize a Map instance, configured to sign requests with Signature Version 4.

See Allowing unauthenticated guest access to your application using Amazon Cognito for instructions on how to create an Identity Pool. The Identity Pool ID will be used below.

Installation

amazon-location-helpers can be installed from npm for use with apps that include a build step:

npm install amazon-location-helpers

amazon-location-helpers can also be used in static HTML documents. For full functionality, MapLibre GL JS, the AWS SDK for JavaScript, and AWS Amplify Core must be loaded:

<html>
  <head>
    <link
      href="https://unpkg.com/maplibre-gl@1/dist/maplibre-gl.css"
      rel="stylesheet"
    />
  </head>

  <body>
    <div id="map" style="height: 100vh" />
    <script src="https://unpkg.com/maplibre-gl@1"></script>
    <script src="https://unpkg.com/amazon-location-helpers@1"></script>
    <script>
      AmazonLocation.createMap(
        {
          "us-east-1:54f2ba88-9390-498d-aaa5-0d97fb7ca3bd",
        },
        {
          container: "map",
          center: [-123.1187, 49.2819], // initial map centerpoint
          zoom: 10, // initial map zoom
          style: "explore.map,
          hash: true,
        }
      );
    </script>
  </body>
</html>

API

createMap

function createMap(
  config: {
    credentials?: Credentials;
    identityPoolId?: string;
    region?: string;
  },
  options: mapboxgl.MapboxOptions,
  mapgl?: typeof mapboxgl
): Promise<mapboxgl.Map>;

This will instantiate a Map, exchange the provided Amazon Cognito Identity Pool ID for AWS credentials, load the style associated with the explore.map Map resource, and render it to the <div> identified as map, centered on Vancouver, British Columbia:

const map = await AmazonLocation.createMap(
  "us-east-1:54f2ba88-9390-498d-aaa5-0d97fb7ca3bd",
  {
    container: "map",
    center: [-123.1187, 49.2819], // initial map centerpoint
    zoom: 10, // initial map zoom
    style: "explore.map",
  }
);

For a fully worked example, see maplibre-gl-js/index.html.

createRequestTransformer

function createRequestTransformer(config: {
  credentials?: Credentials;
  identityPoolId?: string;
  region?: string;
}): Promise<mapboxgl.TransformRequestFunction>;

This will initialize a transformRequest function suitable for providing to Map's transformRequest property that will intercept requests made by MapLibre GL JS to AWS and sign them using Signature Version 4:

import { createRequestTransformer } from "amazon-location-helpers";

const transformRequest = await createRequestTransformer({
  identityPoolId: "us-east-1:54f2ba88-9390-498d-aaa5-0d97fb7ca3bd",
});

This can then be used with react-map-gl:

// React equivalent to the above example
<ReactMapGL
  latitude={49.2819}
  longitude={-123.1187}
  zoom={10}
  width="100%"
  height="100vh"
  transformRequest={transformRequest}
  mapStyle="explore.map"
/>

For a fully worked example, see maplibre-gl-js-react/src/index.tsx.

getCredentialsForIdentityPool


function getCredentialsForIdentityPool(
  identity: string
): Promise<Credentials>;

This will exchange an Amazon Cognito Identity Pool ID for temporary AWS credentials. For example:

const credentials = await AmazonLocation.getCredentialsForIdentityPool("us-east-1:54f2ba88-9390-498d-aaa5-0d97fb7ca3bd");

// use credentials with other AWS services

Security

See CONTRIBUTING for more information.

License

This library is licensed under the MIT-0 License. See the LICENSE file.

FAQs

Package last updated on 08 Oct 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc