Code Monkey home page Code Monkey logo

react-mapbox-gl's Introduction

React-mapbox-gl Doc

Build Status npm version

London cycle example gif

React wrapper of mapbox-gl-js which bring the API to a react friendly way. On top of the layers provided, react-mapbox-gl add some React rendered layers, projected using map.project.

Include the following elements:

  • ReactMapboxGl
  • Layer
  • Source
  • Feature
    • Layer type properties symbol display a mapbox symbol.
    • Layer type properties line display a lineString.
    • Layer type properties fill display a polygon.
    • Layer type properties circle display a mapbox circle.
  • GeoJSONLayer
  • ZoomControl
  • ScaleControl
  • Marker (Projected component)
  • Popup (Projected component)
  • Cluster

The source files are written in Typescript, you can consume the compiled files in Javascript or Typescript and get the type definition files.

Do you need mapbox-gl-js and react-mapbox-gl

Mapbox-gl expose a map rendered in a canvas using WebGl which mean:

  • Vector tiles
  • Fast rendering
  • Smooth transitions
  • Data on the client side (interact with anything on the map)
  • Highly customizable using mapbox studio
  • Considerable bundle size

Details of all the features exposed: mapbox-gl-js

How to start

npm install react-mapbox-gl --save

Example:

// ES6
import ReactMapboxGl, { Layer, Feature } from "react-mapbox-gl";

// ES5
var ReactMapboxGl = require("react-mapbox-gl");
var Layer = ReactMapboxGl.Layer;
var Feature = ReactMapboxGl.Feature;

<ReactMapboxGl
  style="mapbox://styles/mapbox/streets-v8"
  accessToken="pk.eyJ1IjoiZmFicmljOCIsImEiOiJjaWc5aTV1ZzUwMDJwdzJrb2w0dXRmc2d0In0.p6GGlfyV-WksaDV_KdN27A"
  containerStyle={{
    height: "100vh",
    width: "100vw"
  }}>
    <Layer
      type="symbol"
      id="marker"
      layout={{ "icon-image": "marker-15" }}>
      <Feature coordinates={[-0.481747846041145, 51.3233379650232]}/>
    </Layer>
</ReactMapboxGl>

Disclaimer

The zoom property is an array on purpose. With a float as a value we can't tell whether the zoom has changed when checking for value equality 7 === 7 // true. We changed it to an array so that between 2 render it check for a reference equality [7] === [7] // false, this way we can reliably update the zoom value.

See alex3165#57 for more informations.

Examples

Run the examples

  • Clone the repository
  • Go to the example folder
  • Install the dependencies: npm install
  • Run the example
    • Build the library npm run build
    • Go to example folder cd example
    • Run example npm run start
    • Default port: 8080

Contribution

  • Ideally before posting an issue you can try to reproduce the bug you encounter using this boilerplate

react-mapbox-gl's People

Contributors

alex3165 avatar kitten avatar daniel5151 avatar kmamykin avatar sohibul avatar jluxenberg avatar arthur31416 avatar laznic avatar alcoheca avatar ideoma avatar daveschumaker avatar ericrwolfe avatar itjope avatar joshwcomeau avatar mtauer avatar bjorkstam avatar mollymerp avatar nbadag avatar rlski avatar tsemerad avatar z0d14c avatar 0x7b1 avatar

Stargazers

Roman avatar

Watchers

Ken 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.