0.1.47 β€’ Published 11 months ago

@ixnode/geo-sphere v0.1.47

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

@ixnode/geo-sphere

Release Release date npm version TypeScript React Storybook MIT License

@ixnode/geo-sphere is a powerful and flexible Node.js package for rendering interactive maps. It supports various projections (currently only Mercator projection - more are planned), languages, and advanced interactivity, allowing you to display geographical points and create a fully interactive mapping experience.

πŸš€ Features

  • Map Display: Render world maps or other geographical maps in Mercator projection.
  • Point Rendering: Display geographical points using latitude and longitude.
  • Resizable: Dynamically adjust the map size to fit different screen dimensions.
  • Integrated Country Database: Includes all countries with multiple resolution levels by default.
  • Interactive Countries: Countries can be clicked, triggering a customizable callback function. Hover and title effects are also supported.
  • Multi-language Support: Available in multiple languages: cz|de|en|es|fr|hr|it|pl|sv.
  • Mouse and Touch Interaction: The map supports zooming and panning via mouse and touch gestures.
  • Lightweight and built with TypeScript
  • Build on top with storybook

πŸ“¦ Installation

npm install @ixnode/geo-sphere

or

yarn add @ixnode/geo-sphere

πŸ”§ Usage

Display example

Example: France is selected, but the mouse is hovering over Berlin, Germany.

Basic world.

Example: The United States are selected. The city Austin was clicked.

Basic world.

Basic Usage

import React from 'react';
import { WorldMap } from '@ixnode/geo-sphere';
import '@ixnode/geo-sphere/dist/styles.css';

const App = () => (
    <WorldMap
        height={500}
        width={1000}
        country="de"
        language="en"
    />
);

export default App;

Usage with country callback function

import React from 'react';
import { WorldMap, CountryData } from '@ixnode/geo-sphere';
import '@ixnode/geo-sphere/dist/styles.css';

const App = () => (
    <WorldMap
        height={500}
        width={1000}
        country="de"
        language="en"
        dataSource="medium"
        onClickCountry={(data: CountryData) => { console.log(data); }}
    />
);

export default App;

The callback function logs something like (according to the clicked country and the given language):

{
    "id": "de",
    "name": "Germany",
    "latitude": 50.304018990688554,
    "longitude": 7.5794992771470975,
    "screenPosition": {
        "x": 401,
        "y": 333
    },
    "svgPosition": {
        "x": 843746,
        "y": 6499094
    }
}
PropertyDescription
idThe id of clicked element.
nameThe translated name of clicked element.
latitudeThe latitude value. Clicked on the map.
longitudeThe longitude value. Clicked on the map.
screenPosition.xThe x position of the last click. Related to the screen.
screenPosition.yThe y position of the last click. Related to the screen.
svgPosition.xThe x position of the last click. Related to the whole svg map.
svgPosition.yThe x position of the last click. Related to the whole svg map.

Usage with place callback function

import React from 'react';
import { WorldMap, PlaceData } from '@ixnode/geo-sphere';
import '@ixnode/geo-sphere/dist/styles.css';

const App = () => (
    <WorldMap
        height={500}
        width={1000}
        country="de"
        language="en"
        dataSource="medium"
        onClickPlace={(data: PlaceData) => { console.log(data); }}
    />
);

export default App;

The callback function logs something like (according to the clicked place and the given language):

{
    "id": "place-berlin",
    "latitude": 52.5235,
    "longitude": 13.4115,
    "name": "Berlin",
    "population": 3662381, 
    "country": {
        "id": "de",
        "name": "Germany"
    },
    "state": {
        "id": "de-be",
        "name": "Berlin",
        "area": 891.1,
        "population": 3662381
    },
    "screenPosition": {
        "x": 629,
        "y": 295 
    },
    "svgPosition": {
        "x": 1580.7000732421875,
        "y": 6909.73095703125
    }
}
PropertyDescription
idThe id of clicked element.
nameThe translated name of clicked element.
populationThe population of clicked element.
latitudeThe latitude value. Clicked on the map.
longitudeThe longitude value. Clicked on the map.
screenPosition.xThe x position of the last click. Related to the screen.
screenPosition.yThe y position of the last click. Related to the screen.
svgPosition.xThe x position of the last click. Related to the whole svg map.
svgPosition.yThe x position of the last click. Related to the whole svg map.

