hn-map 1.1.13 → 1.1.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +240 -82
- package/package.json +1 -1
- package/src/base/mars3d_entity.ts +0 -2
- package/src/base/siji_entity.ts +139 -118
- package/src/graphic/polygon.ts +1 -1
- package/src/layer/cluster.ts +421 -247
- package/src/layer/heatMap.ts +0 -3
- package/src/layer/layer.ts +30 -2
- package/src/layer/pointCloud.ts +4 -3
- package/src/map.ts +17 -18
- package/src/util.ts +200 -196
package/src/base/siji_entity.ts
CHANGED
|
@@ -1,126 +1,147 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {deepMerge} from "../util";
|
|
2
|
+
|
|
2
3
|
export default class siji_entity {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// 添加属性弹窗
|
|
20
|
-
addPopupByAttr() {
|
|
21
|
-
// 如果已有弹窗,先关闭
|
|
22
|
-
this.removePopup();
|
|
23
|
-
|
|
24
|
-
this.infoWindow = new SGMap.Popup({
|
|
25
|
-
offset: { bottom: [0, 0] },
|
|
26
|
-
className: "my-popupAttr-class",
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
const handleClick = (e: any) => {
|
|
30
|
-
// const data = e.features[0].properties;
|
|
31
|
-
const data = this.option.data;
|
|
32
|
-
// 创建弹窗内容
|
|
33
|
-
let content = "";
|
|
34
|
-
for (const key in data) {
|
|
35
|
-
content += `<div>${key}: ${data[key]}</div>`;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
this.infoWindow.setHTML(content);
|
|
39
|
-
this.infoWindow.setLngLat(e.lngLat).addTo(this.hnMap.map.map);
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
this.hnMap.map.map.on("click", this.config.id, handleClick);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// 添加自定义dom弹窗
|
|
46
|
-
addCustomPopup(getCustomDom: any) {
|
|
47
|
-
this.removePopup();
|
|
48
|
-
this.infoWindow = new SGMap.Popup({
|
|
49
|
-
offset: { bottom: [0, 0] },
|
|
50
|
-
className: "my-customPopup-class",
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
const handleClick = (e: any) => {
|
|
54
|
-
const data = this.option.data;
|
|
55
|
-
// const data = e.features[0].properties;
|
|
56
|
-
const dom = getCustomDom(data);
|
|
57
|
-
this.infoWindow.setHTML(dom);
|
|
58
|
-
this.infoWindow.setLngLat(e.lngLat).addTo(this.hnMap.map.map);
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
this.hnMap.map.map.on("click", this.config.id, handleClick);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// 弹窗删除
|
|
65
|
-
removePopup() {
|
|
66
|
-
if (this.infoWindow) {
|
|
67
|
-
this.infoWindow.remove();
|
|
4
|
+
event: any = {};
|
|
5
|
+
infoWindow: any = null;
|
|
6
|
+
hnMap: any = null;
|
|
7
|
+
config: any = null;
|
|
8
|
+
graphic: any = null;
|
|
9
|
+
option: any = null;
|
|
10
|
+
type: any = null;
|
|
11
|
+
show: boolean = false;
|
|
12
|
+
id: any = null
|
|
13
|
+
|
|
14
|
+
constructor(hnMap: any) {
|
|
15
|
+
this.hnMap = hnMap;
|
|
16
|
+
this.event = {};
|
|
17
|
+
this.show = false;
|
|
68
18
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
19
|
+
|
|
20
|
+
// 添加属性弹窗
|
|
21
|
+
addPopupByAttr() {
|
|
22
|
+
// 如果已有弹窗,先关闭
|
|
23
|
+
this.removePopup();
|
|
24
|
+
|
|
25
|
+
this.infoWindow = new SGMap.Popup({
|
|
26
|
+
offset: {bottom: [0, 0]},
|
|
27
|
+
className: "my-popupAttr-class",
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const handleClick = (e: any) => {
|
|
31
|
+
|
|
32
|
+
const features = this.hnMap.map.map.queryRenderedFeatures(e.point);
|
|
33
|
+
if (features.length > 0) {
|
|
34
|
+
// 当前点击的第一层图形为当前图形时,才满足点击事件
|
|
35
|
+
if (features[0].layer.id === this.id) {
|
|
36
|
+
// const data = e.features[0].properties;
|
|
37
|
+
const data = this.option.data;
|
|
38
|
+
// 创建弹窗内容
|
|
39
|
+
let content = "";
|
|
40
|
+
for (const key in data) {
|
|
41
|
+
content += `<div>${key}: ${data[key]}</div>`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
this.infoWindow.setHTML(content);
|
|
45
|
+
this.infoWindow.setLngLat(e.lngLat).addTo(this.hnMap.map.map);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
this.hnMap.map.map.on("click", this.id, handleClick);
|
|
95
52
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
53
|
+
|
|
54
|
+
// 添加自定义dom弹窗
|
|
55
|
+
addCustomPopup(getCustomDom: any) {
|
|
56
|
+
this.removePopup();
|
|
57
|
+
this.infoWindow = new SGMap.Popup({
|
|
58
|
+
offset: {bottom: [0, 0]},
|
|
59
|
+
className: "my-customPopup-class",
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const handleClick = (e: any) => {
|
|
63
|
+
const features = this.hnMap.map.map.queryRenderedFeatures(e.point);
|
|
64
|
+
if (features.length > 0) {
|
|
65
|
+
// 当前点击的第一层图形为当前图形时,才满足点击事件
|
|
66
|
+
if (features[0].layer.id === this.id) {
|
|
67
|
+
const data = this.option.data;
|
|
68
|
+
// const data = e.features[0].properties;
|
|
69
|
+
const dom = getCustomDom(data);
|
|
70
|
+
this.infoWindow.setHTML(dom);
|
|
71
|
+
this.infoWindow.setLngLat(e.lngLat).addTo(this.hnMap.map.map);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
114
74
|
};
|
|
115
|
-
|
|
75
|
+
|
|
76
|
+
this.hnMap.map.map.on("click", this.id, handleClick);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// 弹窗删除
|
|
80
|
+
removePopup() {
|
|
81
|
+
if (this.infoWindow) {
|
|
82
|
+
this.infoWindow.remove();
|
|
83
|
+
}
|
|
116
84
|
}
|
|
117
|
-
this.hnMap.map.map.on(eventType, this.id, this.event[eventType]);
|
|
118
|
-
} // 监听事件
|
|
119
85
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
86
|
+
flyTo(option: any = {}) {
|
|
87
|
+
deepMerge(this.option, option);
|
|
88
|
+
let zoom = this.hnMap.map.map.getZoom();
|
|
89
|
+
let center;
|
|
90
|
+
if (this.option.center) {
|
|
91
|
+
center = this.option.center;
|
|
92
|
+
} else {
|
|
93
|
+
if (
|
|
94
|
+
this.type == "line" ||
|
|
95
|
+
this.type == "dash" ||
|
|
96
|
+
this.type == "flicker" ||
|
|
97
|
+
this.type == "flow" ||
|
|
98
|
+
this.type == "arrow" ||
|
|
99
|
+
this.type == "mapLabel" ||
|
|
100
|
+
this.type == "rectangle"
|
|
101
|
+
) {
|
|
102
|
+
center = this.option.position[0];
|
|
103
|
+
} else if (this.type == "route") {
|
|
104
|
+
center = [this.option.position[0][0], this.option.position[0][1]];
|
|
105
|
+
} else if (this.type == "polygon") {
|
|
106
|
+
center = this.option.position[0][0];
|
|
107
|
+
} else {
|
|
108
|
+
center = this.option.position;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
this.hnMap.map.map.flyTo({
|
|
112
|
+
duration: 1000, // 持续时间
|
|
113
|
+
zoom: this.option.zoom || zoom,
|
|
114
|
+
center: center,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
destroy() {
|
|
119
|
+
this.hnMap.map.map.removeLayer(this.config.id);
|
|
120
|
+
this.hnMap.map.map.removeSource(this.config.id);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
on(eventType: any, callback: any) {
|
|
124
|
+
this.off(eventType);
|
|
125
|
+
switch (eventType) {
|
|
126
|
+
case "click":
|
|
127
|
+
this.event[eventType] = (e:any) => {
|
|
128
|
+
const features = this.hnMap.map.map.queryRenderedFeatures(e.point);
|
|
129
|
+
if (features.length > 0) {
|
|
130
|
+
// 当前点击的第一层图形为当前图形时,才满足点击事件
|
|
131
|
+
if (features[0].layer.id === this.id) {
|
|
132
|
+
callback(this.option.data);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
this.hnMap.map.map.on(eventType, this.id, this.event[eventType]);
|
|
139
|
+
} // 监听事件
|
|
140
|
+
|
|
141
|
+
off(eventType: any) {
|
|
142
|
+
if (this.event[eventType]) {
|
|
143
|
+
this.hnMap.map.map.off(eventType, this.id, this.event[eventType]);
|
|
144
|
+
delete this.event[eventType];
|
|
145
|
+
}
|
|
124
146
|
}
|
|
125
|
-
}
|
|
126
147
|
}
|
package/src/graphic/polygon.ts
CHANGED
|
@@ -166,7 +166,7 @@ export default (hnMap: any) => {
|
|
|
166
166
|
type: "Feature",
|
|
167
167
|
geometry: {
|
|
168
168
|
type: "Polygon",
|
|
169
|
-
coordinates: convertPosition(option.position), //三层数组[[[0,0],[0,0]]]
|
|
169
|
+
coordinates: convertPosition(this.option.position), //三层数组[[[0,0],[0,0]]]
|
|
170
170
|
},
|
|
171
171
|
},
|
|
172
172
|
],
|