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

react-google-maps-ts

v0.0.15

Published

React components library for google maps.

Downloads

5

Readme

react-google-maps

React components library for google maps.

Library is under active development. It is not recomended for production usage so far.

import {GoogleApiProvider, Map, Marker} from 'react-google-maps-ts';

const App = () => (
  <GoogleApiProvider
    apiKey="<API_KEY>"
  >
    <MyAwesomeApp />
  </GoogleApiProvider>
);

const geoPoint = {lat: 50, lng: 50};

const MyAwesomeApp = () => (
  <Map
    defaultCenter={geoPoint}
  >
    <Marker 
      position={geoPoint}
      zoom={8}
      title="My perfect marker"
    />
  </Map>
);
Implemented features:
  • Marker
  • Polygon
  • Polyline
  • Circle
  • Rectangle
  • TilesOverlay (MapType)
  • DomOverlay (OverlayView)
  • GroundOverlay
  • InfoWindow

GoogleMapsProvider

Common API loading

import {GoogleApiProvider} from 'react-google-maps-ts';

const App = () => (
  <GoogleApiProvider
    apiKey="<API_KEY>"
    geometry // include geometry library
    drawing // include drawing library
    places // include places library
    visualization // include visualization library
    language='en' // Google Maps localization
    region='GB'
    version='quarterly' // Google Maps versioning
  >
    <MyAwesomeApp />
  </GoogleApiProvider>
);

Proxy API loading

You can load Google API using your own proxy

import {GoogleApiProvider} from 'react-google-maps-ts';

const App = () => (
  <GoogleApiProvider
    proxy='<Your proxy URL>'
  >
    <MyAwesomeApp />
  </GoogleApiProvider>
);

Custom loading callback

You can load Google API using your own loading method

import {GoogleApiProvider} from 'react-google-maps-ts';

const load = async (): Promise<GoogleObject> => {
  // implementation

  return googleApi;
}

const App = () => (
  <GoogleApiProvider
    load={load}
  >
    <MyAwesomeApp />
  </GoogleApiProvider>
);

Extending library with you own classes

You can extend Google API with your custom objects

import {GoogleApiProvider} from 'react-google-maps-ts';

const extend = async (google: Google): void => {
  google["<your namespace>"] = // your extension;
}

const App = () => (
  <GoogleApiProvider
    apiKey="<API_KEY>"
    extend={extend}
  >
    <MyAwesomeApp />
  </GoogleApiProvider>
);

Smart vs Dumb components

Main purpose of this library is combining of declarative React syntax with free accessibility to Google Maps objects without doubtful workarounds.

Each component has smart and dumb implementations.

Smart components

Smart components are self-contained. They have their own encapsulated Google Maps objects and you can't access them. But they are extremely simple to use and their intarfaces are similar to corresponding Google Maps object.

import {Map, Marker} from 'react-google-maps-ts';

const geoPoint = {lat: 50, lng: 50};

const MyAwesomeApp = () => (
  <Map
    defaultCenter={geoPoint}
  >
    <Marker 
      position={geoPoint}
      zoom={8}
      title="My perfect marker"
    />
  </Map>
);

Dumb components

Dumb components use Google Maps objects from external context. So you can access it if you need.

import {DumbMap, withSmartMapCtx, MapService, useGoogleCtx} from 'react-google-maps-ts';

interface AwesomeAppProps {
  ...
};

const geoPoint = {lat: 50, lng: 50};

const MyAwesomeApp = (
  {mapService}: AwesomeAppProps & {mapService: MapService | undefined}
) => {  
  const googleApi = useGoogleCtx();

  const centerMap = () => { 
    // Notice that such approach creates new function on each render
    // It is provided only as example. It is recomended to avoid it.

    if (!mapService || !googleApi) return;

    const {object} = mapService; // Google Maps object;

    const defaultCenter = new googleApi.maps.LatLng(geoPoint.lat, geoPoint.lng);

    object.setCenter(defaultCenter);
  }

  return (
    <>
      <button onClick={centerMap}>Center map</button>
      <DumbMap
        defaultCenter={geoPoint}
      />
    </>
  );
}

withSmartMapCtx<AwesomeAppProps>(MyAwesomeApp);