├── .eslintrc
├── .gitignore
├── LICENSE
├── README.md
├── docs
├── index.html
├── rain-layer.css
├── rain-layer.json
└── screenshot1.jpg
├── package.json
├── rollup.config.mjs
└── src
├── index.js
├── scales.json
└── sources.json
/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "extends": [
3 | "mourner",
4 | "plugin:import/recommended"
5 | ],
6 | "parserOptions": {
7 | "sourceType": "module"
8 | },
9 | "plugins": [
10 | "import",
11 | "jsdoc"
12 | ],
13 | "rules": {
14 | // temporarily disabled due to https://github.com/babel/babel-eslint/issues/485
15 | "no-use-before-define": "off",
16 |
17 | // no-duplicate-imports doesn't play well with Flow
18 | // https://github.com/babel/eslint-plugin-babel/issues/59
19 | "no-duplicate-imports": "off",
20 | "import/no-duplicates": "error",
21 |
22 | // temporarily disabled for easier upgrading of dependencies
23 | "implicit-arrow-linebreak": "off",
24 | "arrow-parens": "off",
25 | "arrow-body-style": "off",
26 | "no-confusing-arrow": "off",
27 | "no-control-regex": "off",
28 | "no-invalid-this": "off",
29 | "no-buffer-constructor": "off",
30 |
31 | "array-bracket-spacing": "off",
32 | "consistent-return": "off",
33 | "global-require": "off",
34 | "import/no-commonjs": "error",
35 | "key-spacing": "off",
36 | "no-eq-null": "off",
37 | "no-lonely-if": "off",
38 | "no-new": "off",
39 | "no-unused-vars": ["error", {"argsIgnorePattern": "^_$"}],
40 | "no-warning-comments": "error",
41 | "object-curly-spacing": ["error", "never"],
42 | "prefer-arrow-callback": "error",
43 | "prefer-const": ["error", {"destructuring": "all"}],
44 | "prefer-template": "error",
45 | "quotes": "off",
46 | "space-before-function-paren": "off",
47 | "template-curly-spacing": "error",
48 | "no-useless-escape": "off",
49 | "indent": ["error", 4, {
50 | "flatTernaryExpressions": true,
51 | "CallExpression": {
52 | "arguments": "off"
53 | },
54 | "FunctionDeclaration": {
55 | "parameters": "off"
56 | },
57 | "FunctionExpression": {
58 | "parameters": "off"
59 | }
60 | }],
61 | "no-multiple-empty-lines": [ "error", {
62 | "max": 1
63 | }],
64 | "jsdoc/check-param-names": "warn",
65 | "jsdoc/require-param": "warn",
66 | "jsdoc/require-param-description": "warn",
67 | "jsdoc/require-param-name": "warn",
68 | "jsdoc/require-returns": "warn",
69 | "jsdoc/require-returns-description": "warn"
70 | },
71 | "settings": {
72 | "jsdoc":{
73 | "ignorePrivate": true
74 | }
75 | },
76 | "ignorePatterns": [],
77 | "globals": {
78 | "performance": true
79 | },
80 | "env": {
81 | "es6": true,
82 | "browser": true
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /dist
2 | /node_modules
3 | /package-lock.json
4 | .DS_Store
5 | .eslintcache
6 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2021-2024 Akihiko Kusanagi
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6 |
7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8 |
9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Mapbox GL JS Rain Layer
2 |
3 | *An animated rain layer for [Mapbox GL JS](https://github.com/mapbox/mapbox-gl-js)*
4 |
5 | 
6 |
7 | See a [Live Demo](https://nagix.github.io/mapbox-gl-rain-layer).
8 |
9 | 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.
10 |
11 | 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](https://caniuse.com/es6). It supports the Mapbox Standard style but only works at zoom level 6 or above.
12 |
13 | ## Installation
14 |
15 | You can download the latest version of Mapbox GL JS Rain Layer from the [GitHub releases](https://github.com/nagix/mapbox-gl-rain-layer/releases/latest).
16 |
17 | To install via npm:
18 |
19 | ```bash
20 | npm install mapbox-gl-rain-layer --save
21 | ```
22 |
23 | To use CDN:
24 |
25 | ```html
26 |
27 | ```
28 |
29 | ## Usage
30 |
31 | Mapbox GL JS Rain Layer can be used with ES6 modules, plain JavaScript and module loaders.
32 |
33 | Mapbox GL JS Rain Layer requires [Mapbox GL JS](https://github.com/mapbox/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.
34 |
35 | ```js
36 | const rainLayer = new RainLayer({
37 | id: 'rain',
38 | source: 'rainviewer',
39 | scale: 'noaa'
40 | });
41 | map.addLayer(rainLayer);
42 |
43 | // You can get the HTML text for the legend
44 | const legendHTML = rainLayer.getLegendHTML();
45 |
46 | // You can receive radar data refresh events
47 | // data.timestamp - Unix timestamp in seconds (UTC) when the data was generated
48 | rainLayer.on('refresh', data => {
49 | console.log(data.timestamp);
50 | });
51 | ```
52 |
53 | ### Usage in ES6 as module
54 |
55 | Import the module as `RainLayer`, and use it in the same way as described above.
56 |
57 | ```js
58 | import RainLayer from 'mapbox-gl-rain-layer';
59 | ```
60 |
61 | ## Samples
62 |
63 | You can find an interactive demo at [nagix.github.io/mapbox-gl-rain-layer](https://nagix.github.io/mapbox-gl-rain-layer).
64 |
65 | ## API
66 |
67 | ### Constructor Options
68 |
69 | `RainLayer` supports the following constructor options.
70 |
71 | | Name | Type | Default | Description
72 | | ---- | ---- | ------- | -----------
73 | | **`options.id`** | `string` | | A unique identifier that you define.
74 | | **`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.
75 | | **`options.meshOpacity`** | `number` | `0.1` | The opacity of mesh boxes. The value can be any number between `0` and `1` (inclusive).
76 | | **`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.
77 | | **`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.
78 | | **`options.slot`** | `string` | | (Optional) The identifier of a slot layer that will be used to position this layer.
79 | | **`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.
80 | | **`options.repaint`** | `boolean` | `true` | If true, rendering is automatically triggered for every frame. If false, `Map#triggerRepaint()` needs to be called explicitly.
81 | | **`options.scale`** | `string` | `'noaa'` | The type of the color scale for the radar/precipitation data. Currently, only `'noaa'` is supported. See [Radar Images: Reflectivity](https://www.weather.gov/jetstream/refl) by National Weather Service for details.
82 | | **`options.source`** | `string` | `'rainviewer'` | The data source for the layer. Currently, only `'rainviewer'` is supported.
83 |
84 | ### Instance Members
85 |
86 | #### **`getLegendHTML()`**
87 |
88 | Returns the HTML text for the legend.
89 |
90 | ##### Returns
91 |
92 | `string`: The HTML text for the legend.
93 |
94 | #### **`off(type, listener)`**
95 |
96 | Removes an event listener previously added with `RainLayer#on`.
97 |
98 | ##### Parameters
99 |
100 | **`type`** (string) The event type previously used to install the listener.
101 |
102 | **`listener`** (function) The function previously installed as a listener.
103 |
104 | ##### Returns
105 |
106 | `RainLayer`: `this`
107 |
108 | #### **`on(type, listener)`**
109 |
110 | Adds a listener for events of a specified type.
111 |
112 | ##### Parameters
113 |
114 | **`type`** (`string`) The event type to listen for.
115 |
116 | **`listener`** (`function`) The function to be called when the event is fired.
117 |
118 | ##### Returns
119 |
120 | `RainLayer`: `this`
121 |
122 | #### **`once(type, listener)`**
123 |
124 | Adds a listener that will be called only once to a specified event type.
125 |
126 | ##### Parameters
127 |
128 | **`type`** (`string`) The event type to add a listener for.
129 |
130 | **`listener`** (`function`) The function to be called when the event is fired.
131 |
132 | ##### Returns
133 |
134 | `RainLayer`: `this`
135 |
136 | #### **`setMeshOpacity(opacity)`**
137 |
138 | Sets the opacity of mesh boxes.
139 |
140 | ##### Parameters
141 |
142 | **`opacity`** (`number`) The opacity of mesh boxes. The value can be any number between `0` and `1` (inclusive).
143 |
144 | ##### Returns
145 |
146 | `RainLayer`: `this`
147 |
148 | #### **`setRainColor(color)`**
149 |
150 | Sets the color of raindrops.
151 |
152 | ##### Parameters
153 |
154 | **`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.
155 |
156 | ##### Returns
157 |
158 | `RainLayer`: `this`
159 |
160 | #### **`setSnowColor(color)`**
161 |
162 | Sets the color of snowflakes.
163 |
164 | ##### Parameters
165 |
166 | **`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.
167 |
168 | ##### Returns
169 |
170 | `RainLayer`: `this`
171 |
172 | ### Events
173 |
174 | #### **`refresh`**
175 |
176 | Fired when the radar data is refreshed.
177 |
178 | ##### Properties
179 |
180 | **`timestamp`** (`number`): Unix timestamp in seconds (UTC) when the data was generated
181 |
182 | ## Building
183 |
184 | You first need to install node dependencies (requires [Node.js](https://nodejs.org/)):
185 |
186 | ```bash
187 | npm install
188 | ```
189 |
190 | The following commands will then be available from the repository root:
191 |
192 | ```bash
193 | npm run build # build dist files
194 | npm run lint # perform code linting
195 | ```
196 |
197 | ## About Data
198 |
199 | The data for this visualization are sourced from [RainViewer](https://www.rainviewer.com), which also gathers data from [different data sources](https://www.rainviewer.com/sources.html).
200 |
201 | ## License
202 |
203 | Mapbox GL JS Rain Layer is available under the [MIT license](https://opensource.org/licenses/MIT).
204 |
--------------------------------------------------------------------------------
/docs/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |