npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-mapbox

v1.0.0

Published

A set of lightweight, performant server-renderable React components for Mapbox.

Downloads

3

Readme

React Mapbox

npm Version Real Download Count (Very Real) Very Real Test Coverage

React Mapbox is a dead simple, performant, and easy to use React library for Mapbox. Other libraries either aim to cover the entire mapbox-gl-js API, or provide specific functionality for unique use cases.

We aim to give you a dead simple set of basic map components to work with, and if you end up needing more advanced functionality you can fork it and make your own.

React Mapbox and it's one dependency React Script only rely on React, so the library is extremely lightweight. The Mapbox library itself is dynamically injected when needed, so this package won't affect bundle size on views that don't need maps.

Example

import React, { PureComponent } from 'react';
import Mapbox, { Marker, ZoomControl } from 'react-mapbox';

class MapView extends PureComponent {
  this.state = {
    viewport: {
      center: {
        lat: 37.7577,
        lng: -122.4376,
      },
      zoom: 10,
    },
  };

  render () {
    return (
      <div className="map">
        <Mapbox
          mapbox={{
            accessToken: 'your-access-token',
            style: 'mapbox://styles/your-map-style',
          }}
          viewport={this.state.viewport}>
          <ZoomControl />
          <Marker
            lat={37.7577}
            lng={-122.4376}>
            <div className="marker">
              You are here!
            </div>
          </Marker>
        </Mapbox>
      </div>
    );
  }
};

React Mapbox supports several useful callbacks: onClick, onError, onLoad, onMoveEnd, onTouchEnd

onTouchEnd and onMoveEnd pass the new map position details as a parameter:

    {
      bearing: map.getBearing(),
      bounds: {
        northeast: {
          lat: bounds.getNorth(),
          lng: bounds.getEast(),
        },
        southwest: {
          lat: bounds.getSouth(),
          lng: bounds.getWest(),
        },
      },
      center: {
        lat: center.lat(),
        lng: center.lng(),
      },
      pitch: map.getPitch(),
      zoom: map.getZoom(),
    }

onLoad fires when the map is fully loaded. It's hooked into the load event within mapbox-gl-js, which means the style has loaded and the map has rendered for the first time.

Compatibility

React Mapbox exclusively works with React 16+ because it relies on the new Context API in React 16.

Installation

Yarn:

yarn add react-mapbox

npm:

npm install --save react-mapbox

Server Usage

React Script is handling the script loading, so you can setup a ScriptProvider and render your scripts from the server.

import React from 'react';
import { ScriptProvider } from 'react-script';

const scripts = [];
const markup = React.renderToString(
  <ScriptProvider injectScript={(script) => scripts.push(script)}>
    ...
  </ScriptProvider>
);

res.render('app', {
  markup,
  scripts,
});

You can view react-script documentation here.

Contributing to this project

We have no contibution guide, it's just anarchy live your life

License

MIT