Socket
Book a DemoInstallSign in
Socket

react-simple-maps

Package Overview
Dependencies
Maintainers
1
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-simple-maps

An svg map chart component built with and for React

3.0.0
latest
Source
npmnpm
Version published
Maintainers
1
Created

What is react-simple-maps?

react-simple-maps is a library for creating SVG maps in React applications. It provides a simple and flexible way to create interactive and customizable maps using React components.

What are react-simple-maps's main functionalities?

Creating a Basic Map

This code demonstrates how to create a basic world map using react-simple-maps. The `ComposableMap` component is the container for the map, and `Geographies` and `Geography` components are used to render the map's geographical features.

import React from 'react';
import { ComposableMap, Geographies, Geography } from 'react-simple-maps';

const BasicMap = () => (
  <ComposableMap>
    <Geographies geography="https://raw.githubusercontent.com/zcreativelabs/react-simple-maps/master/topojson-maps/world-110m.json">
      {({ geographies }) =>
        geographies.map(geo => (
          <Geography key={geo.rsmKey} geography={geo} />
        ))
      }
    </Geographies>
  </ComposableMap>
);

export default BasicMap;

Adding Interactivity

This code sample shows how to add interactivity to the map. The `onMouseEnter` and `onMouseLeave` events are used to log the name of the country when the mouse enters and leaves a geographical area.

import React from 'react';
import { ComposableMap, Geographies, Geography } from 'react-simple-maps';

const InteractiveMap = () => (
  <ComposableMap>
    <Geographies geography="https://raw.githubusercontent.com/zcreativelabs/react-simple-maps/master/topojson-maps/world-110m.json">
      {({ geographies }) =>
        geographies.map(geo => (
          <Geography
            key={geo.rsmKey}
            geography={geo}
            onMouseEnter={() => {
              const { NAME } = geo.properties;
              console.log(`Mouse entered: ${NAME}`);
            }}
            onMouseLeave={() => {
              console.log('Mouse left');
            }}
          />
        ))
      }
    </Geographies>
  </ComposableMap>
);

export default InteractiveMap;

Customizing Map Styles

This code demonstrates how to customize the styles of the map. The `style` prop is used to define different styles for the default, hover, and pressed states of the geographical areas.

import React from 'react';
import { ComposableMap, Geographies, Geography } from 'react-simple-maps';

const StyledMap = () => (
  <ComposableMap>
    <Geographies geography="https://raw.githubusercontent.com/zcreativelabs/react-simple-maps/master/topojson-maps/world-110m.json">
      {({ geographies }) =>
        geographies.map(geo => (
          <Geography
            key={geo.rsmKey}
            geography={geo}
            style={{
              default: { fill: '#D6D6DA', outline: 'none' },
              hover: { fill: '#F53', outline: 'none' },
              pressed: { fill: '#E42', outline: 'none' }
            }}
          />
        ))
      }
    </Geographies>
  </ComposableMap>
);

export default StyledMap;

Other packages similar to react-simple-maps

Keywords

react

FAQs

Package last updated on 25 Jul 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.