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