hn-map 1.1.13 → 1.1.14
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 +35 -17
- package/package.json +1 -1
- package/src/base/siji_entity.ts +139 -118
package/dist/index.js
CHANGED
|
@@ -1775,17 +1775,23 @@
|
|
|
1775
1775
|
className: "my-popupAttr-class"
|
|
1776
1776
|
});
|
|
1777
1777
|
var handleClick = function handleClick(e) {
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1778
|
+
var features = _this.hnMap.map.map.queryRenderedFeatures(e.point);
|
|
1779
|
+
if (features.length > 0) {
|
|
1780
|
+
// 当前点击的第一层图形为当前图形时,才满足点击事件
|
|
1781
|
+
if (features[0].layer.id === _this.id) {
|
|
1782
|
+
// const data = e.features[0].properties;
|
|
1783
|
+
var data = _this.option.data;
|
|
1784
|
+
// 创建弹窗内容
|
|
1785
|
+
var content = "";
|
|
1786
|
+
for (var key in data) {
|
|
1787
|
+
content += "<div>".concat(key, ": ").concat(data[key], "</div>");
|
|
1788
|
+
}
|
|
1789
|
+
_this.infoWindow.setHTML(content);
|
|
1790
|
+
_this.infoWindow.setLngLat(e.lngLat).addTo(_this.hnMap.map.map);
|
|
1791
|
+
}
|
|
1784
1792
|
}
|
|
1785
|
-
_this.infoWindow.setHTML(content);
|
|
1786
|
-
_this.infoWindow.setLngLat(e.lngLat).addTo(_this.hnMap.map.map);
|
|
1787
1793
|
};
|
|
1788
|
-
this.hnMap.map.map.on("click", this.
|
|
1794
|
+
this.hnMap.map.map.on("click", this.id, handleClick);
|
|
1789
1795
|
}
|
|
1790
1796
|
// 添加自定义dom弹窗
|
|
1791
1797
|
}, {
|
|
@@ -1800,13 +1806,19 @@
|
|
|
1800
1806
|
className: "my-customPopup-class"
|
|
1801
1807
|
});
|
|
1802
1808
|
var handleClick = function handleClick(e) {
|
|
1803
|
-
var
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1809
|
+
var features = _this2.hnMap.map.map.queryRenderedFeatures(e.point);
|
|
1810
|
+
if (features.length > 0) {
|
|
1811
|
+
// 当前点击的第一层图形为当前图形时,才满足点击事件
|
|
1812
|
+
if (features[0].layer.id === _this2.id) {
|
|
1813
|
+
var data = _this2.option.data;
|
|
1814
|
+
// const data = e.features[0].properties;
|
|
1815
|
+
var dom = getCustomDom(data);
|
|
1816
|
+
_this2.infoWindow.setHTML(dom);
|
|
1817
|
+
_this2.infoWindow.setLngLat(e.lngLat).addTo(_this2.hnMap.map.map);
|
|
1818
|
+
}
|
|
1819
|
+
}
|
|
1808
1820
|
};
|
|
1809
|
-
this.hnMap.map.map.on("click", this.
|
|
1821
|
+
this.hnMap.map.map.on("click", this.id, handleClick);
|
|
1810
1822
|
}
|
|
1811
1823
|
// 弹窗删除
|
|
1812
1824
|
}, {
|
|
@@ -1856,8 +1868,14 @@
|
|
|
1856
1868
|
this.off(eventType);
|
|
1857
1869
|
switch (eventType) {
|
|
1858
1870
|
case "click":
|
|
1859
|
-
this.event[eventType] = function () {
|
|
1860
|
-
|
|
1871
|
+
this.event[eventType] = function (e) {
|
|
1872
|
+
var features = _this3.hnMap.map.map.queryRenderedFeatures(e.point);
|
|
1873
|
+
if (features.length > 0) {
|
|
1874
|
+
// 当前点击的第一层图形为当前图形时,才满足点击事件
|
|
1875
|
+
if (features[0].layer.id === _this3.id) {
|
|
1876
|
+
callback(_this3.option.data);
|
|
1877
|
+
}
|
|
1878
|
+
}
|
|
1861
1879
|
};
|
|
1862
1880
|
break;
|
|
1863
1881
|
}
|
package/package.json
CHANGED
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
|
}
|