1+ ( function ( global , factory ) {
2+ if ( typeof define === "function" && define . amd ) {
3+ define ( [ 'exports' , 'react' , '../lib/String' ] , factory ) ;
4+ } else if ( typeof exports !== "undefined" ) {
5+ factory ( exports , require ( 'react' ) , require ( '../lib/String' ) ) ;
6+ } else {
7+ var mod = {
8+ exports : { }
9+ } ;
10+ factory ( mod . exports , global . react , global . String ) ;
11+ global . HeatMap = mod . exports ;
12+ }
13+ } ) ( this , function ( exports , _react , _String ) {
14+ 'use strict' ;
15+
16+ Object . defineProperty ( exports , "__esModule" , {
17+ value : true
18+ } ) ;
19+ exports . HeatMap = undefined ;
20+
21+ var _react2 = _interopRequireDefault ( _react ) ;
22+
23+ function _interopRequireDefault ( obj ) {
24+ return obj && obj . __esModule ? obj : {
25+ default : obj
26+ } ;
27+ }
28+
29+ function _classCallCheck ( instance , Constructor ) {
30+ if ( ! ( instance instanceof Constructor ) ) {
31+ throw new TypeError ( "Cannot call a class as a function" ) ;
32+ }
33+ }
34+
35+ var _createClass = function ( ) {
36+ function defineProperties ( target , props ) {
37+ for ( var i = 0 ; i < props . length ; i ++ ) {
38+ var descriptor = props [ i ] ;
39+ descriptor . enumerable = descriptor . enumerable || false ;
40+ descriptor . configurable = true ;
41+ if ( "value" in descriptor ) descriptor . writable = true ;
42+ Object . defineProperty ( target , descriptor . key , descriptor ) ;
43+ }
44+ }
45+
46+ return function ( Constructor , protoProps , staticProps ) {
47+ if ( protoProps ) defineProperties ( Constructor . prototype , protoProps ) ;
48+ if ( staticProps ) defineProperties ( Constructor , staticProps ) ;
49+ return Constructor ;
50+ } ;
51+ } ( ) ;
52+
53+ function _possibleConstructorReturn ( self , call ) {
54+ if ( ! self ) {
55+ throw new ReferenceError ( "this hasn't been initialised - super() hasn't been called" ) ;
56+ }
57+
58+ return call && ( typeof call === "object" || typeof call === "function" ) ? call : self ;
59+ }
60+
61+ function _inherits ( subClass , superClass ) {
62+ if ( typeof superClass !== "function" && superClass !== null ) {
63+ throw new TypeError ( "Super expression must either be null or a function, not " + typeof superClass ) ;
64+ }
65+
66+ subClass . prototype = Object . create ( superClass && superClass . prototype , {
67+ constructor : {
68+ value : subClass ,
69+ enumerable : false ,
70+ writable : true ,
71+ configurable : true
72+ }
73+ } ) ;
74+ if ( superClass ) Object . setPrototypeOf ? Object . setPrototypeOf ( subClass , superClass ) : subClass . __proto__ = superClass ;
75+ }
76+
77+ var evtNames = [ 'click' , 'mouseover' , 'recenter' ] ;
78+
79+ var wrappedPromise = function wrappedPromise ( ) {
80+ var wrappedPromise = { } ,
81+ promise = new Promise ( function ( resolve , reject ) {
82+ wrappedPromise . resolve = resolve ;
83+ wrappedPromise . reject = reject ;
84+ } ) ;
85+ wrappedPromise . then = promise . then . bind ( promise ) ;
86+ wrappedPromise . catch = promise . catch . bind ( promise ) ;
87+ wrappedPromise . promise = promise ;
88+
89+ return wrappedPromise ;
90+ } ;
91+
92+ var HeatMap = exports . HeatMap = function ( _React$Component ) {
93+ _inherits ( HeatMap , _React$Component ) ;
94+
95+ function HeatMap ( ) {
96+ _classCallCheck ( this , HeatMap ) ;
97+
98+ return _possibleConstructorReturn ( this , ( HeatMap . __proto__ || Object . getPrototypeOf ( HeatMap ) ) . apply ( this , arguments ) ) ;
99+ }
100+
101+ _createClass ( HeatMap , [ {
102+ key : 'componentDidMount' ,
103+ value : function componentDidMount ( ) {
104+ this . heatMapPromise = wrappedPromise ( ) ;
105+ this . renderHeatMap ( ) ;
106+ }
107+ } , {
108+ key : 'componentDidUpdate' ,
109+ value : function componentDidUpdate ( prevProps ) {
110+ if ( this . props . map !== prevProps . map || this . props . position !== prevProps . position ) {
111+ if ( this . heatMap ) {
112+ this . heatMap . setMap ( null ) ;
113+ this . renderHeatMap ( ) ;
114+ }
115+ }
116+ }
117+ } , {
118+ key : 'componentWillUnmount' ,
119+ value : function componentWillUnmount ( ) {
120+ if ( this . heatMap ) {
121+ this . heatMap . setMap ( null ) ;
122+ }
123+ }
124+ } , {
125+ key : 'renderHeatMap' ,
126+ value : function renderHeatMap ( ) {
127+ var _this2 = this ;
128+
129+ var _props = this . props ,
130+ map = _props . map ,
131+ google = _props . google ,
132+ positions = _props . positions ,
133+ mapCenter = _props . mapCenter ,
134+ icon = _props . icon ,
135+ gradient = _props . gradient ,
136+ radius = _props . radius ,
137+ opacity = _props . opacity ;
138+
139+
140+ if ( ! google ) {
141+ return null ;
142+ }
143+
144+ positions = positions . map ( function ( pos ) {
145+ return new google . maps . LatLng ( pos . lat , pos . lng ) ;
146+ } ) ;
147+
148+ var pref = {
149+ map : map ,
150+ data : positions
151+ } ;
152+
153+ this . heatMap = new google . maps . visualization . HeatmapLayer ( pref ) ;
154+
155+ this . heatMap . set ( 'gradient' , gradient ) ;
156+
157+ this . heatMap . set ( 'radius' , radius === undefined ? 20 : radius ) ;
158+
159+ this . heatMap . set ( 'opacity' , opacity === undefined ? 0.2 : opacity ) ;
160+
161+ evtNames . forEach ( function ( e ) {
162+ _this2 . heatMap . addListener ( e , _this2 . handleEvent ( e ) ) ;
163+ } ) ;
164+
165+ this . heatMapPromise . resolve ( this . heatMap ) ;
166+ }
167+ } , {
168+ key : 'getHeatMap' ,
169+ value : function getHeatMap ( ) {
170+ return this . heatMapPromise ;
171+ }
172+ } , {
173+ key : 'handleEvent' ,
174+ value : function handleEvent ( evt ) {
175+ var _this3 = this ;
176+
177+ return function ( e ) {
178+ var evtName = 'on' + ( 0 , _String . camelize ) ( evt ) ;
179+ if ( _this3 . props [ evtName ] ) {
180+ _this3 . props [ evtName ] ( _this3 . props , _this3 . heatMap , e ) ;
181+ }
182+ } ;
183+ }
184+ } , {
185+ key : 'render' ,
186+ value : function render ( ) {
187+ return null ;
188+ }
189+ } ] ) ;
190+
191+ return HeatMap ;
192+ } ( _react2 . default . Component ) ;
193+
194+ HeatMap . propTypes = {
195+ position : _react . PropTypes . object ,
196+ map : _react . PropTypes . object ,
197+ icon : _react . PropTypes . string
198+ } ;
199+
200+ evtNames . forEach ( function ( e ) {
201+ return HeatMap . propTypes [ e ] = _react . PropTypes . func ;
202+ } ) ;
203+
204+ HeatMap . defaultProps = {
205+ name : 'HeatMap'
206+ } ;
207+
208+ exports . default = HeatMap ;
209+ } ) ;
0 commit comments