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

mapbox-gl-rain-layer

v0.7.0

Published

Mapbox GL Rain Layer

Downloads

469

Readme

Mapbox GL JS Rain Layer

An animated rain layer for Mapbox GL JS

Screenshot

See a Live Demo.

The rain animation is up to date according to the current radar data from data sources. In addition to the density of raindrops, the colors of semi-transparent boxes indicate the intensity of rainfall.

Version 0.7 requires Mapbox GL JS 0.54.0 or later, and only works with the Mercator projection. This component works on browsers that support ES6. It supports the Mapbox Standard style but only works at zoom level 6 or above.

Installation

You can download the latest version of Mapbox GL JS Rain Layer from the GitHub releases.

To install via npm:

npm install mapbox-gl-rain-layer --save

To use CDN:

<script src="https://cdn.jsdelivr.net/npm/mapbox-gl-rain-layer@latest/dist/mapbox-gl-rain-layer.min.js"></script>

Usage

Mapbox GL JS Rain Layer can be used with ES6 modules, plain JavaScript and module loaders.

Mapbox GL JS Rain Layer requires Mapbox GL JS. Include Mapbox GL JS and Mapbox GL JS Rain Layer to your page, then you can use the RainLayer class, which can be added to your map as a layer.

const rainLayer = new RainLayer({
    id: 'rain',
    source: 'rainviewer',
    scale: 'noaa'
});
map.addLayer(rainLayer);

// You can get the HTML text for the legend
const legendHTML = rainLayer.getLegendHTML();

// You can receive radar data refresh events
// data.timestamp - Unix timestamp in seconds (UTC) when the data was generated
rainLayer.on('refresh', data => {
    console.log(data.timestamp);
});

Usage in ES6 as module

Import the module as RainLayer, and use it in the same way as described above.

import RainLayer from 'mapbox-gl-rain-layer';

Samples

You can find an interactive demo at nagix.github.io/mapbox-gl-rain-layer.

API

Constructor Options

RainLayer supports the following constructor options.

| Name | Type | Default | Description | ---- | ---- | ------- | ----------- | options.id | string | | A unique identifier that you define. | options.maxzoom | number | | The maximum zoom level for the layer. At zoom levels equal to or greater than the maxzoom, the layer will be hidden. The value can be any number between 0 and 24 (inclusive). If no maxzoom is provided, the layer will be visible at all zoom levels for which there are tiles available. | options.meshOpacity | number | 0.1 | The opacity of mesh boxes. The value can be any number between 0 and 1 (inclusive). | options.minzoom | number | | The minimum zoom level for the layer. At zoom levels less than the minzoom, the layer will be hidden. The value can be any number between 0 and 24 (inclusive). If no minzoom is provided, the layer will be visible at all zoom levels for which there are tiles available. | options.rainColor | string | '#ccf' | The color of raindrops. Colors are strings in a variety of permitted formats: HTML-style hex values, RGB, RGBA, HSL and HSLA. Predefined HTML colors names, like yellow and blue, are also permitted. The default is light blue. | options.slot | string | | (Optional) The identifier of a slot layer that will be used to position this layer. | options.snowColor | string | '#fff' | The color of snowflakes. Colors are strings in a variety of permitted formats: HTML-style hex values, RGB, RGBA, HSL and HSLA. Predefined HTML colors names, like yellow and blue, are also permitted. The default is white. | options.repaint | boolean | true | If true, rendering is automatically triggered for every frame. If false, Map#triggerRepaint() needs to be called explicitly. | options.scale | string | 'noaa' | The type of the color scale for the radar/precipitation data. Currently, only 'noaa' is supported. See Radar Images: Reflectivity by National Weather Service for details. | options.source | string | 'rainviewer' | The data source for the layer. Currently, only 'rainviewer' is supported.

Instance Members

getLegendHTML()

Returns the HTML text for the legend.

Returns

string: The HTML text for the legend.

off(type, listener)

Removes an event listener previously added with RainLayer#on.

Parameters

type (string) The event type previously used to install the listener.

listener (function) The function previously installed as a listener.

Returns

RainLayer: this

on(type, listener)

Adds a listener for events of a specified type.

Parameters

type (string) The event type to listen for.

listener (function) The function to be called when the event is fired.

Returns

RainLayer: this

once(type, listener)

Adds a listener that will be called only once to a specified event type.

Parameters

type (string) The event type to add a listener for.

listener (function) The function to be called when the event is fired.

Returns

RainLayer: this

setMeshOpacity(opacity)

Sets the opacity of mesh boxes.

Parameters

opacity (number) The opacity of mesh boxes. The value can be any number between 0 and 1 (inclusive).

Returns

RainLayer: this

setRainColor(color)

Sets the color of raindrops.

Parameters

color (string) The color of raindrops. Colors are strings in a variety of permitted formats: HTML-style hex values, RGB, RGBA, HSL and HSLA. Predefined HTML colors names, like yellow and blue, are also permitted.

Returns

RainLayer: this

setSnowColor(color)

Sets the color of snowflakes.

Parameters

color (string) The color of snowflakes. Colors are strings in a variety of permitted formats: HTML-style hex values, RGB, RGBA, HSL and HSLA. Predefined HTML colors names, like yellow and blue, are also permitted.

Returns

RainLayer: this

Events

refresh

Fired when the radar data is refreshed.

Properties

timestamp (number): Unix timestamp in seconds (UTC) when the data was generated

Building

You first need to install node dependencies (requires Node.js):

npm install

The following commands will then be available from the repository root:

npm run build    # build dist files
npm run lint     # perform code linting

About Data

The data for this visualization are sourced from RainViewer, which also gathers data from different data sources.

License

Mapbox GL JS Rain Layer is available under the MIT license.