├── .babelrc
├── .eslintignore
├── .eslintrc
├── .flowconfig
├── .gitignore
├── .npmignore
├── .nvmrc
├── CHANGELOG.md
├── CONTRIBUTING.md
├── LICENSE.md
├── README.md
├── example
├── index.html
├── index.js
├── realworld.10000.js
└── webpack.config.js
├── lib
└── HeatmapLayer.js
├── package.json
├── screenshot.jpg
└── src
└── HeatmapLayer.js
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "plugins": [
3 | "babel-plugin-transform-do-expressions",
4 | "babel-plugin-transform-function-bind",
5 | "babel-plugin-transform-class-constructor-call",
6 | ["babel-plugin-transform-class-properties", { "loose": true }],
7 | "babel-plugin-transform-decorators",
8 | "babel-plugin-transform-export-extensions",
9 | "babel-plugin-syntax-trailing-function-commas",
10 | "babel-plugin-transform-object-rest-spread",
11 | "babel-plugin-transform-async-to-generator",
12 | "babel-plugin-transform-exponentiation-operator",
13 |
14 | "babel-plugin-transform-react-jsx",
15 | "babel-plugin-transform-flow-strip-types",
16 | "babel-plugin-syntax-flow",
17 | "babel-plugin-syntax-jsx",
18 | "babel-plugin-transform-react-display-name",
19 |
20 | ["babel-plugin-transform-es2015-template-literals", { "loose": true }],
21 | "babel-plugin-transform-es2015-literals",
22 | "babel-plugin-transform-es2015-function-name",
23 | "babel-plugin-transform-es2015-arrow-functions",
24 | "babel-plugin-transform-es2015-block-scoped-functions",
25 | ["babel-plugin-transform-es2015-classes", { "loose": true }],
26 | "babel-plugin-transform-es2015-object-super",
27 | "babel-plugin-transform-es2015-shorthand-properties",
28 | ["babel-plugin-transform-es2015-computed-properties", { "loose": true }],
29 | ["babel-plugin-transform-es2015-for-of", { "loose": true }],
30 | "babel-plugin-transform-es2015-sticky-regex",
31 | "babel-plugin-transform-es2015-unicode-regex",
32 | ["babel-plugin-transform-es2015-spread", { "loose": true }],
33 | "babel-plugin-transform-es2015-parameters",
34 | ["babel-plugin-transform-es2015-destructuring", { "loose": true }],
35 | "babel-plugin-transform-es2015-block-scoping",
36 | "babel-plugin-transform-es2015-typeof-symbol",
37 | ["babel-plugin-transform-es2015-modules-commonjs", { "loose": true }],
38 | "babel-plugin-transform-regenerator"
39 | ]
40 | }
41 |
--------------------------------------------------------------------------------
/.eslintignore:
--------------------------------------------------------------------------------
1 | node_modules/**
2 | lib/**
3 |
--------------------------------------------------------------------------------
/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "eslint-config-airbnb",
3 | "parser": "babel-eslint",
4 | "env": {
5 | "browser": true,
6 | "mocha": true,
7 | "node": true
8 | },
9 | "globals": {
10 | "__data": true,
11 | "expect": true,
12 | "ga": true,
13 | "Intercom": true,
14 | "spy": true,
15 | "sinon": true,
16 | "Raven": true,
17 | "Highcharts": true
18 | },
19 | "rules": {
20 | "comma-dangle": 0,
21 | "no-wrap-func": 0,
22 | "spaced-comment": 0,
23 | "eqeqeq": [2, "smart"],
24 |
25 | // Portal uses some camelcase
26 | "camelcase": 1,
27 |
28 | // used for creating new Immutable Lists and Maps
29 | "new-cap": [1, {"capIsNewExceptions": ["Immutable"]}],
30 |
31 | // Sometimes short variable names are okay
32 | "id-length": 0,
33 |
34 | // Doesn't play nice with chai's assertions
35 | "no-unused-expressions": 0,
36 |
37 | "react/jsx-uses-react": 2,
38 | "react/jsx-uses-vars": 2,
39 | "react/react-in-jsx-scope": 2,
40 | "react/jsx-no-duplicate-props": 2,
41 |
42 |
43 | // Discourages microcomponentization
44 | "react/no-multi-comp": 0,
45 |
46 | //Temporarirly disabled due to a possible bug in babel-eslint (todomvc example)
47 | "block-scoped-var": 0,
48 | // Temporarily disabled for test/* until babel/babel-eslint#33 is resolved
49 | "padded-blocks": 0,
50 | "no-param-reassign": 0
51 | },
52 | "plugins": [
53 | "react",
54 | "lean-imports"
55 | ]
56 | }
57 |
--------------------------------------------------------------------------------
/.flowconfig:
--------------------------------------------------------------------------------
1 | [ignore]
2 | .*/node_modules/babel-cli/.*
3 | .*/node_modules/babel-generator/.*
4 | .*/node_modules/babel-helper-builder-binary-assignment-operator-visitor/.*
5 | .*/node_modules/babel-helper-explode-assignable-expression/.*
6 | .*/node_modules/babel-helper-remap-async-to-generator/.*
7 | .*/node_modules/babel-helper-regex/.*
8 | .*/node_modules/babel-plugin-transform-regenerator/.*
9 | .*/node_modules/babel-template/.*
10 | .*/node_modules/babel-types/.*
11 | .*/node_modules/jsxhint/.*
12 | .*/node_modules/fbjs/.*
13 | .*/node_modules/flow-bin/.*
14 | .*/node_modules/flux/.*
15 | .*/node_modules/node-sass/.*
16 | .*/node_modules/phantomjs/.*
17 | .*/node_modules/react-styleguidist/.*
18 | .*/node_modules/config-chain/.*
19 | .*/node_modules/findup/.*
20 |
21 |
22 | [include]
23 |
24 | [libs]
25 |
26 | [options]
27 | esproposal.class_instance_fields=enable
28 | suppress_comment= \\(.\\|\n\\)*\\$FlowFixMe
29 | esproposal.class_static_fields=enable
30 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 |
5 | # Runtime data
6 | pids
7 | *.pid
8 | *.seed
9 |
10 | # Directory for instrumented libs generated by jscoverage/JSCover
11 | lib-cov
12 |
13 | # Coverage directory used by tools like istanbul
14 | coverage
15 |
16 | # Compiled binary addons (http://nodejs.org/api/addons.html)
17 | build/Release
18 | build
19 |
20 | # Dependency directory
21 | # Commenting this out is preferred by some people, see
22 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git-
23 | node_modules
24 | bower_components
25 |
26 | # Users Environment Variables
27 | .lock-wscript
28 | .sass-cache
29 |
30 | .idea/
31 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | .babelrc
2 | .gitignore
3 | .npmignore
4 | .nvmrc
5 | screenshot.jpg
6 |
--------------------------------------------------------------------------------
/.nvmrc:
--------------------------------------------------------------------------------
1 | 4.3.0
2 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # 2.0.0 Release
2 | - React-leaflet v2.x support. For react-leaflet v1.x please use react-leaflet-heatmep-layer v1.x.
3 |
4 | # 1.0.4 Release
5 | - Allow the latest versions of `react` and `react-dom` (i.e. 16 and up).
6 |
7 | # 1.0.3 Release
8 | - Fixed warning "Accessing PropTypes via the main React package is deprecated"
9 |
10 | # 1.0.2 Release
11 | - Fix bug where radius, blur, and max were not being used when passed in as props.
12 |
13 | # 1.0.1 Release
14 | - Fix bug in componentWillUnmount->safeRemoveLayer where getPanes doesn't return anything so .contains is called on undefined.
15 |
16 | # 1.0.0 Release
17 | - Leaflet 1.0.0 support
18 | - React-Leaflet 1.0.0 support
19 | - List eslint as an explicit devDependency
20 | - upgrade the eslint related packages
21 | - fix linting errors using current config
22 | - Add notes about maintaining absence of lint errors and warnings in Contributing guide
23 | - This should make it easier to ensure code quality as others contribute in the open
24 | - Also, drop unused jest and enzyme deps
25 |
26 | # 0.2.3 Release
27 | - Missed Transpilation
28 |
29 | # 0.2.2 Release
30 | - Change `getHeatmapProps` signature to take a `props` argument to support passing `nextProps` from `componentWillReceiveProps` and `this.props` from `componentDidMount`
31 |
32 | # 0.2.1 Release
33 |
34 | - Fix getMaxZoom returning props.radius instead of props.maxZoom, fix misnamed call to getMax instead of getMaxZoom in redraw()
35 |
36 | # 0.2.0 Release
37 |
38 | - adds an `onStatsUpdate` prop which is called on redraw with a { min, max } object containing the min and max number of items found for a single coordinate
39 |
40 | # 0.1.0 Release
41 |
42 | - Handle invalid points gracefully
43 | - Add `fitBoundsOnUpdate` prop to indicate that the map should fit the data in the map on update
44 |
45 | # 0.0.2 Release
46 |
47 | - Fix an issue with the gradient property being applied
48 |
49 | # 0.0.1 Release
50 |
51 | - Initial implementation of package
52 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing
2 |
3 | Things you can do to contribute include:
4 |
5 | 1. Report a bug by [opening an issue](https://github.com/OpenGov/react-leaflet-heatmap-layer/issues/new)
6 | 2. Suggest a change by [opening an issue](https://www.github.com/OpenGov/react-leaflet-heatmap-layer/issues/new)
7 | 3. Fork the repository and fix [an open issue](https://github.com/OpenGov/react-leaflet-heatmap-layer/issues)
8 |
9 | ### Technology
10 |
11 | `react-leaflet-heatmap-layer` is a custom layer for the `react-leaflet` package. This package is a convenient wrapper around Leaflet, a mapping library, for React. The source code is written with ES6/ES2015 syntax as well as [FlowType](http://flowtype.org) type annotations.
12 |
13 | ### Install dependencies
14 |
15 | 1. Install Node via [nodejs.org](http://nodejs.org)
16 | 2. After cloning the repository, run `npm install` in the root of the project
17 |
18 | This project is developed with Node version 4.3.0 and NPM 3.3.10.
19 |
20 | ### Contributing via Github
21 |
22 | The entire project can be found [on Github](https://github.com/OpenGov/react-leaflet-heatmap-layer). We use the [fork and pull model](https://help.github.com/articles/using-pull-requests/) to process contributions.
23 |
24 | #### Fork the Repository
25 |
26 | Before contributing, you'll need to fork the repository:
27 |
28 | 1. Fork the repository so you have your own copy (`your-username/react-leaflet-heatmap-layer`)
29 | 2. Clone the repo locally with `git clone https://github.com/your-username/react-leaflet-heatmap-layer`
30 | 3. Move into the cloned repo: `cd react-leaflet-heatmap-layer`
31 | 4. Install the project's dependencies: `npm install`
32 |
33 | You should also add `OpenGov/react-leaflet-heatmap-layer` as a remote at this point. We generally call this remote branch 'upstream':
34 |
35 | ```
36 | git remote add upstream https://github.com/OpenGov/react-leaflet-heatmap-layer
37 | ```
38 |
39 | #### Development
40 |
41 | You can work with a live, hot-reloading example of the component by running:
42 |
43 | ```bash
44 | npm run example
45 | ```
46 |
47 | And then visiting [localhost:8000](http://localhost:8000).
48 |
49 | As you make changes, please describe them in `CHANGELOG.md`.
50 |
51 | #### Submitting a Pull Request
52 |
53 | Before submitting a Pull Request please ensure you have completed the following tasks:
54 |
55 | 1. Describe your changes in `CHANGELOG.md`
56 | 2. Make sure your copy is up to date: `git pull upstream master`
57 | 3. Run `npm run compile`, to compile your changes to the exported `/lib` code.
58 | 4. Bump the version in `package.json` as appropriate, see `Versioning` in the section below.
59 | 4. Run `npm run lint` to verify code style, all pull requests should have zero lint errors and warnings
60 | 4. Commit your changes
61 | 5. Push your changes to your fork: `your-username/react-leaflet-heatmap-layer`
62 | 6. Open a pull request from your fork to the `upstream` fork (`OpenGov/react-leaflet-heatmap-layer`)
63 |
64 | ## Versioning
65 |
66 | This project follows Semantic Versioning.This means that version numbers are basically formatted like `MAJOR.MINOR.PATCH`.
67 |
68 | #### Major
69 |
70 | Breaking changes are signified with a new **first** number. For example, moving from 1.0.0 to 2.0.0 implies breaking changes.
71 |
72 | #### Minor
73 |
74 | New components, new helper classes, or substantial visual changes to existing components and patterns are *minor releases*. These are signified by the second number changing. So from 1.1.2 to 1.2.0 there are minor changes.
75 |
76 | #### Patches
77 |
78 | The final number signifies patches such as fixing a pattern or component in a certain browser, or fixing an existing bug. Small changes to the documentation site and the tooling around the Calcite-Web library are also considered patches.
79 |
80 | ## Developer's Certificate of Origin 1.1
81 |
82 | By making a contribution to this project, I certify that:
83 |
84 | * (a) The contribution was created in whole or in part by me and I
85 | have the right to submit it under the open source license
86 | indicated in the file; or
87 |
88 | * (b) The contribution is based upon previous work that, to the best
89 | of my knowledge, is covered under an appropriate open source
90 | license and I have the right under that license to submit that
91 | work with modifications, whether created in whole or in part
92 | by me, under the same open source license (unless I am
93 | permitted to submit under a different license), as indicated
94 | in the file; or
95 |
96 | * (c) The contribution was provided directly to me by some other
97 | person who certified (a), (b) or (c) and I have not modified
98 | it.
99 |
100 | * (d) I understand and agree that this project and the contribution
101 | are public and that a record of the contribution (including all
102 | personal information I submit with it, including my sign-off) is
103 | maintained indefinitely and may be redistributed consistent with
104 | this project or the open source license(s) involved.
105 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 | Copyright (c) 2016 OpenGov, Inc.
3 |
4 | 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:
5 |
6 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 |
8 | 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.
9 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # react-leaflet-heatmap-layer
2 |
3 | `react-leaflet-heatmap-layer` provides a simple `` component for creating a heatmap layer in a `react-leaflet` map.
4 |
5 | 
6 |
7 | ## Usage
8 |
9 | Use directly as a fixed layer:
10 |
11 | ```js
12 | import React from 'react';
13 | import { render } from 'react-dom';
14 | import { Map, Marker, Popup, TileLayer } from 'react-leaflet';
15 | import HeatmapLayer from '../src/HeatmapLayer';
16 | import { addressPoints } from './realworld.10000.js';
17 |
18 | class MapExample extends React.Component {
19 |
20 | render() {
21 | return (
22 |
23 |
36 |
37 | );
38 | }
39 |
40 | }
41 |
42 | render(, document.getElementById('app'));
43 | ```
44 |
45 | Or use it inside a layer control to toggle it:
46 |
47 | ```js
48 | import React from 'react';
49 | import { render } from 'react-dom';
50 | import { Map, Marker, Popup, TileLayer } from 'react-leaflet';
51 | import HeatmapLayer from '../src/HeatmapLayer';
52 | import { addressPoints } from './realworld.10000.js';
53 |
54 | class MapExample extends React.Component {
55 |
56 | render() {
57 | return (
58 |
59 |
95 |
96 | );
97 | }
98 | }
99 |
100 | render(, document.getElementById('app'));
101 | ```
102 |
103 |
104 | ## API
105 |
106 | The `HeatmapLayer` component takes the following props:
107 |
108 | - `points`: *required* an array of objects to be processed
109 | - `longitudeExtractor`: *required* a function that returns the object's longitude e.g. `marker => marker.lng`
110 | - `latitudeExtractor`: *required* a function that returns the object's latitude e.g. `marker => marker.lat`
111 | - `intensityExtractor`: *required* a function that returns the object's intensity e.g. `marker => marker.val`
112 | - `fitBoundsOnLoad`: boolean indicating whether map should fit data in bounds of map on load
113 | - `fitBoundsOnUpdate`: boolean indicating whether map should fit data in bounds of map on Update
114 | - `max`: max intensity value for heatmap (default: 3.0)
115 | - `radius`: radius for heatmap points (default: 30)
116 | - `maxZoom`: maximum zoom for heatmap (default: 18)
117 | - `minOpacity`: minimum opacity for heatmap (default: 0.01)
118 | - `blur`: blur for heatmap points (default: 15)
119 | - `gradient`: object defining gradient stop points for heatmap e.g. `{ 0.4: 'blue', 0.8: 'orange', 1.0: 'red' }` (default: `simpleheat` package default gradient)
120 | - `onStatsUpdate`: called on redraw with a { min, max } object containing the min and max number of items found for a single coordinate
121 |
122 | ## Example
123 |
124 | To try the example:
125 |
126 | 1. Clone this repository
127 | 2. run `npm install` in the root of your cloned repository
128 | 3. run `npm run example`
129 | 4. Visit [localhost:8000](http://localhost:8000)
130 |
131 | ## Contributing
132 |
133 | See [CONTRIBUTING.md](https://www.github.com/OpenGov/react-leaflet-heatmap-layer/blob/master/CONTRIBUTING.md)
134 |
135 | ## Credits
136 |
137 | This package was inspired by [Leaflet.heat](https://github.com/Leaflet/Leaflet.heat).
138 |
139 | ## License
140 |
141 | `react-leaflet-heatmap-layer` is MIT licensed.
142 |
143 | See [LICENSE.md](https://www.github.com/OpenGov/react-leaflet-heatmap-layer/blob/master/LICENSE.md) for details.
144 |
--------------------------------------------------------------------------------
/example/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | react-leaflet-heatmap-layer example
6 |
7 |
8 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/example/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { render } from 'react-dom';
3 | import { Map, TileLayer } from 'react-leaflet';
4 | import HeatmapLayer from '../src/HeatmapLayer';
5 | import { addressPoints } from './realworld.10000.js';
6 |
7 | class MapExample extends React.Component {
8 |
9 | state = {
10 | mapHidden: false,
11 | layerHidden: false,
12 | addressPoints,
13 | radius: 4,
14 | blur: 8,
15 | max: 0.5,
16 | limitAddressPoints: true,
17 | };
18 |
19 | /**
20 | * Toggle limiting the address points to test behavior with refocusing/zooming when data points change
21 | */
22 | toggleLimitedAddressPoints() {
23 | if (this.state.limitAddressPoints) {
24 | this.setState({ addressPoints: addressPoints.slice(500, 1000), limitAddressPoints: false });
25 | } else {
26 | this.setState({ addressPoints, limitAddressPoints: true });
27 | }
28 | }
29 |
30 | render() {
31 | if (this.state.mapHidden) {
32 | return (
33 |