6.0.3 • Published 2 years ago

bpk-component-map-css v6.0.3

Weekly downloads
195
License
Apache-2.0
Repository
github
Last release
2 years ago

bpk-component-map

Backpack map component.

Requires React 16.8+

Installation

npm install bpk-component-map --save-dev

Usage

import React from 'react';
import BpkText from 'bpk-component-text';
import { withRtlSupport } from 'bpk-component-icon';
import LandmarkIconSm from 'bpk-component-icon/sm/landmark';
import BpkMap, {
  BpkIconMarker,
  BpkOverlayView,
} from 'bpk-component-map';

const AlignedLandmarkIconSm = withRtlSupport(LandmarkIconSm);

export default () => (
  <BpkMap
    zoom={15}
    showControls={false}
    panEnabled={false}
    center={{
      latitude: 27.9881,
      longitude: 86.925,
    }}
  >
    <BpkIconMarker
      icon={<AlignedLandmarkIconSm />}
      position={{ latitude: 27.9881, longitude: 86.925 }}
      onClick={() => {}}
    />
    <BpkIconMarker
      icon={<AlignedLandmarkIconSm />}
      position={{ latitude: 27.9881, longitude: 86.925 }}
      onClick={() => {}}
      selected
    />
    <BpkIconMarker
      icon={<AlignedLandmarkIconSm />}
      position={{ latitude: 27.9881, longitude: 86.927 }}
      onClick={() => {}}
      disabled
    />
    <BpkOverlayView position={{ latitude: 27.9881, longitude: 86.925 }}>
      <BpkText>Shibuya Crossing</BpkText>
    </BpkOverlayView>
  </BpkMap>
);

BpkPriceMarker

Price markers are used to display clickable prices on a map.

import React from 'react';
import BpkMap, { BpkPriceMarker, PRICE_MARKER_STATUSES } from 'bpk-component-map';

export default () => (
  <BpkMap
    zoom={15}
    showControls={false}
    panEnabled={false}
    center={{
      latitude: 27.9881,
      longitude: 86.925,
    }}
  >
    <BpkPriceMarker
      label="£120"
      position={{ latitude: 27.9881, longitude: 86.925 }}
      onClick={() => {
        console.log("Price marker pressed.")
      }}
      status={PRICE_MARKER_STATUSES.focused}
    />
    <BpkPriceMarker
      label="£120"
      position={{ latitude: 27.9881, longitude: 86.925 }}
      onClick={() => {
        console.log("Price marker pressed.")
      }}
      status={PRICE_MARKER_STATUSES.viewed}
    />
  </BpkMap>
);

Accompanying HOCs

withGoogleMapsScript

withGoogleMapsScript is a HOC that loads the Google Maps JavaScript, then loads the map. This is useful for when you don't already have the Google Maps JavaScript loaded.

If you intend to include multiple maps on one page, it's better to load the Google Maps JavaScript in this HOC, as it ensures that script will not be re-downloaded every time it's used.

import React from 'react';
import BpkMap, { withGoogleMapsScript } from 'bpk-component-map';

const BpkMapWithScript = withGoogleMapsScript(BpkMap);

export default () => (
  <BpkMapWithScript
    googleMapsApiKey='YOUR_API_KEY'
    zoom={15}
    center={{
      latitude: 27.9881,
      longitude: 86.925,
    }}
    showControls={false}
    panEnabled={false}
  />
);

Props

BpkMap

PropertyPropTypeRequiredDefault Value
boundsshape({north: number, east: number, south: number, west: number})falsenull
centershape({latitude: number, longitude: number})falsenull
classNamestringfalsenull
greedyGestureHandlingboolfalsefalse
mapOptionStylesarrayfalsenull
mapReffuncfalsenull
onRegionChangefuncfalsenull
onZoomfuncfalsenull
onTilesLoadedfuncfalsenull
panEnabledboolfalsetrue
showControlsboolfalsetrue
zoomnumberfalse15

Note: One of bounds and center must be provided.

withGoogleMapsScript

When using withGoogleMapsScript, some additional props are available:

PropertyPropTypeRequiredDefault Value
googleMapsApiKeystringtrue-
librariesarrayfalse'geometry', 'drawing', 'places'
loadingElementnodefalseBpkSpinner
preventGoogleFontsLoadingboolfalsefalse

