Giter Site home page Giter Site logo

jaslife1 / react-simple-maps Goto Github PK

View Code? Open in Web Editor NEW

This project forked from zcreativelabs/react-simple-maps

0.0 0.0 0.0 3.06 MB

Beautiful React SVG maps with d3-geo and topojson using a declarative api.

Home Page: https://www.react-simple-maps.io/

License: MIT License

JavaScript 100.00%

react-simple-maps's Introduction

react-simple-maps

Create beautiful SVG maps in react with d3-geo and topojson using a declarative api.

Read the docs, or check out the examples.

Why

React-simple-maps aims to make working with svg maps in react easier. It handles tasks such as panning, zooming and simple rendering optimization, and takes advantage of parts of d3-geo and topojson-client instead of relying on the entire d3 library.

Since react-simple-maps leaves DOM work to react, it can also easily be used with other libraries, such as react-spring and react-annotation.

Install

To install react-simple-maps

$ npm install --save react-simple-maps@beta

...or if you use yarn:

$ yarn add react-simple-maps@beta

Usage

React-simple-maps exposes a set of components that can be combined to create svg maps with markers and annotations. In order to render a map you have to provide a reference to a valid topojson file. You can find example topojson files in the topojson-maps folder or on topojson world-atlas. To learn how to make your own topojson maps from shapefiles, please read "How to convert and prepare TopoJSON files for interactive mapping with d3" on medium.

import React from "react"
import ReactDOM from "react-dom"
import {
  ComposableMap,
  Geographies,
  Geography,
} from "react-simple-maps"

// url to a valid topojson file
const geoUrl =
  "https://raw.githubusercontent.com/zcreativelabs/react-simple-maps/master/topojson-maps/world-110m.json"

const App = () => {
  return (
    <div>
      <ComposableMap>
        <Geographies geography={geoUrl}>
          {({geographies}) => geographies.map(geo =>
            <Geography key={geo.rsmKey} geography={geo} />
          )}
        </Geographies>
      </ComposableMap>
    </div>
  )
}

document.addEventListener("DOMContentLoaded", () => {
  ReactDOM.render(<App />, document.getElementById("app"))
})

Check out the live example

The above will render a world map using the equal earth projection. You can read more about this projection on Shaded Relief and on Wikipedia.

For other examples and components, check out the documentation.

License

MIT licensed. Copyright (c) Richard Zimerman 2017. See LICENSE.md for more details.

react-simple-maps's People

Contributors

abemedia avatar alexlukelevy avatar erabhimanyu avatar ericmcornelius avatar glennsl avatar henrymunro avatar j8seangel avatar jamestthompson3 avatar kevinahuber avatar mekanics avatar pronebird avatar sorodrigo avatar stevenliuyi avatar thepocp avatar walidvb avatar zimrick avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.