3.2.1 • Published 5 years ago

react-places-map v3.2.1

Weekly downloads
4
License
MIT
Repository
github
Last release
5 years ago

React Places Map

Installation

Using npm

npm i react-places-map

Usage

import * as React from "react";
import * as Places from "react-places-map";

export class PlacesLayout extends React.Component {
    public render() {
        return (
            <Places.Controller
                apiKey="your api key"
                imagePath="/path/to/load/images"
                places={[
                    {
                        type: "placeType1",
                        getCoordinates: this.getCoordinates("placeType1"),
                    },
                    {
                        type: "placeType2",
                        getCoordinates: this.getCoordinates("placeType2"),
                    },
                ]}
            >
                <Places.SearchBox inputProps={{ placeholder: "Fill address" }} />
                <Places.Header type="placeType1">
                    Place type 1
                </Places.Header>
                <Places.Header type="placeType2">
                    Place type 2
                </Places.Header>
                <Places.Map />
            </Places.Controller>
        )
    }

    protected getCoordinates = (type: string) => () => {
        // You should return array of places (see Place interface)
        // You can load it asynchronously and return promise
        return {
            placeType1: [
                [50, 30],
                [50, 29],
                [51, 30],
            ],
            placeType2: [
                [61, 20],
                [51, 33],
                [53, 20]
            ],
        }[type];
    }
}

Places controller props

PropertyDescriptionRequired
apiKeyYour private api key to load google mapstrue
imagePathPath to access markers image (f.e. if you can access like http://domain/static/m1.png, you should return /static/mtrue
placesArray of Place values - coordinates of markerstrue

Search box props

PropertyDescriptionRequired
inputPropsCustom props to rendered inputfalse
classNamesObject with class names to children (root, input, autocompleteContainer)false

Header props

PropertyDescriptionRequired
typeSelected place type which markers will be showntrue

Contributors

License

MIT