Skip to content

Commit b12a53c

Browse files
committed
first commit
0 parents commit b12a53c

File tree

5 files changed

+101
-0
lines changed

5 files changed

+101
-0
lines changed

.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["es2015"]
3+
}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
lib/
2+
node_modules/

.npmignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
src/
2+
node_modules/

package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "react-amap-plugin-heatmap",
3+
"version": "0.0.1",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"build": "babel src -d lib",
8+
"test": "echo \"Error: no test specified\" && exit 1"
9+
},
10+
"author": "ohislh@gmail.com",
11+
"license": "MIT",
12+
"devDependencies": {
13+
"babel-preset-es2015": "^6.24.1"
14+
}
15+
}

src/index.js

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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

Comments
 (0)