1+ import React from 'react' ;
2+
3+ // const configurableProps = [
4+ // 'radius',
5+ // 'gradient',
6+ // 'opacity',
7+ // 'zooms',
8+
9+ // 'visible',
10+ // 'dataset',
11+ // ]
12+ // const allProps = configurableProps;
13+
14+ // const defaultProps = {
15+ // radius: 30,
16+ // }
17+
18+ class Heatmap extends React . Component {
19+ constructor ( props ) {
20+ super ( prpos ) ;
21+ if ( typeof window !== 'undefined' ) {
22+ if ( ! props . __map__ ) {
23+ throw new Error ( 'Heatmap has to be a child of Map component' ) ;
24+ } else {
25+ this . map = props . __map__ ;
26+ this . element = props . __ele__ ;
27+ this . createHeatmap ( props ) . then ( ( ) => {
28+ // 初始化创建的时候,如果 visible 为 false 隐藏
29+ if ( ( typeof props . visible === 'boolean' ) && ! props . visible ) {
30+ this . heatmap . hide ( ) ;
31+ }
32+ if ( 'dataSet' in props ) {
33+ this . heatmap . setDataSet ( props . dataSet ) ;
34+ }
35+ } ) ;
36+ }
37+ }
38+ }
39+
40+ shouldComponentUpdate ( ) {
41+ return false ;
42+ }
43+
44+ componentWillReceiveProps ( nextProps , props ) {
45+
46+ }
47+
48+ createHeatmap ( props ) {
49+ if ( this . heatmap ) {
50+ return new Promise ( ( resolve ) => {
51+ resolve ( this . heatmap ) ;
52+ } ) ;
53+ } else {
54+ return new Promise ( ( resolve ) => {
55+ this . map . plugin ( [ 'AMap.Heatmap' ] , ( ) => {
56+ const heatmapOptions = this . buildInitOptions ( props ) ;
57+ this . heatmap = new window . AMap . Heatmap ( this . map , heatmapOptions ) ;
58+ resolve ( this . heatmap ) ;
59+ } ) ;
60+ } ) ;
61+ }
62+ }
63+
64+ buildInitOptions ( props ) {
65+ const opts = { } ;
66+ [ 'radius' , 'gradient' , 'opacity' , 'zooms' ] . forEach ( ( key ) => {
67+ if ( key in props ) {
68+ opts [ key ] = props [ key ] ;
69+ }
70+ } ) ;
71+ return opts ;
72+ }
73+
74+ render ( ) {
75+ return null ;
76+ }
77+ }
78+
79+ export default Heatmap ;
0 commit comments