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 🙏

© 2026 – Pkg Stats / Ryan Hefner

reactive-atlas

v1.7.0

Published

Google Maps JavaScript v3 API React Wrapper.

Readme

Atlas

atlas the greek god

A Google Maps React library. Written because I was dissatisfied with fullstackreact/google-maps-react. Will have focus on minimal rerenders, and trying to rely as much as possible on the Google Maps Javascript API (v3).

NPM JavaScript Style Guide

Live demo

Notes

  • google.maps.LatLngLiteral is just an object of type { lat: number, lng: number }

Install

yarn add reactive-atlas

Usage

API Provider

First of all, you have to setup the global API provider. This is required by the library to work. I recommend you wrap the highest common component of all components that require access to the map with this.

import { GoogleAPIProvider } from "reactive-atlas";

const Root: React.FC = props => (
  <GoogleAPIProvider apiKey="API_KEY">{props.children}</GoogleAPIProvider>
);

useGoogle

This is a hook that returns a google object containing all the methods exposed to us. Has to be used in a component that is a child of GoogleAPIProvider;

import { useGoogle } from "reactive-atlas";

const ComponentThatUsesGoogleAPI: React.FC = props => {
  const google = useGoogle();

  // ...
};

Map

The map is the most important object. It has to be a child (though not direct) of GoogleAPIProvider.

The required options are zoom and center. A number (0-18 inclusive), and google.maps.LatLng or google.maps.LatLngLiteral, respectively.

import { Map, useGoogle } from "reactive-atlas";

const Globus = () => {
  const google = useGoogle();

  return <Map options={{ zoom: 8, center: new google.maps.LatLng(1, 2) }} />;
};

All Markers and other elements should be children of a map, and you should not nest Maps.

Marker

The marker is a common object in maps. It has to be a child of a Map.

import { Map, Marker, useGoogle } from "reactive-atlas";

const Globus = () => {
  const google = useGoogle();

  return (
    <Map options={{ zoom: 8, center: new google.maps.LatLng(1, 2) }}>
      <Marker
        options={{
          position: new google.maps.LatLng(63, 10),
          title: "Hello, World!",
          label: "B"
        }}
      />
    </Map>
  );
};

InfoWindow (and ref forwarding)

The InfoWindow can be handy if you want to display extra information about e.g. a Marker.

import { InfoWindow, Marker, Map, useGoogle } from "reactive-atlas";

const IWExample = () => {
  const ref = React.useRef<Marker>();
  const [open, setOpen] = React.useState(false);

  return (
    <Map options={{ zoom: 8, center: new google.maps.LatLng(1, 2) }}>
      <Marker
        ref={ref}
        options={{
          position: new google.maps.LatLng(63, 10),
          title: "Hello, World!",
          label: "B"
        }}
        eventHandlers={[["click", () => setOpen(o => !o)]]}
      />

      <InfoWindow
        open={open}
        setOpen={setOpen}
        anchor={() => ref.current.marker}
      >
        <p>Hello, World!</p>
      </InfoWindow>
    </Map>
  );
};

As you can see, you can pass a ref to the Marker, and later get out the underlying marker property.

Circle

Exactly the same usage as Marker.

Required option keys are radius: number, and center: google.maps.LatLng | google.maps.LatLngLiteral.

import { Map, Circle, useGoogle } from "reactive-atlas";

const Globus = () => {
  const google = useGoogle();

  return (
    <Map options={{ zoom: 8, center: new google.maps.LatLng(1, 2) }}>
      <Circle
        options={{
          center: new google.maps.LatLng(63, 10),
          radius: 128000
        }}
      />
    </Map>
  );
};

Example of resizable and movable circle

First you have to wrap it in a Provider and Map of course.

Create an event handler which simply prints the new location and radius.

const circleChangePosRadius = circle =>
  console.log(
    `Circle is at ${circle
      .getCenter()
      .toString()} with radius ${circle.getRadius()}.`
  );

Wire it up to print pos/radius every time the radius or center changes.

<Circle
  options={{
    editable: true,
    radius: 100000,
    center: new google.maps.LatLng(63, 10)
  }}
  eventHandlers={[
    ["radius_changed", circleChangePosRadius],
    ["center_changed", circleChangePosRadius]
  ]}
/>

The same principles would be used when making a Marker draggable; just replace radius_changed/center_changed with dragend.

Events

To retain as much of the original code as possible from the google API, I've decided to opt for a bit strange event handling. Instead of doing like google-maps-react (the reason I'm making this library) and using "standard" HTML-like handlers (i.e. onCenter_changed (the weird combination of camelCase and snake_case is because google uses snake-case, and HTML uses camelCase)), I've opted to use a list of event handlers you'd like to attach to the element. This property can be used on Map, Marker, and Circle (as of now).

To remove an event handler, simply remove the entry from the array of handlers, and the library will remove the listener. It will also clean up all listeners when unmounting.

The first parameter in the callback function is the object you're operating on, so in the next example, it's a marker, but if you were to add a listener to a circle, it would be the circle. This allows you to operate directly on the google API, which might be desirable.

The second parameter is a list with one of the following;

  1. Nothing, i.e. []
  2. undefined, i.e. [undefined]
  3. The event (e.g. MouseEvent), i.e. [MouseEvent]

This is a bit strange, but it works quite well. I believe it was intended for possible expansion, so that you could pass more than one event.

import { Map, Marker, useGoogle } from "reactive-atlas";

const Globus = () => {
  const google = useGoogle();

  return (
    <Map options={{ zoom: 8, center: new google.maps.LatLng(1, 2) }}>
      <Marker
        options={{
          position: new google.maps.LatLng(pos, pos)
        }}
        eventHandlers={[
          [
            "click",
            (marker, evt) => {
              // Make it jump!
              marker.setAnimation(google.maps.Animation.BOUNCE);
              setTimeout(() => marker.setAnimation(null), 500);
            }
          ]
        ]}
      />
    </Map>
  );
};

Bounds

Often times, you want to specify the bounds of the place you want to see.

You can do this using the bounds prop on Map. Simply send in a google.maps.LatLngBounds | google.maps.LatLngBoundsLiteral object, and it will scale to that area. If you change the bounds, the map will fit to the new area and pan there.

Styling

For now, there isn't really much styling on the map. It's container is set to flex-grow: 1, which means that you should try to use flex to control the positioning.

License

MIT © fredrikaugust