npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

amazon-location-helpers

v1.1.1

Published

Simplified use of Amazon Location Service.

Downloads

1,396

Readme

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.