forked from huiyan-fe/react-bmap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
point-label.js
84 lines (70 loc) · 1.93 KB
/
point-label.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
* @file 文本标注组件
* @author kyle([email protected])
*/
import React from 'react';
import { render } from 'react-dom';
import Component from './component';
import DraggingTip from '../overlay/DraggingTip';
export default class PointLabel extends Component {
constructor(args) {
super(args);
this.state = {
};
this.tips = [];
}
/**
* 设置默认的props属性
*/
static get defaultProps() {
return {
}
}
componentDidUpdate(prevProps) {
this.initialize();
}
componentDidMount() {
this.initialize();
}
componentWillUnmount() {
this.destroy();
}
destroy() {
this.tips.forEach((tip) => {
tip.hide();
});
this.tips = [];
}
initialize() {
var map = this.props.map;
if (!map) {
return;
}
this.destroy();
if (this.props.data) {
var points = [];
this.props.data.forEach((item, index) => {
var tip = new DraggingTip({
isShowTipArrow: true,
changePosition: (point) => {
this.props.changePosition && this.props.changePosition(point, index);
},
map: map,
numberDirection: item.numberDirection,
isShowNumber: item.isShowNumber,
point: item.point,
name: item.name,
index: item.index !== undefined ? item.index : index + 1,
color: item.color,
change: function() {}
});
points.push(item.point);
tip.show();
this.tips.push(tip);
});
if (this.props.autoViewport) {
map.setViewport(points, this.props.viewportOptions);
}
}
}
}