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

sdk-mapbox-react

v0.1.3

Published

Mapbox wrapper for XYO

Downloads

7

Readme

Layer One Mapbox Wrapper

Install

Development

If running in development, please follow the README in the root package directory

Running stories

We use Storybook for visual testing. If you would like to do so, you will need a .env file in this directory with the following contents:

STORYBOOK_MAPBOX_API_TOKEN=[api-key]
PELIAS_ORIGIN=[pelias-origin]

You can also do something like STORYBOOK_MAPBOX_API_TOKEN=[api-key] yarn run storybook but that's a bit verbose.

Set STORYBOOK_MAPBOX_API_TOKEN to your MapBox API token, and Pelias Origin will be a URL to your Pelias server. See Pelias documentation to spin up your own.

Production

yarn add sdk-mapbox-react

Usage

Basic:

import React, { Component } from 'react'
import { Map } from 'sdk-mapbox-react'

const mapboxApiAccessToken = process.env.REACT_APP_MAPBOX_API_TOKEN

class MapPage extends Component {
  render() {
    return <Map mapboxApiAccessToken={mapboxApiAccessToken} />
  }
}

With QuadKey Tile Layers:

import { Map, TileLayer } from 'sdk-mapbox-react'
import {
  is,
  uniq,
  concat,
  symmetricDifference,
  __,
} from 'ramda'
// Note: ramda not necessary for using this library, just useful to use

const mapboxApiAccessToken = process.env.REACT_APP_MAPBOX_API_TOKEN

const isArray = is(Array)
const castArray = x => (isArray(x) ? x : [x])

class DeckGLTileMap extends Component {
  state = {
    selectedTiles: [],
  }

  selectTile = tileId => {
    const tileIds = castArray(tileId)
    this.setState(({ selectedTiles }) => ({
      selectedTiles: uniq(concat(selectedTiles, tileIds)),
    }))
  }

  deselectTile = tileId => {
    const tileIds = castArray(tileId)
    this.setState(({ selectedTiles }) => ({
      selectedTiles: symmetricDifference(selectedTiles, tileIds),
    }))
  }

  handleTileClick = ({ object }) => {
    const { selectedTiles } = this.state
    const { selected, quadKey } = object
    if (selected) {
      this.deselectTile(quadKey)
    } else {
      this.deselectTile(selectedTiles) // comment this out to enable single-click multi select
      this.selectTile(quadKey)
      const { lat, lng } = quadTools.origin(quadKey)
    }
  }

  render() {
    const { selectedTiles } = this.state

    return (
      <DeckGLMap mapboxApiAccessToken={mapboxApiAccessToken}>
        <TileLayer
          onClick={this.handleTileClick}
          selectTile={this.selectTile}
          selectedTiles={selectedTiles}
        />
      </DeckGLMap>
    )
  }
}

See DeckGLMap.stories.js for more examples, including usage of the experimental POI (points of interest) Layer.

API

* denotes deprecated API

Map

{
  /**
   * API Access token
   */
  mapboxApiAccessToken: string.isRequired,
  /**
  * Map Style, one of the following:
  * basic
  * streets
  * bright
  * light
  * dark
  * satellite
  * OR a regular mapbox style URL
  * Default: bright
  * Read more: https://www.mapbox.com/mapbox-gl-js/example/setstyle/
  */
  mapStyle: oneOf([
  'basic',
  'streets',
  'bright',
  'light',
  'dark',
  'satellite',
  ]),
  /**
   * Any Deck.GL Layers
   */
  children: any,
  /**
   * If true, drag select will be enabled. Default true.
   */
  dragSelect: bool,
  /**
   * If true, map will stretch to fit parent. Default false.
   */
  fitParent: bool,
  /**
   * viewport, optional. If provided, this will be a controlled component
   */
  viewport: shape({
    latitude: number,
    longitude: number,
    zoom: number,
    bearing: number,
    pitch: number,
    width: number,
    height: number,
  }),
  /**
   * viewport => void: update viewport
   */
  onViewportChange: func,
  /**
   * fill color of the drag-select rectangle. We use [Color](https://github.com/Qix-/color)
   * under the covers, so anything that it accepts as arguments is also accepted,
   * which includes Color objects themselves.
   */
  dragRectFillColor: oneOfType([object, string]),
  /**
   * stroke color of the drag-select rectangle. We use [Color](https://github.com/Qix-/color)
   * under the covers, so anything that it accepts as arguments is also accepted,
   * which includes Color objects themselves.
   */
  dragRectStrokeColor: oneOfType([object, string]),
}

