3.0.1 • Published 4 years ago

@trackcode/map v3.0.1

Weekly downloads
4
License
UNLICENSED
Repository
-
Last release
4 years ago

@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

NameTypeDefaultDescription
apiKeystringGoogle Maps api key.
librariesstringplacesDefine libraries for Google Maps.
versionstringplacesUse specific Google Maps version.
childrenany@trackcode/map components e.g. <Pin />, <Driver />
defaultZoom *numberDefault zoom level
defaultCenter *objectDefault center
defaultCenter.latnumberLatitude
defaultCenter.lngnumberLongitude
defaultFullscreenControlbooleantrueThe display options for the Fullscreen control.
defaultMapTypeControlbooleantrueThe initial enabled/disabled state of the Map type control.
defaultStreetViewControlbooleantrueThe initial enabled/disabled state of the Street View Pegman control.
defaultZoomControlbooleantrueThe 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

NameTypeDefaultDescription
appearancestring"primary"The base styling to apply to the Pin. Possible values are "primary", "subtle".
position *ObjectSet position
position.latnumberLatitude
position.lngnumberLongitude
labelstringSet label
onClickfunctionHandle 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

NameTypeDefaultDescription
position *ObjectSet position
position.latnumberLatitude
position.lngnumberLongitude
titlestringShow a title tooltip
activebooleantrueBlur 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

NameTypeDefaultDescription
origin *ObjectSettings for origin
origin.locationString | LatLngLocation of origin
destination *ObjectSettings for destination
destination.locationString | LatLngLocation of origin
wayPointsArrayWay points between origin and destination
wayPoints[].locationString | LatLngSettings of a way point
autoFitBoundsBooleantrueFit bounds based on direction path

Type: (Object) LatLng

NameTypeDescription
latnumberLatitude
lngnumberLongitude

* 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

NameTypeDefaultDescription
positions *ArrayList of LatLng positions.
positions[].latnumberLatitude
positions[].lngnumberLongitude
useConvexHullBooleantrueUse "convex hull" to draw outline polygon of a set of positions.

* required

Inspiration

3.0.1

4 years ago

3.0.0

4 years ago

3.0.0-alpha.3

4 years ago

3.0.0-alpha.1

4 years ago

3.0.0-alpha.0

4 years ago

2.0.0

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago

0.3.0-beta.1

5 years ago

0.2.6

6 years ago

0.2.0

6 years ago

0.1.0

6 years ago

0.0.4

6 years ago