├── .nvmrc ├── .eslintignore ├── .npmignore ├── screenshot.jpg ├── CHANGELOG.md ├── .gitignore ├── example ├── index.html ├── webpack.config.js └── index.js ├── .flowconfig ├── LICENSE.md ├── .eslintrc ├── .babelrc ├── package.json ├── README.md ├── src ├── __tests__ │ └── ClusterLayer.test.js └── ClusterLayer.js ├── CONTRIBUTING.md └── lib └── ClusterLayer.js /.nvmrc: -------------------------------------------------------------------------------- 1 | 4.3.0 2 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | node_modules/** 2 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .babelrc 2 | .gitignore 3 | .npmignore 4 | .nvmrc 5 | screenshot.jpg 6 | -------------------------------------------------------------------------------- /screenshot.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenGov/react-leaflet-cluster-layer/HEAD/screenshot.jpg -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # 0.0.3 Release 2 | 3 | - Correct issue introduced with removal of 'moveend' listener 4 | 5 | # 0.0.2 Release 6 | 7 | - Simplify event responders 8 | - Fix a bug where clusters got wrong props 9 | 10 | # 0.0.1 Release 11 | 12 | - Initial implementation of package 13 | - Updated readme, license filename, added changelog, added contribution guide 14 | - Added description of technology and language to contribution guide 15 | - Expanded instructions for running example in README.md 16 | - Added unit tests 17 | - Added developer certificate of origin to contributing guide 18 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /example/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | React-Leaflet examples 6 | 7 | 8 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /example/webpack.config.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | var webpack = require('webpack'); 3 | 4 | module.exports = { 5 | debug: true, 6 | devtool: 'source-map', 7 | entry: { 8 | app: __dirname + '/index.js' 9 | }, 10 | module: { 11 | loaders: [ 12 | { 13 | test: /\.js$/, 14 | exclude: /node_modules/, 15 | loader: 'babel', 16 | query: { 17 | plugins: [ 18 | ['react-transform', { 19 | transforms: [{ 20 | transform: 'react-transform-hmr', 21 | imports: ['react'], 22 | locals: ['module'] 23 | }] 24 | }] 25 | ] 26 | } 27 | }, 28 | ] 29 | }, 30 | output: { 31 | path: __dirname + '/build/', 32 | filename: '[name].js', 33 | publicPath: 'http://localhost:8000/build' 34 | }, 35 | plugins: [ 36 | new webpack.DefinePlugin({ 37 | 'process.env': { 38 | 'NODE_ENV': '"development"' 39 | } 40 | }), 41 | new webpack.NoErrorsPlugin(), 42 | new webpack.HotModuleReplacementPlugin() 43 | ], 44 | devServer: { 45 | colors: true, 46 | contentBase: __dirname, 47 | historyApiFallback: true, 48 | hot: true, 49 | inline: true, 50 | port: 8000, 51 | progress: true, 52 | stats: { 53 | cached: false 54 | } 55 | } 56 | }; 57 | -------------------------------------------------------------------------------- /.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 | 51 | }, 52 | "plugins": [ 53 | "react", 54 | "lean-imports" 55 | ] 56 | } 57 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /example/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { render } from 'react-dom'; 3 | import { Map, Marker, Popup, TileLayer } from 'react-leaflet'; 4 | import ClusterLayer from '../src/ClusterLayer'; 5 | 6 | const position = { lng: -122.673447, lat: 45.522558 }; 7 | const markers = [ 8 | { 9 | position: { lng: -122.673447, lat: 45.5225581 }, 10 | text: 'Voodoo Doughnut', 11 | }, 12 | { 13 | position: { lng: -122.6781446, lat: 45.5225512 }, 14 | text: 'Bailey\'s Taproom', 15 | }, 16 | { 17 | position: { lng: -122.67535700000002, lat: 45.5192743 }, 18 | text: 'Barista' 19 | }, 20 | { 21 | position: { lng: -122.65596570000001, lat: 45.5199148000001 }, 22 | text: 'Base Camp Brewing' 23 | } 24 | ]; 25 | 26 | class ExampleClusterComponent extends React.Component { 27 | 28 | render() { 29 | const style = { 30 | border: 'solid 3px lightblue', 31 | backgroundColor: '#333333', 32 | color: 'white', 33 | textAlign: 'center', 34 | margin: '0', 35 | padding: '0.25em 0.25em 0.5em', 36 | fontSize: '1.25em', 37 | fontWeight: '700' 38 | }; 39 | const cluster = this.props.cluster; 40 | 41 | if (cluster.markers.length == 1) { 42 | const markerStyle = Object.assign({}, style, { 43 | minWidth: '110px', 44 | borderRadius: '16px', 45 | borderTopLeftRadius: '0', 46 | }); 47 | 48 | return ( 49 |
{cluster.markers[0].text}
50 | ); 51 | } 52 | 53 | const clusterStyle = Object.assign({}, style, { 54 | borderRadius: '50%', 55 | borderTopLeftRadius: '0', 56 | width: '24px', 57 | height: '24px' 58 | }); 59 | 60 | return ( 61 |
{cluster.markers.length}
62 | ); 63 | } 64 | 65 | } 66 | 67 | const map = ( 68 | 69 | 72 | 76 | 77 | ); 78 | 79 | render(map, document.getElementById('app')); 80 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-leaflet-cluster-layer", 3 | "version": "0.0.3", 4 | "description": "A custom layer for react-leaflet that makes plotting and clustering react components simple", 5 | "main": "lib/ClusterLayer.js", 6 | "scripts": { 7 | "test": "jest", 8 | "compile": "npm run clean; npm run transpile", 9 | "transpile": "./node_modules/.bin/babel src/ClusterLayer.js --out-file lib/ClusterLayer.js", 10 | "clean": "rm -rf ./lib/*", 11 | "example": "webpack-dev-server --config ./example/webpack.config.js" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "git+https://github.com/OpenGov/react-leaflet-cluster-layer.git" 16 | }, 17 | "keywords": [ 18 | "react", 19 | "leaflet", 20 | "cluster", 21 | "layer", 22 | "map", 23 | "maps", 24 | "gis", 25 | "geo", 26 | "geojson", 27 | "marker" 28 | ], 29 | "author": "Jeremiah Hall ", 30 | "license": "MIT", 31 | "peerDependencies": { 32 | "leaflet": "^0.7.7", 33 | "react-leaflet": "^0.10.2", 34 | "react": "^0.14.7", 35 | "react-dom": "^0.14.7" 36 | }, 37 | "devDependencies": { 38 | "babel-cli": "^6.6.5", 39 | "babel-core": "^6.7.4", 40 | "babel-eslint": "^5.0.0", 41 | "babel-jest": "^9.0.3", 42 | "babel-loader": "^6.2.4", 43 | "babel-plugin-object-assign": "^1.2.1", 44 | "babel-plugin-react-transform": "^2.0.0", 45 | "babel-plugin-transform-proto-to-assign": "^6.4.0", 46 | "babel-polyfill": "^6.7.4", 47 | "babel-preset-es2015": "^6.3.13", 48 | "babel-preset-react": "^6.3.13", 49 | "babel-preset-stage-0": "^6.3.13", 50 | "enzyme": "^2.2.0", 51 | "eslint-config-airbnb": "^6.2.0", 52 | "eslint-plugin-arrow-function": "^2.0.0", 53 | "eslint-plugin-react": "^4.2.3", 54 | "jest-cli": "^0.9.2", 55 | "leaflet": "^0.7.7", 56 | "react": "^0.14.7", 57 | "react-addons-test-utils": "^0.14.7", 58 | "react-dom": "^0.14.7", 59 | "react-leaflet": "^0.10.2", 60 | "react-transform-hmr": "^1.0.4", 61 | "webpack-dev-server": "^1.14.1", 62 | "webpack": "^1.12.14" 63 | }, 64 | "jest": { 65 | "scriptPreprocessor": "/node_modules/babel-jest/src/index.js", 66 | "unmockedModulePathPatterns": [ 67 | "react", 68 | "enzyme", 69 | "react-dom", 70 | "react-addons-test-utils", 71 | "fbjs", 72 | "cheerio", 73 | "htmlparser2", 74 | "underscore", 75 | "lodash", 76 | "domhandler", 77 | "object.assign", 78 | "define-properties", 79 | "function-bind", 80 | "object-keys" 81 | ], 82 | "moduleFileExtensions": [ 83 | "js", 84 | "json", 85 | "jsx" 86 | ] 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # react-leaflet-cluster-layer 2 | 3 | `react-leaflet-cluster-layer` provides a simple `` component for plotting React components as markers and clusters in a `react-leaflet` map. 4 | 5 | ![A screenshot of a cluster on a leaflet map](../master/screenshot.jpg?raw=true) 6 | 7 | ## Usage 8 | 9 | ```js 10 | import React from 'react'; 11 | import { render } from 'react-dom'; 12 | import { Map, Marker, Popup, TileLayer } from 'react-leaflet'; 13 | import ClusterLayer from 'react-leaflet-cluster-layer'; 14 | 15 | const position = { lng: -122.673447, lat: 45.522558 }; 16 | const markers = [ 17 | { 18 | position: { lng: -122.673447, lat: 45.5225581 }, 19 | text: 'Voodoo Doughnut', 20 | }, 21 | { 22 | position: { lng: -122.6781446, lat: 45.5225512 }, 23 | text: 'Bailey\'s Taproom', 24 | }, 25 | { 26 | position: { lng: -122.67535700000002, lat: 45.5192743 }, 27 | text: 'Barista' 28 | } 29 | ]; 30 | 31 | class ExampleClusterComponent extends React.Component { 32 | 33 | render() { 34 | const style = { 35 | border: 'solid 2px darkgrey', 36 | borderRadius: '8px', 37 | backgroundColor: 'white', 38 | padding: '1em', 39 | textAlign: 'center' 40 | }; 41 | const cluster = this.props.cluster; 42 | 43 | if (cluster.markers.length == 1) { 44 | return ( 45 |
{cluster.markers[0].text}
46 | ); 47 | } 48 | 49 | return ( 50 |
{cluster.markers.length} items
51 | ); 52 | } 53 | 54 | } 55 | 56 | const map = ( 57 | 58 | 61 | 65 | 66 | ); 67 | 68 | render(map, document.getElementById('app')); 69 | ``` 70 | 71 | ## API 72 | 73 | The `ClusterLayer` component takes the following props: 74 | 75 | - `markers`: an array of objects that expose the properties defined in the `Marker` type 76 | - `clusterComponent`: (required) the React component to be rendered for each marker and cluster, this component will receive the following props 77 | - `cluster`: a `Cluster` object, as defined by the Cluster Flow type 78 | - `style`: a style object for positioning 79 | - `map`: the Leaflet map object from the `react-leaflet` `MapLayer` 80 | - `...propsForClusters`: the component will also receive the properties of `propsForClusters` as props 81 | - `propsForClusters`: props to pass on to marker and cluster components 82 | - `gridSize`: optional prop to control how bounds of clusters expand while being generated (default: 60) 83 | - `minClusterSize`: optional prop to enforce a minimum cluster size (default: 2) 84 | 85 | ## Example 86 | 87 | To try the example: 88 | 89 | 1. Clone this repository 90 | 2. run `npm install` in the root of your cloned repository 91 | 3. run `npm run example` 92 | 4. Visit [localhost:8000](http://localhost:8000) 93 | 94 | ## Contributing 95 | 96 | See [CONTRIBUTING.md](https://www.github.com/OpenGov/react-leaflet-cluster-layer/blob/master/CONTRIBUTING.md) 97 | 98 | ## License 99 | 100 | `react-leaflet-cluster-layer` is MIT licensed. 101 | 102 | See [LICENSE.md](https://www.github.com/OpenGov/react-leaflet-cluster-layer/blob/master/LICENSE.md) for details. 103 | -------------------------------------------------------------------------------- /src/__tests__/ClusterLayer.test.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { shallow, mount, render } from 'enzyme'; 3 | import { Map } from 'react-leaflet'; 4 | import ClusterLayer from '../ClusterLayer.js'; 5 | 6 | jest.unmock('../ClusterLayer.js'); 7 | 8 | const L = jest.genMockFromModule('leaflet'); 9 | 10 | class ClusterComponent extends React.Component { 11 | render() { 12 | return ( 13 |
Cluster component
14 | ); 15 | } 16 | } 17 | 18 | describe('ClusterLayer', () => { 19 | 20 | /* 21 | Here we declare mocks or fixtures of 22 | all the data structures that the component uses 23 | */ 24 | const center = { lng: -122.673447, lat: 45.522558 }; 25 | 26 | const mockBounds = { 27 | contains: jest.fn(() => true), 28 | extend: jest.fn(), 29 | getNorthEast: jest.fn(() => ({ lng: -122, lat: 46 })), 30 | getSouthWest: jest.fn(() => ({ lng: -123, lat: 45 })), 31 | }; 32 | 33 | const mockPanes = { overlayPane: { appendChild: jest.fn() } }; 34 | 35 | const mockMap = { 36 | layerPointToLatLng: jest.fn(() => ({ lng: -122.6, lat: 45.522 })), 37 | latLngToLayerPoint: jest.fn(() => ({ x: 100, y: 100 })), 38 | on: jest.fn(), 39 | getBounds: jest.fn(() => mockBounds), 40 | getPanes: jest.fn(() => mockPanes), 41 | invalidateSize: jest.fn() 42 | }; 43 | 44 | const mockMarkers = [ 45 | { 46 | position: { lng: -122.673447, lat: 45.5225581 }, 47 | text: 'Voodoo Doughnut', 48 | }, 49 | { 50 | position: { lng: -122.6781446, lat: 45.5225512 }, 51 | text: 'Bailey\'s Taproom', 52 | }, 53 | { 54 | position: { lng: -122.67535700000002, lat: 45.5192743 }, 55 | text: 'Barista' 56 | } 57 | ]; 58 | 59 | it('should render', () => { 60 | const layer = render( 61 | 64 | ); 65 | expect(layer).toBeTruthy(); 66 | }); 67 | 68 | it('should render a single child given one marker', () => { 69 | const layer = mount( 70 | 74 | ); 75 | expect(layer.find('.cluster-component').length).toEqual(1); 76 | }); 77 | 78 | it('should render one child given three markers with the same position', () => { 79 | const layer = mount( 80 | 84 | ); 85 | expect(layer.find('.cluster-component').length).toEqual(1); 86 | }); 87 | 88 | it('should render three child given three markers with the different positions', () => { 89 | const layer = mount( 90 | 94 | ); 95 | expect(layer.find('.cluster-component').length).toEqual(3); 96 | }); 97 | 98 | it('should pass the `propsForClusters` prop to rendered ', () => { 99 | const mockProps = { 100 | theAnswer: 42, 101 | numCoffees: 3 102 | }; 103 | 104 | const layer = mount( 105 | 110 | ); 111 | const componentProps = layer.find(ClusterComponent).at(0).props(); 112 | expect(componentProps).toBeTruthy(); 113 | expect(componentProps.theAnswer).toEqual(mockProps.theAnswer); 114 | expect(componentProps.numCoffees).toEqual(mockProps.numCoffees); 115 | }); 116 | }); 117 | -------------------------------------------------------------------------------- /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-cluster-layer/issues/new) 6 | 2. Suggest a change by [opening an issue](https://www.github.com/OpenGov/react-leaflet-cluster-layer/issues/new) 7 | 3. Fork the repository and fix [an open issue](https://github.com/OpenGov/react-leaflet-cluster-layer/issues) 8 | 9 | ### Technology 10 | 11 | `react-leaflet-cluster-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-cluster-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-cluster-layer`) 29 | 2. Clone the repo locally with `git clone https://github.com/your-username/react-leaflet-cluster-layer` 30 | 3. Move into the cloned repo: `cd react-leaflet-cluster-layer` 31 | 4. Install the project's dependencies: `npm install` 32 | 33 | You should also add `OpenGov/react-leaflet-cluster-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-cluster-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. Ensure that all tests pass, tests for the component can be found in `lib/__tests__/ClusterLayer.test.js`, you can run these tests with `npm test` 58 | 3. Run `npm run compile`, to compile your changes to the exported `/lib` code. 59 | 4. Bump the version in `package.json` as appropriate, see `Versioning` in the section below. 60 | 4. Commit your changes 61 | 5. Push your changes to your fork: `your-username/react-leaflet-cluster-layer` 62 | 6. Open a pull request from your fork to the `upstream` fork (`OpenGov/react-leaflet-cluster-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 | -------------------------------------------------------------------------------- /src/ClusterLayer.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | 4 | import L from 'leaflet'; 5 | import { MapLayer } from 'react-leaflet'; 6 | 7 | export type LngLat = { 8 | lng: number; 9 | lat: number; 10 | } 11 | 12 | export type Marker = { 13 | position: LngLat; 14 | isAdded: boolean; 15 | } 16 | 17 | export type Point = { 18 | x: number; 19 | y: number; 20 | } 21 | 22 | export type Bounds = { 23 | contains: (latLng: LngLat) => boolean; 24 | extend: (latLng: LngLat) => void; 25 | getNorthEast: () => LngLat; 26 | getSouthWest: () => LngLat; 27 | } 28 | 29 | export type Map = { 30 | layerPointToLatLng: (lngLat: Point) => LngLat; 31 | latLngToLayerPoint: (lngLat: LngLat) => Point; 32 | on: (event: string, handler: () => void) => void; 33 | getBounds: () => Bounds; 34 | getPanes: () => Panes; 35 | invalidateSize: () => void; 36 | } 37 | 38 | export type Panes = { 39 | overlayPane: Pane; 40 | } 41 | 42 | export type Pane = { 43 | appendChild: (element: Object) => void; 44 | } 45 | 46 | export type Cluster = { 47 | center: LngLat; 48 | markers: Array; 49 | bounds: Bounds; 50 | } 51 | 52 | // Taken from http://stackoverflow.com/questions/1538681/how-to-call-fromlatlngtodivpixel-in-google-maps-api-v3/12026134#12026134 53 | // and modified to use Leaflet API 54 | function getExtendedBounds(map: Map, bounds: Bounds, gridSize: number): Bounds { 55 | // Turn the bounds into latlng. 56 | const northEastLat = bounds && bounds.getNorthEast() && bounds.getNorthEast().lat; 57 | const northEastLng = bounds && bounds.getNorthEast() && bounds.getNorthEast().lng; 58 | const southWestLat = bounds && bounds.getSouthWest() && bounds.getSouthWest().lat; 59 | const southWestLng = bounds && bounds.getSouthWest() && bounds.getSouthWest().lng; 60 | 61 | const tr = L.latLng(northEastLat, northEastLng); 62 | const bl = L.latLng(southWestLat, southWestLng); 63 | 64 | // Convert the points to pixels and the extend out by the grid size. 65 | const trPix = map.latLngToLayerPoint(tr); 66 | trPix.x += gridSize; 67 | trPix.y -= gridSize; 68 | 69 | const blPix = map.latLngToLayerPoint(bl); 70 | blPix.x -= gridSize; 71 | blPix.y += gridSize; 72 | 73 | // Convert the pixel points back to LatLng 74 | const ne = map.layerPointToLatLng(trPix); 75 | const sw = map.layerPointToLatLng(blPix); 76 | 77 | // Extend the bounds to contain the new bounds. 78 | bounds.extend(ne); 79 | bounds.extend(sw); 80 | 81 | return bounds; 82 | } 83 | 84 | function distanceBetweenPoints(p1: LngLat, p2: LngLat): number { 85 | if (!p1 || !p2) { 86 | return 0; 87 | } 88 | 89 | const R = 6371; // Radius of the Earth in km 90 | 91 | const degreesToRadians = degree => (degree * Math.PI / 180); 92 | const sinDouble = degree => Math.pow(Math.sin(degree / 2), 2); 93 | const cosSquared = (point1, point2) => { 94 | return Math.cos(degreesToRadians(point1.lat)) * Math.cos(degreesToRadians(point2.lat)); 95 | }; 96 | 97 | const dLat = degreesToRadians(p2.lat - p1.lat); 98 | const dLon = degreesToRadians(p2.lng - p1.lng); 99 | const a = sinDouble(dLat) + cosSquared(p1, p2) * sinDouble(dLon); 100 | const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); 101 | const d = R * c; 102 | return d; 103 | } 104 | 105 | export default class ClusterLayer extends MapLayer { 106 | static propTypes = { 107 | markers: React.PropTypes.array, 108 | clusterComponent: React.PropTypes.func.isRequired, 109 | propsForClusters: React.PropTypes.object, 110 | gridSize: React.PropTypes.number, 111 | minClusterSize: React.PropTypes.number 112 | }; 113 | 114 | state: Object = { 115 | clusters: [] 116 | }; 117 | 118 | componentDidMount(): void { 119 | this.leafletElement = ReactDOM.findDOMNode(this.refs.container); 120 | this.props.map.getPanes().overlayPane.appendChild(this.leafletElement); 121 | this.setClustersWith(this.props.markers); 122 | this.attachEvents(); 123 | } 124 | 125 | componentWillReceiveProps(nextProps: Object): void { 126 | if (!this.props || nextProps.markers !== this.props.markers) { 127 | this.setClustersWith(nextProps.markers); 128 | } 129 | } 130 | 131 | componentWillUnmount(): void { 132 | this.props.map.getPanes().overlayPane.removeChild(this.leafletElement); 133 | } 134 | 135 | componentDidUpdate(): void { 136 | this.props.map.invalidateSize(); 137 | this.updatePosition(); 138 | } 139 | 140 | shouldComponentUpdate(): boolean { 141 | return true; 142 | } 143 | 144 | setClustersWith(markers: Array): void { 145 | this.setState({ 146 | clusters: this.createClustersFor(markers) 147 | }); 148 | } 149 | 150 | recalculate(): void { 151 | this.setClustersWith(this.props.markers); 152 | this.updatePosition(); 153 | } 154 | 155 | attachEvents(): void { 156 | const map: Map = this.props.map; 157 | 158 | map.on('viewreset', () => this.recalculate()); 159 | map.on('moveend', () => this.recalculate()); 160 | } 161 | 162 | updatePosition(): void { 163 | this.state.clusters.forEach((cluster: Cluster, i) => { 164 | const clusterElement = ReactDOM.findDOMNode( 165 | this.refs[this.getClusterRefName(i)] 166 | ); 167 | 168 | L.DomUtil.setPosition( 169 | clusterElement, 170 | this.props.map.latLngToLayerPoint(cluster.center) 171 | ); 172 | }); 173 | } 174 | 175 | render(): React.Element { 176 | return ( 177 |
183 | {this.renderClusters()} 184 |
185 | ); 186 | } 187 | 188 | renderClusters(): Array { 189 | const style = { position: 'absolute' }; 190 | const ClusterComponent = this.props.clusterComponent; 191 | return this.state.clusters 192 | .map((cluster: Cluster, index: number) => ( 193 | 201 | )); 202 | } 203 | 204 | getGridSize(): number { 205 | return this.props.gridSize || 60; 206 | } 207 | 208 | getMinClusterSize(): number { 209 | return this.props.minClusterSize || 2; 210 | } 211 | 212 | isMarkerInBounds(marker: Marker, bounds: Bounds): boolean { 213 | return bounds.contains(marker.position); 214 | } 215 | 216 | calculateClusterBounds(cluster: Cluster) { 217 | const bounds = L.latLngBounds(cluster.center, cluster.center); 218 | cluster.bounds = getExtendedBounds(this.props.map, bounds, this.getGridSize()); 219 | } 220 | 221 | isMarkerInClusterBounds(cluster: Cluster, marker: Marker): boolean { 222 | return cluster.bounds.contains(L.latLng(marker.position)); 223 | } 224 | 225 | addMarkerToCluster(cluster: Cluster, marker: Marker) { 226 | const center = cluster.center; 227 | const markersLen = cluster.markers.length; 228 | 229 | if (!center) { 230 | cluster.center = L.latLng(marker.position); 231 | this.calculateClusterBounds(cluster); 232 | } else { 233 | const len = markersLen + 1; 234 | const lng = (center.lng * (len - 1) + marker.position.lng) / len; 235 | const lat = (center.lat * (len - 1) + marker.position.lat) / len; 236 | cluster.center = L.latLng({ lng, lat }); 237 | this.calculateClusterBounds(cluster); 238 | } 239 | 240 | marker.isAdded = true; 241 | cluster.markers.push(marker); 242 | } 243 | 244 | createClustersFor(markers: Array): Array { 245 | const map: Map = this.props.map; 246 | const extendedBounds = getExtendedBounds(map, map.getBounds(), this.getGridSize()); 247 | return markers 248 | .filter(marker => extendedBounds.contains(L.latLng(marker.position))) 249 | .reduce((clusters: Array, marker: Marker) => { 250 | let distance = 40000; // Some large number 251 | let clusterToAddTo = null; 252 | const pos = marker.position; 253 | 254 | clusters.forEach((cluster) => { 255 | const center = cluster.center; 256 | if (center) { 257 | const d = distanceBetweenPoints(center, pos); 258 | if (d < distance) { 259 | distance = d; 260 | clusterToAddTo = cluster; 261 | } 262 | } 263 | }); 264 | 265 | if (clusterToAddTo && this.isMarkerInClusterBounds(clusterToAddTo, marker)) { 266 | this.addMarkerToCluster(clusterToAddTo, marker); 267 | } else { 268 | const cluster = { 269 | markers: [marker], 270 | center: L.latLng(pos), 271 | bounds: L.latLngBounds() 272 | }; 273 | this.calculateClusterBounds(cluster); 274 | clusters.push(cluster); 275 | } 276 | return clusters; 277 | }, []); 278 | } 279 | 280 | getClusterRefName(index: number): string { 281 | return `cluster${index}`; 282 | } 283 | 284 | } 285 | -------------------------------------------------------------------------------- /lib/ClusterLayer.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | exports.__esModule = true; 4 | 5 | var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; 6 | 7 | var _react = require('react'); 8 | 9 | var _react2 = _interopRequireDefault(_react); 10 | 11 | var _reactDom = require('react-dom'); 12 | 13 | var _reactDom2 = _interopRequireDefault(_reactDom); 14 | 15 | var _leaflet = require('leaflet'); 16 | 17 | var _leaflet2 = _interopRequireDefault(_leaflet); 18 | 19 | var _reactLeaflet = require('react-leaflet'); 20 | 21 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 22 | 23 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } 24 | 25 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } 26 | 27 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } 28 | 29 | // Taken from http://stackoverflow.com/questions/1538681/how-to-call-fromlatlngtodivpixel-in-google-maps-api-v3/12026134#12026134 30 | // and modified to use Leaflet API 31 | function getExtendedBounds(map, bounds, gridSize) { 32 | // Turn the bounds into latlng. 33 | var northEastLat = bounds && bounds.getNorthEast() && bounds.getNorthEast().lat; 34 | var northEastLng = bounds && bounds.getNorthEast() && bounds.getNorthEast().lng; 35 | var southWestLat = bounds && bounds.getSouthWest() && bounds.getSouthWest().lat; 36 | var southWestLng = bounds && bounds.getSouthWest() && bounds.getSouthWest().lng; 37 | 38 | var tr = _leaflet2.default.latLng(northEastLat, northEastLng); 39 | var bl = _leaflet2.default.latLng(southWestLat, southWestLng); 40 | 41 | // Convert the points to pixels and the extend out by the grid size. 42 | var trPix = map.latLngToLayerPoint(tr); 43 | trPix.x += gridSize; 44 | trPix.y -= gridSize; 45 | 46 | var blPix = map.latLngToLayerPoint(bl); 47 | blPix.x -= gridSize; 48 | blPix.y += gridSize; 49 | 50 | // Convert the pixel points back to LatLng 51 | var ne = map.layerPointToLatLng(trPix); 52 | var sw = map.layerPointToLatLng(blPix); 53 | 54 | // Extend the bounds to contain the new bounds. 55 | bounds.extend(ne); 56 | bounds.extend(sw); 57 | 58 | return bounds; 59 | } 60 | 61 | function distanceBetweenPoints(p1, p2) { 62 | if (!p1 || !p2) { 63 | return 0; 64 | } 65 | 66 | var R = 6371; // Radius of the Earth in km 67 | 68 | var degreesToRadians = function degreesToRadians(degree) { 69 | return degree * Math.PI / 180; 70 | }; 71 | var sinDouble = function sinDouble(degree) { 72 | return Math.pow(Math.sin(degree / 2), 2); 73 | }; 74 | var cosSquared = function cosSquared(point1, point2) { 75 | return Math.cos(degreesToRadians(point1.lat)) * Math.cos(degreesToRadians(point2.lat)); 76 | }; 77 | 78 | var dLat = degreesToRadians(p2.lat - p1.lat); 79 | var dLon = degreesToRadians(p2.lng - p1.lng); 80 | var a = sinDouble(dLat) + cosSquared(p1, p2) * sinDouble(dLon); 81 | var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); 82 | var d = R * c; 83 | return d; 84 | } 85 | 86 | var ClusterLayer = function (_MapLayer) { 87 | _inherits(ClusterLayer, _MapLayer); 88 | 89 | function ClusterLayer() { 90 | var _temp, _this, _ret; 91 | 92 | _classCallCheck(this, ClusterLayer); 93 | 94 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { 95 | args[_key] = arguments[_key]; 96 | } 97 | 98 | return _ret = (_temp = (_this = _possibleConstructorReturn(this, _MapLayer.call.apply(_MapLayer, [this].concat(args))), _this), _this.state = { 99 | clusters: [] 100 | }, _temp), _possibleConstructorReturn(_this, _ret); 101 | } 102 | 103 | ClusterLayer.prototype.componentDidMount = function componentDidMount() { 104 | this.leafletElement = _reactDom2.default.findDOMNode(this.refs.container); 105 | this.props.map.getPanes().overlayPane.appendChild(this.leafletElement); 106 | this.setClustersWith(this.props.markers); 107 | this.attachEvents(); 108 | }; 109 | 110 | ClusterLayer.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) { 111 | if (!this.props || nextProps.markers !== this.props.markers) { 112 | this.setClustersWith(nextProps.markers); 113 | } 114 | }; 115 | 116 | ClusterLayer.prototype.componentWillUnmount = function componentWillUnmount() { 117 | this.props.map.getPanes().overlayPane.removeChild(this.leafletElement); 118 | }; 119 | 120 | ClusterLayer.prototype.componentDidUpdate = function componentDidUpdate() { 121 | this.props.map.invalidateSize(); 122 | this.updatePosition(); 123 | }; 124 | 125 | ClusterLayer.prototype.shouldComponentUpdate = function shouldComponentUpdate() { 126 | return true; 127 | }; 128 | 129 | ClusterLayer.prototype.setClustersWith = function setClustersWith(markers) { 130 | this.setState({ 131 | clusters: this.createClustersFor(markers) 132 | }); 133 | }; 134 | 135 | ClusterLayer.prototype.recalculate = function recalculate() { 136 | this.setClustersWith(this.props.markers); 137 | this.updatePosition(); 138 | }; 139 | 140 | ClusterLayer.prototype.attachEvents = function attachEvents() { 141 | var _this2 = this; 142 | 143 | var map = this.props.map; 144 | 145 | map.on('viewreset', function () { 146 | return _this2.recalculate(); 147 | }); 148 | map.on('moveend', function () { 149 | return _this2.recalculate(); 150 | }); 151 | }; 152 | 153 | ClusterLayer.prototype.updatePosition = function updatePosition() { 154 | var _this3 = this; 155 | 156 | this.state.clusters.forEach(function (cluster, i) { 157 | var clusterElement = _reactDom2.default.findDOMNode(_this3.refs[_this3.getClusterRefName(i)]); 158 | 159 | _leaflet2.default.DomUtil.setPosition(clusterElement, _this3.props.map.latLngToLayerPoint(cluster.center)); 160 | }); 161 | }; 162 | 163 | ClusterLayer.prototype.render = function render() { 164 | return _react2.default.createElement( 165 | 'div', 166 | { ref: 'container', 167 | className: 'leaflet-objects-pane leaflet-marker-pane leaflet-zoom-hide react-leaflet-cluster-layer' 168 | }, 169 | this.renderClusters() 170 | ); 171 | }; 172 | 173 | ClusterLayer.prototype.renderClusters = function renderClusters() { 174 | var _this4 = this; 175 | 176 | var style = { position: 'absolute' }; 177 | var ClusterComponent = this.props.clusterComponent; 178 | return this.state.clusters.map(function (cluster, index) { 179 | return _react2.default.createElement(ClusterComponent, _extends({}, _this4.props.propsForClusters, { 180 | key: index, 181 | style: style, 182 | map: _this4.props.map, 183 | ref: _this4.getClusterRefName(index), 184 | cluster: cluster 185 | })); 186 | }); 187 | }; 188 | 189 | ClusterLayer.prototype.getGridSize = function getGridSize() { 190 | return this.props.gridSize || 60; 191 | }; 192 | 193 | ClusterLayer.prototype.getMinClusterSize = function getMinClusterSize() { 194 | return this.props.minClusterSize || 2; 195 | }; 196 | 197 | ClusterLayer.prototype.isMarkerInBounds = function isMarkerInBounds(marker, bounds) { 198 | return bounds.contains(marker.position); 199 | }; 200 | 201 | ClusterLayer.prototype.calculateClusterBounds = function calculateClusterBounds(cluster) { 202 | var bounds = _leaflet2.default.latLngBounds(cluster.center, cluster.center); 203 | cluster.bounds = getExtendedBounds(this.props.map, bounds, this.getGridSize()); 204 | }; 205 | 206 | ClusterLayer.prototype.isMarkerInClusterBounds = function isMarkerInClusterBounds(cluster, marker) { 207 | return cluster.bounds.contains(_leaflet2.default.latLng(marker.position)); 208 | }; 209 | 210 | ClusterLayer.prototype.addMarkerToCluster = function addMarkerToCluster(cluster, marker) { 211 | var center = cluster.center; 212 | var markersLen = cluster.markers.length; 213 | 214 | if (!center) { 215 | cluster.center = _leaflet2.default.latLng(marker.position); 216 | this.calculateClusterBounds(cluster); 217 | } else { 218 | var len = markersLen + 1; 219 | var _lng = (center.lng * (len - 1) + marker.position.lng) / len; 220 | var _lat = (center.lat * (len - 1) + marker.position.lat) / len; 221 | cluster.center = _leaflet2.default.latLng({ lng: _lng, lat: _lat }); 222 | this.calculateClusterBounds(cluster); 223 | } 224 | 225 | marker.isAdded = true; 226 | cluster.markers.push(marker); 227 | }; 228 | 229 | ClusterLayer.prototype.createClustersFor = function createClustersFor(markers) { 230 | var _this5 = this; 231 | 232 | var map = this.props.map; 233 | var extendedBounds = getExtendedBounds(map, map.getBounds(), this.getGridSize()); 234 | return markers.filter(function (marker) { 235 | return extendedBounds.contains(_leaflet2.default.latLng(marker.position)); 236 | }).reduce(function (clusters, marker) { 237 | var distance = 40000; // Some large number 238 | var clusterToAddTo = null; 239 | var pos = marker.position; 240 | 241 | clusters.forEach(function (cluster) { 242 | var center = cluster.center; 243 | if (center) { 244 | var d = distanceBetweenPoints(center, pos); 245 | if (d < distance) { 246 | distance = d; 247 | clusterToAddTo = cluster; 248 | } 249 | } 250 | }); 251 | 252 | if (clusterToAddTo && _this5.isMarkerInClusterBounds(clusterToAddTo, marker)) { 253 | _this5.addMarkerToCluster(clusterToAddTo, marker); 254 | } else { 255 | var cluster = { 256 | markers: [marker], 257 | center: _leaflet2.default.latLng(pos), 258 | bounds: _leaflet2.default.latLngBounds() 259 | }; 260 | _this5.calculateClusterBounds(cluster); 261 | clusters.push(cluster); 262 | } 263 | return clusters; 264 | }, []); 265 | }; 266 | 267 | ClusterLayer.prototype.getClusterRefName = function getClusterRefName(index) { 268 | return 'cluster' + index; 269 | }; 270 | 271 | return ClusterLayer; 272 | }(_reactLeaflet.MapLayer); 273 | 274 | ClusterLayer.propTypes = { 275 | markers: _react2.default.PropTypes.array, 276 | clusterComponent: _react2.default.PropTypes.func.isRequired, 277 | propsForClusters: _react2.default.PropTypes.object, 278 | gridSize: _react2.default.PropTypes.number, 279 | minClusterSize: _react2.default.PropTypes.number 280 | }; 281 | exports.default = ClusterLayer; 282 | --------------------------------------------------------------------------------