Tile Layer

{
  /**
   * ID to identify the TileLayer.
   * Default: 'tile-layer'
   */
  id: string,
  /**
   * Function to get the fill color of the tile. Is called on each item in the data array.
   * Can also pass in a constant accessor, like '#FFF'.
   * Note: `getColor` turns any color into an rgba array and converts the a into percent
   * instead of decimal (i.e., 50 instead of 0.5 alpha)
   * Default: getColor(d.selected ? selectedFillColor : d.pendingSelection ? pendingSelectedFillColor: defaultFillColor)
   */
  getFillColor: oneOfType([string, func]),
  /**
   * Function to get the stroke/line color of the tile. Is called on each item in the data array.
   * Can also pass in a constant accessor, like '#FFF'.
   * Note: `getColor` turns any color into an rgba array and converts the a into percent
   * instead of decimal (i.e., 50 instead of 0.5 alpha)
   * Default: getColor(d.selected ? selectedStrokeColor : d.pendingSelection ? pendingSelectedStrokeColor: defaultStrokeColor)
   */
  getLineColor: oneOfType([string, func]),
  /**
   * function which handles tile click. Passed onto the Layer onClick prop, so
   * it will take the same functional arguments:
   * http://deck.gl/#/documentation/deckgl-api-reference/layers/layer?section=interaction-properties
   */
  onClick: func,
  /**
   * Array of selected tileIds
   */
  selectedTiles: arrayOf(string),
  /**
   * function which selects the tile or tiles
   * accepts a tileId, or an array of tileIds
   */
  selectTile: func,
  /**
   * fill color of an unselected tile. We use [Color](https://github.com/Qix-/color)
   * under the covers, so anything that it accepts as arguments is also accepted,
   * which includes Color objects themselves.
   * Default: Color('#00F').alpha(0.5)
   */
  defaultFillColor: oneOfType([object, string]),
  /**
   * stroke color of an unselected tile. We use [Color](https://github.com/Qix-/color)
   * under the covers, so anything that it accepts as arguments is also accepted,
   * which includes Color objects themselves.
   * Default: Color('#00F')
   */
  defaultStrokeColor: oneOfType([object, string]),
  /**
   * fill color of a selected tile. We use [Color](https://github.com/Qix-/color)
   * under the covers, so anything that it accepts as arguments is also accepted,
   * which includes Color objects themselves.
   * Default: Color('#0F0').alpha(0.5)
   */
  selectedFillColor: oneOfType([object, string]),
  /**
   * stroke color of a selected tile. We use [Color](https://github.com/Qix-/color)
   * under the covers, so anything that it accepts as arguments is also accepted,
   * which includes Color objects themselves.
   * Default: Color('#0F0')
   */
  selectedStrokeColor: oneOfType([object, string]),
  /**
   * fill color of a pending selected tile. We use [Color](https://github.com/Qix-/color)
   * under the covers, so anything that it accepts as arguments is also accepted,
   * which includes Color objects themselves.
   * Default: Color('#F00').alpha(0.5)
   */
  pendingSelectedFillColor: oneOfType([object, string]),
  /**
   * stroke color of a pending selected tile. We use [Color](https://github.com/Qix-/color)
   * under the covers, so anything that it accepts as arguments is also accepted,
   * which includes Color objects themselves.
   * Default: Color('#F00')
   */
  pendingSelectedStrokeColor: oneOfType([object, string]),
}

POILayer

Same PropTypes as TileLayer, except also needs the mapboxApiAccessToken and peliasOrigin.

Note regarding colors: We use Color under the covers, so anything that it accepts as arguments is also accepted, which includes Color objects themselves. 🤯

License

MIT © XYO, The Findables Company