πŸ”§ Properties

PropertyTypeDefaultDescription
dataSource'tiny'\|'low'\|'medium''low'The data source to be used.
countrystring\|nullnullThe country that is marked.
widthnumber1000The width of the map in pixels. Only used for ratio. The svg is always 100% of parent element.
heightnumber500The height of the map in pixels. Only used for ratio. The svg is always 100% of parent element.
language'cz'|'de'|'en'|'es'|'fr'|'hr'|'it'|'pl'|'sv''en'The language to be used.
onClickCountry(data: CountryData) => void\|nullnullAn optional country click handler.
onClickPlace(data: PlaceData) => void\|nullnullAn optional place click handler.
onHoverCountry(data: CountryData) => void\|nullnullAn optional country hover handler.
onHoverPlace(data: PlaceData) => void\|nullnullAn optional place hover handler.
debugbooleanfalseFlag to enable or disable the debug mode.
logobooleantrueFlag to enable or disable the logo.

Common countries (country)

Use ISO 3166-1 alpha-2 code to select a country. Examples:

CountryISO code
United Kingdom of Great Britain and Northern Irelandgb
United States of Americaus
Germanyde
Swedense
etc.

See https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 for more information.

Common languages (language)

Currently supported languages:

LanguageDescription
czCzech
deGerman
enEnglish
esSpanish
frFrench
hrCroatian
itItalian
plPolish
svSwedish

πŸ›  Development

Building the Project

To build the project locally:

npm run build

Running Storybook

View and develop components in isolation:

npm run storybook

Open: http://localhost:6006/

Example: The country Portugal and language spanisch is selected, but the mouse is hovering over Madrid, Spain.

Storybook

πŸ“¦ Publishing to npm

Check TypeScript Code

  • Runs the TypeScript compiler to detect errors without generating any JavaScript output
  • Should not throw an error
npx tsc --noEmit

Build the project

  • Runs the build process to produce production-ready artifacts
  • Test build for a future release process to npmjs.org
  • Should not throw an error
npm run build

Verify the build

  • Checks that the compiled code runs as expected
  • Should not throw an error

ES Modules build

node dist/index.js

or to ignore possible warnings:

node --no-warnings dist/index.js

CommonJS build

node dist/index.cjs

Bump the version

Update the version in the package.json, e.g., from 1.0.0 to 1.0.1, to create a new release:

npm version patch

Alternatively:

  • Use npm version minor for new features.
  • Use npm version major for breaking changes.

Publish the package

npm publish --access public

Verify the publication

Check the package on npm: https://www.npmjs.com/package/@ixnode/geo-sphere.

πŸ“„ License

This project is licensed under the MIT License. See the LICENSE file for details.

Authors

🌟 Contributing

Contributions are welcome! Feel free to submit issues or pull requests to improve this project.

🀝 Acknowledgments

Special thanks to the open-source community for providing amazing tools like React, TypeScript, and Storybook.

0.1.47

11 months ago

0.1.46

11 months ago

0.1.45

11 months ago

0.1.44

11 months ago

0.1.43

11 months ago

0.1.42

11 months ago

0.1.41

11 months ago

0.1.40

11 months ago

0.1.39

11 months ago

0.1.38

11 months ago

0.1.37

11 months ago

0.1.36

11 months ago

0.1.35

11 months ago

0.1.34

11 months ago

0.1.33

11 months ago

0.1.32

11 months ago

0.1.31

11 months ago

0.1.30

11 months ago

0.1.29

11 months ago

0.1.28

11 months ago

0.1.27

11 months ago

0.1.26

11 months ago

0.1.25

11 months ago

0.1.24

11 months ago

0.1.23

11 months ago

0.1.22

11 months ago

0.1.21

11 months ago

0.1.20

11 months ago

0.1.19

11 months ago

0.1.18

12 months ago

0.1.17

12 months ago

0.1.16

12 months ago

0.1.15

12 months ago

0.1.14

12 months ago

0.1.13

12 months ago

0.1.12

12 months ago

0.1.11

12 months ago

0.1.10

12 months ago

0.1.9

12 months ago

0.1.8

12 months ago

0.1.7

12 months ago

0.1.6

12 months ago

0.1.5

12 months ago

0.1.4

12 months ago