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

@trackcode/map

v3.0.1

Published

<!-- STORY -->

Downloads

16

Readme

@trackcode/map

A lightweight react package to interact with google maps.

npm install --save @trackcode/map

Load Google Maps dynamically (recommended)

import React from "react";
import { Pin } from "@trackcode/map";

const MyMap = () => (
  <Map
    apiKey="YOU_API_KEY"
    libraries="places,geometry" // default "places"
    defaultZoom={14}
    defaultCenter={{ lat: 52.01525584, lng: 8.52046783 }}
  >
    <Pin label="A" position={{ lat: 52.02221556, lng: 8.53188536 }} />
  </Map>
);

Use script tag to load Google Maps

Add this script tag to the <head> of your website:

<script src="https://maps.googleapis.com/maps/api/js?key=API_KEY&libraries=places"></script>

Example:

import React from "react";
import { Map, Pin, Driver } from "@trackcode/map";

const MyMap = () => (
  <div style={{ width: "350px", height: "400px" }}>
    <Map defaultZoom={14} defaultCenter={{ lat: 52.01525584, lng: 8.52046783 }}>
      <Pin label="A" position={{ lat: 52.02221556, lng: 8.53188536 }} />
      <Driver position={{ lat: 52.01757214, lng: 8.52521203 }} />
    </Map>
  </div>
);

<Map />

Important component to show the map.

Example

<Map
  defaultZoom={14}
  defaultCenter={{ lat: 52.01525584, lng: 8.52046783 }}
>

Properties

| Name | Type | Default | Description | | :----------------------- | :------ | :------- | :-------------------------------------------------------------------- | | apiKey | string | | Google Maps api key. | | libraries | string | places | Define libraries for Google Maps. | | version | string | places | Use specific Google Maps version. | | children | any | | @trackcode/map components e.g. <Pin />, <Driver /> | | defaultZoom * | number | | Default zoom level | | defaultCenter * | object | | Default center | | defaultCenter.lat | number | | Latitude | | defaultCenter.lng | number | | Longitude | | defaultFullscreenControl | boolean | true | The display options for the Fullscreen control. | | defaultMapTypeControl | boolean | true | The initial enabled/disabled state of the Map type control. | | defaultStreetViewControl | boolean | true | The initial enabled/disabled state of the Street View Pegman control. | | defaultZoomControl | boolean | true | The enabled/disabled state of the Zoom control. |

* required

<Pin />

A pin (or marker) to show a location on the map.

Example

<Pin
  appearance="subtle"
  position={{ lat: 52.0277157, lng: 8.50419146 }}
/>
<Pin position={{ lat: 52.0287157, lng: 8.52419146 }} />
<Pin label="A" position={{ lat: 52.0287157, lng: 8.54419146 }} />

Properties

| Name | Type | Default | Description | | :----------- | :------- | :---------- | :--------------------------------------------------------------------------------- | | appearance | string | "primary" | The base styling to apply to the Pin. Possible values are "primary", "subtle". | | position * | Object | | Set position | | position.lat | number | | Latitude | | position.lng | number | | Longitude | | label | string | | Set label | | onClick | function | | Handle click event. |

* required

<Driver />

Show a driver point on map. This component is able to animate position changes in a smooth way.

Example

<Driver position={{ lat: 52.0287157, lng: 8.52419146 }} />
<Driver active={false} title="Inactive" position={{ lat: 52.0287157, lng: 8.53419146 }} />

Properties

| Name | Type | Default | Description | | :----------- | :------ | :------ | :---------------------------------------------- | | position * | Object | | Set position | | position.lat | number | | Latitude | | position.lng | number | | Longitude | | title | string | | Show a title tooltip | | active | boolean | true | Blur color for active and gray if it's inactive |

* required

<Directions />

Show directions on map.

Example

<Directions
  origin={{
    location: { lat: 52.012054, lng: 8.537375 },
  }}
  wayPoints={[{ location: "Herforder Straße 1, Bielefeld" }]}
  destination={{
    location: "Siegfriedstr. 18, Bielefeld",
  }}
/>

Properties

| Name | Type | Default | Description | | :------------------- | :------------------- | :------ | :---------------------------------------- | | origin * | Object | | Settings for origin | | origin.location | String | LatLng | | Location of origin | | destination * | Object | | Settings for destination | | destination.location | String | LatLng | | Location of origin | | wayPoints | Array | | Way points between origin and destination | | wayPoints[].location | String | LatLng | | Settings of a way point | | autoFitBounds | Boolean | true | Fit bounds based on direction path |

Type: (Object) LatLng

| Name | Type | Description | | :--- | :----- | :---------- | | lat | number | Latitude | | lng | number | Longitude |

* required

<Polygon />

Show polygon on map.

Example

<Polygon
  positions={[
    { lat: 52.01525584, lng: 8.52046783 },
    { lat: 52.02382442, lng: 8.52382776 },
    { lat: 52.02029969, lng: 8.53465948 },
    { lat: 52.00129969, lng: 8.53465948 },
    { lat: 52.01665505, lng: 8.55311308 },
    { lat: 52.0192433, lng: 8.55328474 },
  ]}
/>

Properties

| Name | Type | Default | Description | | :-------------- | :------ | :------ | :--------------------------------------------------------------- | | positions * | Array | | List of LatLng positions. | | positions[].lat | number | | Latitude | | positions[].lng | number | | Longitude | | useConvexHull | Boolean | true | Use "convex hull" to draw outline polygon of a set of positions. |

* required

Inspiration

  • react-google-maps, March 2018, https://github.com/tomchentw/react-google-maps
  • google-map-react, March 2018, https://github.com/google-map-react/google-map-react