BpkIconMarker

PropertyPropTypeRequiredDefault Value
iconnodetrue-
positionshape({latitude: number, longitude: number})true-
classNamestringfalsenull
disabledboolfalsefalse
onClickfuncfalsenull
selectedboolfalsefalse
buttonPropsobjectfalsenull

icon

BpkIconMarker only supports small icons from the Backpack icon set. Large icons should not be used with BpkIconMarker.

BpkPriceMarker

PropertyPropTypeRequiredDefault Value
labelstringtrue-
positionshape({latitude: number, longitude: number})true-
arrowClassNamestringfalsenull
classNamestringfalsenull
disabledboolfalsefalse
onClickfuncfalsenull
statusoneOf(PRICE_MARKER_STATUSES.default, PRICE_MARKER_STATUSES.focused, PRICE_MARKER_STATUSES.viewed)falsePRICE_MARKER_STATUSES.default
buttonPropsobjectfalsenull

BpkOverlayView

PropertyPropTypeRequiredDefault Value
childrennodetrue-
positionshape({latitude: number, longitude: number})true-

Theme Props

Icon markers:

  • iconMarkerDefaultBackgroundColor
  • iconMarkerDefaultSelectedColor
  • iconMarkerDefaultDisabledBackgroundColor
  • iconMarkerDefaultDisabledColor

Price markers:

  • priceMarkerBackgroundColor

  • priceMarkerSelectedBorderColor

  • priceMarkerSelectedColor

  • priceMarkerViewedBackgroundColor

  • priceMarkerViewedBorderColor
  • priceMarkerViewedColor
6.0.1

2 years ago

6.0.0

2 years ago

6.0.3

2 years ago

5.2.7

2 years ago

5.2.5

2 years ago

5.2.4

2 years ago

5.2.2

2 years ago

5.2.1

2 years ago

5.1.21

2 years ago

5.1.18

2 years ago

5.1.16

2 years ago

5.1.15

2 years ago

5.1.9

2 years ago

5.1.7

2 years ago

5.1.6

2 years ago

5.1.5

3 years ago

5.1.1

3 years ago

5.0.10

3 years ago

5.0.8

3 years ago

5.0.7

3 years ago

5.0.6

3 years ago

5.0.5

3 years ago

5.0.4

3 years ago

5.0.3

3 years ago

5.0.2

3 years ago

5.0.1

3 years ago

4.1.7

3 years ago

5.0.0

3 years ago

4.1.5

3 years ago

4.1.4

3 years ago

4.1.3

3 years ago

4.1.2

3 years ago

4.1.1

3 years ago

4.1.0

3 years ago

4.0.43

3 years ago

4.0.44

3 years ago

4.0.42

3 years ago

4.0.40

3 years ago

4.0.39

3 years ago

4.0.38

3 years ago

4.0.37

3 years ago

4.0.36

3 years ago

4.0.35

3 years ago

4.0.34

3 years ago

4.0.33

3 years ago

4.0.32

3 years ago

4.0.31

3 years ago

4.0.30

3 years ago

4.0.29

3 years ago

4.0.28

3 years ago

4.0.27

3 years ago

4.0.26

3 years ago

4.0.25

3 years ago

4.0.23

3 years ago

4.0.24

3 years ago

4.0.22

3 years ago

4.0.21

3 years ago

4.0.20

3 years ago

4.0.19

3 years ago

4.0.18

3 years ago

4.0.16

3 years ago

4.0.17

3 years ago

4.0.15

3 years ago

4.0.14

3 years ago

4.0.11

3 years ago

4.0.10

4 years ago

4.0.9

4 years ago

4.0.8

4 years ago

4.0.7

4 years ago

4.0.5

4 years ago

4.0.4

4 years ago

4.0.3

4 years ago

4.0.2

4 years ago

4.0.1

4 years ago

4.0.0

4 years ago

3.2.0

4 years ago

3.1.70

4 years ago

3.1.69

4 years ago

3.1.64

4 years ago

3.1.61

4 years ago

3.1.59

4 years ago

3.1.58

4 years ago

3.1.57

4 years ago

3.1.56

4 years ago