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-mapboxgl/button-layer

v2.3.5

Published

ButtonLayer component for @react-mapboxgl

Downloads

7

Readme

@react-mapboxgl/button-layer

The ButtonLayer component encapsulates several styled layers pointing to the same source. These layers provide the typical UI required for 'interactive' features.

Props

  • id (required): The id for this layer.
  • property (required): The unique property to identify features.
  • source: The source (id or options).
  • sourceLayer: The source-layer (if relevant).
  • base: Options for the 'base' layer, the one that is always visible.
  • borders: Options for a borders layer (if relevant).
  • hover: Options for a hover layer (if relevant).
  • hoverBorder: Options for a hover-border layer (if relevant).
  • active: Options for an active layer (if relevant).
  • activeBorder: Options for an active border layer (if relevant).
  • activeProperty: The property value identifying the currently active feature (if one is active).

Example

An example usage. See it in action in the storybook.

/**
 * ButtonLayer - Example
 *
 * ## ButtonLayer Example - Interactive Polygons
 *
 * Uses the ButtonLayer 'meta component' to add polygons
 * with border, hover, and active states.
 *
 * Toggle any polygon to 'zoom' into/out of it.
 */
import React from 'react'
import bbox from '@turf/bbox'
import {MapboxProvider, MapGL} from '@react-mapboxgl/core'
import Toggle from '@react-mapboxgl/toggle'
import ButtonLayer from './'

const mapOptions = {
  style: 'mapbox://styles/mapbox/streets-v9',
  bbox: [[-123.881836, 25.063209], [-65.170898, 48.848451]],
  center: [-95.844727, 39.620499],
  zoom: 3,
  padding: 30,
  containerStyle: {
    position: 'fixed',
    top: 0,
    left: 0,
    right: 0,
    bottom: 0,
    zIndex: 1
  }
}

class Example extends React.Component {
  state = {
    activeName: null,
    bbox: mapOptions.bbox
  }

  constructor () {
    super()
    this.handleToggle = this.handleToggle.bind(this)
  }

  handleToggle (feature, isOn) {
    if (isOn) {
      this.setState({
        activeName: feature.properties.name,
        bbox: bbox(feature)
      })
    } else {
      this.setState({
        activeName: null,
        bbox: mapOptions.bbox
      })
    }
  }

  render () {
    return (
      <MapboxProvider accessToken='[your token]'>
        <MapGL {...mapOptions} bbox={this.state.bbox}>
          <ButtonLayer
            id='states'
            property='name'
            activeProperty={this.state.activeName}
            source={{
              id: 'states',
              type: 'geojson',
              data: 'https://d2ad6b4ur7yvpq.cloudfront.net/naturalearth-3.3.0/ne_110m_admin_1_states_provinces.geojson'
            }}
            base={{
              type: 'fill',
              paint: {
                'fill-color': '#627BC1',
                'fill-opacity': 0.5
              }
            }}
            borders={{
              type: 'line',
              paint: {
                'line-color': '#627BC1',
                'line-width': 2
              }
            }}
            hover={{
              type: 'fill',
              paint: {
                'fill-color': '#627BC1',
                'fill-opacity': 1
              }
            }}
            hoverBorder={{
              type: 'line',
              paint: {
                'line-color': '#425BA1',
                'line-width': 2
              }
            }}
            active={{
              type: 'fill',
              paint: {
                'fill-color': '#ff0e0e',
                'fill-opacity': 0.4
              }
            }}
            activeBorder={{
              type: 'line',
              paint: {
                'line-color': '#ff0e0e',
                'line-width': 2
              }
            }}
          />
          <Toggle
            layer='states'
            property='name'
            onToggle={this.handleToggle}
            avoidDoubleClick
          />
        </MapGL>
      </MapboxProvider>
    )
  }
}

export default Example

Developed by TerraEclipse

Terra Eclipse, Inc. is a nationally recognized political technology and strategy firm located in Santa Cruz, CA and Washington, D.C.