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

google-maps-js-api-loader

v4.0.3

Published

A lightweight JavaScript library for loading the Google Maps JavaScript API

Downloads

340

Readme

google-maps-js-api-loader

Description

Lightweight JavaScript library that simplifies the process of adding Google Maps JavaScript API to web application.

Installation

using npm:

npm install --save google-maps-js-api-loader

or yarn:

yarn add google-maps-js-api-loader

or pnpm:

pnpm add google-maps-js-api-loader

Example

import { GoogleMapsLoader } from 'google-maps-js-api-loader';

GoogleMapsLoader(
  {
    key: API_KEY,
    // ...some other options
  },
  { async: true }
);

if (GoogleMapsLoader.getStatus() === 'loaded') {
  console.log('google.maps is ready');
}

GoogleMapsLoader.getCompletion('maps').then(({ Map }) =>
  // ...do something with Map
);

const [{ Map }, { AutocompleteService }] = await GoogleMapsLoader.load(
  'maps',
  'places'
);

API

GoogleMapsLoader

function GoogleMapsLoader(
  options: GoogleMapsLoaderOptions,
  scriptOptions: ScriptOptions,
  callbackName?: string
): GoogleMapsLoader;

Sets options for a Google Maps JavaScript API script, options must be set before load is executed

| GoogleMapsLoaderOptions | Description | | ----------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | key | Your API key | | v? | The version of the Google Maps JavaScript API to use | | language? | The language to use. This affects the names of controls, copyright notices, driving directions, and control labels, as well as the responses to service requests. See the list of supported languages | | region? | The region code to use. This alters the map's behavior based on a given country or territory | | auth_referrer_policy? | Maps JS customers can configure HTTP Referrer Restrictions in the Cloud Console to limit which URLs are allowed to use a particular API Key. By default, these restrictions can be configured to allow only certain paths to use an API Key. If any URL on the same domain or origin may use the API Key, you can set "origin" to limit the amount of data sent when authorizing requests from the Google Maps JavaScript API. This is available starting in version 3.46. When this parameter is specified and HTTP Referrer Restrictions are enabled on Cloud Console, Google Maps JavaScript API will only be able to load if there is an HTTP Referrer Restriction that matches the current website's domain without a path specified |

scriptOptions - object with options for script element

callbackName - Google Maps JavaScript API load callback name, "__gmlcb" by default


load

static load(): Promise<void>;

static load<L extends GoogleMapsLibrary>(
  library: L
): Promise<GoogleMapsLibraries[L]>;

static load<const A extends GoogleMapsLibrary[]>(
  ...libraries: A
): Promise<{
  [Index in keyof A]: GoogleMapsLibraries[A[Index]];
}>;

Can be called multiple times, only on the first call it starts loading Google Maps JavaScript API script with the given options

Returns a promise that resolves when the Google Maps JavaScript API script and specified libraries have been successfully loaded, or rejects if an error occurs during the loading process.


getStatus

type GoogleMapsLoaderStatus = "none" | "loading" | "loaded" | "error";

static getStatus(): GoogleMapsLoaderStatus;

static getStatus(library: GoogleMapsLibrary): GoogleMapsLoaderStatus;

Returns current status of GoogleMapsLoader or provided library loading


getCompletion

static getCompletion(): Promise<void>;

static getCompletion<L extends GoogleMapsLibrary>(
  library: L
): Promise<GoogleMapsLibraries[L]>;

static getCompletion<const A extends GoogleMapsLibrary[]>(
  ...libraries: A
): Promise<{
  [Index in keyof A]: GoogleMapsLibraries[A[Index]];
}>;

Returns a promise that resolves when the Google Maps JavaScript API script and specified libraries have been successfully loaded, or rejects if an error occurs during the loading process.


get

static get<L extends GoogleMapsLibrary>(
  library: L
): GoogleMapsLibraries[L] | undefined;

Returns the provided library or undefined if it has not been loaded yet.


getError

static getError(): Error | undefined;

static getError(
  library: GoogleMapsLibrary
):
  | google.maps.MapsServerError
  | google.maps.MapsNetworkError
  | google.maps.MapsRequestError
  | undefined;

Returns the error for the provided library or undefined


License

MIT © Andrii Dubetskyi