# render-cities-to-custom-map

> # Render cities to custom map

Latest version **1.0.1** (published 2023-12-03) · 0 weekly downloads

## Install

```sh
npm install render-cities-to-custom-map
pnpm add render-cities-to-custom-map
yarn add render-cities-to-custom-map
bun add render-cities-to-custom-map
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2023-12-03 |
| First published | 2023-12-01 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 53.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | mirja-t |

## Links

- npm: https://www.npmjs.com/package/render-cities-to-custom-map
- Repository: https://github.com/mirja-t/render-cities-to-custom-map
- Homepage: https://github.com/mirja-t/render-cities-to-custom-map#readme
- Issues: https://github.com/mirja-t/render-cities-to-custom-map/issues
- npm.io page: https://npm.io/package/render-cities-to-custom-map

## Recent versions

- 1.0.1 (latest) — 2023-12-03
- 1.0.0 — 2023-12-01

## README

### React Component

# Render cities to custom map 

This component displays a custom svg map and renders a given list of cities to the map by their latitude and longitude props. As many cities as possible, sorted by size, are rendered to the map as long as their names don't overlap. If zoomed in, more cities are displayed on the map.

## Demo

[render-cities-to-custom-map.mirja-t.de](http://render-cities-to-custom-map.mirja-t.de)


## Installation

#### As npm package

```sh
npm i render-cities-to-custom-map
```

## How to use

#### Basic usage

A custom map prop is required. `mapComponent` needs to be passed as a function with a React component containing the custom map as return value.

```
import SvgMapCities from "render-cities-to-custom-map"
import CustomMap from "./CustomMap"

function App() {
  return (
    <SvgMapCities 
      mapdata={mapdata}
      mapComponent={() => <GermanyMap/>}/>
    )
}
```

#### Data structure
```
import { MapData } from "render-cities-to-custom-map";

export const mapdata: MapData = {
    name: "germany",
    bounds: {
        north: 55.0582645 // latitude of the northernnmost point of the map 
        east: 15.04193, // longitude of the easternmost point of the map 
        south: 47.271679, // latitude of the southernmost point of the map 
        west: 5.866944, // longitude of the westernmost point of the map 
    },
    cities: [
        {
            id: "berlin",
            name: "Berlin",
            lat: 52.51777021534373,
            lon: 13.405460226934554,
            inhabitants: 3755251
        },
        {
            id: "hamburg",
            name: "Hamburg",
            lat: 53.550556,
            lon: 9.993333,
            inhabitants: 1830000
        },
        ...
    ]
}
```

#### Optional:

+ zoom: number, defaults to 1
+ baseFontSize: number, font size of largest cities, defaults to 14 
+ color: string, color of city names and related dots, defaults to "black"
+ fontFamily: string, defaults to "Arial, sans-serif"

```
import SvgMapCities from "render-cities-to-custom-map"
import CustomMap from "./CustomMap"

const config = {
  baseFontSize: 18,
  color: '#CCC'
}

function App() {
  const [zoom, setZoom] = useState(1)
  return (<>
    <SvgMapCities 
      zoom={zoom}
      mapdata={mapdata}
      mapComponent={(zoom) => <CustomMap zoom={zoom}/>}
      {...config}/>
    <input style={{ position: 'fixed', bottom: 5, left: 5, zIndex: 3 }} type="number" value={zoom} onChange={(e) => { setZoom(Number(e.target.value)) }} />
  </>)
}
```

License: [MIT](./LICENSE.md)

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