# the-map

> Geo map for the-components

Latest version **1.0.43** (published 2019-02-28) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install the-map
pnpm add the-map
yarn add the-map
bun add the-map
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.43 |
| Published | 2019-02-28 |
| First published | 2018-11-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=8 |
| Dependencies | 10 |
| Unpacked size | 285.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | okunishinishi |
| Maintainers | okunishinishi |
| Keywords | react-component, the |

## Links

- npm: https://www.npmjs.com/package/the-map
- Repository: https://github.com/the-labo/the-map
- Homepage: https://github.com/the-labo/the-map#readme
- Issues: https://github.com/the-labo/the-map/issues
- npm.io page: https://npm.io/package/the-map

## Dependencies (10)

- [leaflet](https://npm.io/package/leaflet.md) ^1.4.0
- [the-spin](https://npm.io/package/the-spin.md) ^3.1.12
- [the-style](https://npm.io/package/the-style.md) ^2.2.8
- [classnames](https://npm.io/package/classnames.md) ^2.2.6
- [prop-types](https://npm.io/package/prop-types.md) ^15.7.2
- [the-window](https://npm.io/package/the-window.md) ^7.0.3
- [formatcoords](https://npm.io/package/formatcoords.md) ^1.1.3
- [the-component-util](https://npm.io/package/the-component-util.md) ^3.0.22
- [the-component-constants](https://npm.io/package/the-component-constants.md) ^2.0.8
- [@okunishinishi/leaflet-shim](https://npm.io/package/@okunishinishi/leaflet-shim.md) ^1.0.2

## Alternatives

- [@pothos/plugin-authz](https://npm.io/package/@pothos/plugin-authz.md) — 12.4K weekly downloads
- [@bounded-sh/client](https://npm.io/package/@bounded-sh/client.md) — 3.2K weekly downloads
- [@luigi-project/plugin-auth-oauth2](https://npm.io/package/@luigi-project/plugin-auth-oauth2.md) — 2.3K weekly downloads
- [@nocobase/plugin-verification](https://npm.io/package/@nocobase/plugin-verification.md) — 2.0K weekly downloads
- [escher-request](https://npm.io/package/escher-request.md) — 545 weekly downloads

## Recent versions

- 1.0.43 (latest) — 2019-02-28
- 1.0.42 — 2019-02-28
- 1.0.41 — 2019-02-28
- 1.0.40 — 2019-02-28
- 1.0.39 — 2019-02-28
- 1.0.38 — 2019-02-28
- 1.0.37 — 2019-02-28
- 1.0.36 — 2019-02-27
- 1.0.35 — 2019-02-22
- 1.0.34 — 2019-02-15
- 1.0.33 — 2019-02-15
- 1.0.32 — 2019-02-15
- 1.0.31 — 2019-02-13
- 1.0.30 — 2019-02-08
- 1.0.29 — 2019-02-07
- … 29 more at https://npm.io/package/the-map/versions

## README

the-map
==========

<!---
This file is generated by the-tmpl. Do not update manually.
--->

<!-- Badge Start -->
<a name="badges"></a>

[![Build Status][bd_travis_shield_url]][bd_travis_url]
[![npm Version][bd_npm_shield_url]][bd_npm_url]
[![JS Standard][bd_standard_shield_url]][bd_standard_url]

[bd_repo_url]: https://github.com/the-labo/the-map
[bd_travis_url]: http://travis-ci.org/the-labo/the-map
[bd_travis_shield_url]: http://img.shields.io/travis/the-labo/the-map.svg?style=flat
[bd_travis_com_url]: http://travis-ci.com/the-labo/the-map
[bd_travis_com_shield_url]: https://api.travis-ci.com/the-labo/the-map.svg?token=
[bd_license_url]: https://github.com/the-labo/the-map/blob/master/LICENSE
[bd_npm_url]: http://www.npmjs.org/package/the-map
[bd_npm_shield_url]: http://img.shields.io/npm/v/the-map.svg?style=flat
[bd_standard_url]: http://standardjs.com/
[bd_standard_shield_url]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg

<!-- Badge End -->


<!-- Description Start -->
<a name="description"></a>

Geo map for the-components

<!-- Description End -->


<!-- Overview Start -->
<a name="overview"></a>



<!-- Overview End -->


<!-- Sections Start -->
<a name="sections"></a>

<!-- Section from "doc/guides/01.Installation.md.hbs" Start -->

<a name="section-doc-guides-01-installation-md"></a>

Installation
-----

```bash
$ npm install the-map --save
```


<!-- Section from "doc/guides/01.Installation.md.hbs" End -->

<!-- Section from "doc/guides/02.Usage.md.hbs" Start -->

<a name="section-doc-guides-02-usage-md"></a>

Usage
---------

```javascript
'use strict'

import React from 'react'
import { TheMap, TheMapStyle, TheMapPositionInput } from 'the-map'
import { TheSpinStyle } from 'the-spin'

// @see https://leaflet-extras.github.io/leaflet-providers/preview/
const MapLayers = [
  {
    key: 'layer01',
    title: 'Layer 01',
    url: 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
    maxZoom: 19,
    attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
  },
  {
    key: 'layer02',
    title: 'Layer 02',
    url: 'http://{s}.tiles.wmflabs.org/bw-mapnik/{z}/{x}/{y}.png',
    maxZoom: 18,
    attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
  },
]

class ExampleComponent extends React.Component {
  handleLeafletMap = (map) => {
    this.map = map
  }
  handleChange = ({ lat, lng, zoom, bounds: { west, south, east, north } }) => {
    this.setState({ lat, lng, zoom })
    console.log('bounds changed', { west, south, east, north })
  }
  handleUpdate = ({ pos01 }) => {
    const { lat, lng, zoom } = pos01
    this.setState({
      post01: { lat, lng, zoom },
    })
  }

  moveToCurrent = () => {
    navigator.geolocation.getCurrentPosition(({ coords }) => {
      const { latitude: lat, longitude: lng } = coords
      this.setState({ lat, lng })
    }, () => alert('Failed to get current position'))
  }

  setMarker(key, values) {
    const { markers } = this.state
    this.setState({
      markers: [
        ...markers.filter((m) => m.key !== key),
        { key, ...values }
      ]
    })
  }

  getMarker(key) {
    return this.state.markers.find((m) => m.key === key)
  }

  handleClick = ({ lat, lng }) => {
    const { markers } = this.state
    console.log('Map clicked', { lat, lng })
    let name = `m${String(markers.length + 1).padStart(2, '0')}`
    let markerValues = {
      lat,
      lng,
      onClick: () => console.log('node clicked', name),
      node: (
        <div style={{
          borderRadius: '50%',
          textAlign: 'center',
          background: '#EE1',
          width: 22,
          height: 22,
          color: 'white',
          lineHeight: '22px',
        }}>
          <div>{name}</div>
        </div>
      ),
    }
    this.setMarker(name, markerValues)

    setInterval(() => {
      const marker = this.getMarker(name)
      const lng = marker.lng + 0.001
      const lat = marker.lat + 0.001
      this.setMarker(name, {
        ...marker,
        lat,
        lng,
      })
      console.log('Marker moved', name, { lat, lng })
    }, 1000)
  }

  state = {
    lat: 35.6895,
    lng: 139.6917,
    zoom: 13,
    markers: [
      {
        key: 'marker-01',
        lat: 51.505,
        lng: -0.09,
        onClick: () => console.log('marker01 clicked'),
        node: (
          <div style={{
            borderRadius: '50%',
            textAlign: 'center',
            background: '#E33',
            width: 48,
            height: 48,
            color: 'white',
            lineHeight: '48px',
          }}>
            <div>Mrkr01</div>
          </div>
        ),
      }
    ],
    popups: [
      {
        key: 'popup-01',
        for: 'marker-01',
        node: (
          <div>This is popup01 for marker01</div>
        )
      }
    ]
  }

  render() {
    const { state: { lat, lng, zoom, markers, post01 } } = this
    return (
      <div>
        <TheSpinStyle />
        <TheMapStyle />
        <TheMap onLeafletMap={this.handleLeafletMap}
                onChange={this.handleChange}
                {...{ lat, lng, zoom }}
                width={'480px'}
                height={'50vh'}
                layers={MapLayers}
                onClick={this.handleClick}
                markers={markers}
        >
        </TheMap>

        <hr />

        <button
          onClick={this.moveToCurrent}>Move to current
        </button>


        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <hr />
        <section>
          <h1>As Input</h1>
          <TheMapPositionInput value={post01}
                               name={'pos01'}
                               onUpdate={this.handleUpdate}
          />
        </section>
      </div>

    )
  }
}

export default ExampleComponent

```


<!-- Section from "doc/guides/02.Usage.md.hbs" End -->

<!-- Section from "doc/guides/03.Components.md.hbs" Start -->

<a name="section-doc-guides-03-components-md"></a>

Components
-----------

### TheMap

Geo map for the-components

**Props**

| Name | Type | Description | Default |
| --- | --- | ---- | ---- |
| `freezed` | bool  | Disable all interactions | `false` |
| `height` | union  | Height of map | `null` |
| `lat` | number  | latitude value | `` |
| `lng` | number  | longitude value | `` |
| `onLeafletMap` | func  | Callback when map map created | `null` |
| `spinning` | bool  | Shows spinner | `false` |
| `width` | union  | Width of map | `null` |
| `layerControlEnabled` |   |  | `true` |
| `layerControlPosition` |   |  | `'topright'` |
| `layers` |   |  | `[
  {
    attribution:
      '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
    key: 'default',
    maxZoom: 19,
    url: 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
  },
]` |
| `markers` |   |  | `[]` |
| `zoomControlEnabled` |   |  | `true` |
| `zoomControlPosition` |   |  | `'topleft'` |

### TheMapMarker




### TheMapPositionInput



**Props**

| Name | Type | Description | Default |
| --- | --- | ---- | ---- |
| `id` | string  |  | `` |
| `name` | string  |  | `` |
| `value` | union  |  | `{ lat: 35.6895, lng: 139.6917, zoom: 13 }` |
| `height` |   |  | `150` |
| `layers` |   |  | `TheMap.defaultProps.layers || []` |
| `width` |   |  | `300` |



<!-- Section from "doc/guides/03.Components.md.hbs" End -->


<!-- Sections Start -->


<!-- LICENSE Start -->
<a name="license"></a>

License
-------
This software is released under the [MIT License](https://github.com/the-labo/the-map/blob/master/LICENSE).

<!-- LICENSE End -->


<!-- Links Start -->
<a name="links"></a>

Links
------

+ [THE Labo][t_h_e_labo_url]

[t_h_e_labo_url]: https://github.com/the-labo

<!-- Links End -->

---
_Source: https://npm.io/package/the-map · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
