hn-map 1.1.12 → 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 +41 -22
- package/package.json +1 -1
- package/src/base/siji_entity.ts +139 -117
package/dist/index.js
CHANGED
|
@@ -1756,6 +1756,7 @@
|
|
|
1756
1756
|
this.option = null;
|
|
1757
1757
|
this.type = null;
|
|
1758
1758
|
this.show = false;
|
|
1759
|
+
this.id = null;
|
|
1759
1760
|
this.hnMap = hnMap;
|
|
1760
1761
|
this.event = {};
|
|
1761
1762
|
this.show = false;
|
|
@@ -1774,17 +1775,23 @@
|
|
|
1774
1775
|
className: "my-popupAttr-class"
|
|
1775
1776
|
});
|
|
1776
1777
|
var handleClick = function handleClick(e) {
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
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
|
+
}
|
|
1783
1792
|
}
|
|
1784
|
-
_this.infoWindow.setHTML(content);
|
|
1785
|
-
_this.infoWindow.setLngLat(e.lngLat).addTo(_this.hnMap.map.map);
|
|
1786
1793
|
};
|
|
1787
|
-
this.hnMap.map.map.on("click", this.
|
|
1794
|
+
this.hnMap.map.map.on("click", this.id, handleClick);
|
|
1788
1795
|
}
|
|
1789
1796
|
// 添加自定义dom弹窗
|
|
1790
1797
|
}, {
|
|
@@ -1799,13 +1806,19 @@
|
|
|
1799
1806
|
className: "my-customPopup-class"
|
|
1800
1807
|
});
|
|
1801
1808
|
var handleClick = function handleClick(e) {
|
|
1802
|
-
var
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
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
|
+
}
|
|
1807
1820
|
};
|
|
1808
|
-
this.hnMap.map.map.on("click", this.
|
|
1821
|
+
this.hnMap.map.map.on("click", this.id, handleClick);
|
|
1809
1822
|
}
|
|
1810
1823
|
// 弹窗删除
|
|
1811
1824
|
}, {
|
|
@@ -1850,23 +1863,29 @@
|
|
|
1850
1863
|
}
|
|
1851
1864
|
}, {
|
|
1852
1865
|
key: "on",
|
|
1853
|
-
value: function on(eventType,
|
|
1866
|
+
value: function on(eventType, callback) {
|
|
1854
1867
|
var _this3 = this;
|
|
1855
|
-
this.off(eventType
|
|
1868
|
+
this.off(eventType);
|
|
1856
1869
|
switch (eventType) {
|
|
1857
1870
|
case "click":
|
|
1858
|
-
this.event[eventType] = function () {
|
|
1859
|
-
|
|
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
|
+
}
|
|
1860
1879
|
};
|
|
1861
1880
|
break;
|
|
1862
1881
|
}
|
|
1863
|
-
this.hnMap.map.map.on(eventType,
|
|
1882
|
+
this.hnMap.map.map.on(eventType, this.id, this.event[eventType]);
|
|
1864
1883
|
} // 监听事件
|
|
1865
1884
|
}, {
|
|
1866
1885
|
key: "off",
|
|
1867
|
-
value: function off(eventType
|
|
1886
|
+
value: function off(eventType) {
|
|
1868
1887
|
if (this.event[eventType]) {
|
|
1869
|
-
this.hnMap.map.map.off(eventType,
|
|
1888
|
+
this.hnMap.map.map.off(eventType, this.id, this.event[eventType]);
|
|
1870
1889
|
delete this.event[eventType];
|
|
1871
1890
|
}
|
|
1872
1891
|
}
|
package/package.json
CHANGED
package/src/base/siji_entity.ts
CHANGED
|
@@ -1,125 +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
|
-
addPopupByAttr() {
|
|
20
|
-
// 如果已有弹窗,先关闭
|
|
21
|
-
this.removePopup();
|
|
22
|
-
|
|
23
|
-
this.infoWindow = new SGMap.Popup({
|
|
24
|
-
offset: { bottom: [0, 0] },
|
|
25
|
-
className: "my-popupAttr-class",
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
const handleClick = (e: any) => {
|
|
29
|
-
// const data = e.features[0].properties;
|
|
30
|
-
const data = this.option.data;
|
|
31
|
-
// 创建弹窗内容
|
|
32
|
-
let content = "";
|
|
33
|
-
for (const key in data) {
|
|
34
|
-
content += `<div>${key}: ${data[key]}</div>`;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
this.infoWindow.setHTML(content);
|
|
38
|
-
this.infoWindow.setLngLat(e.lngLat).addTo(this.hnMap.map.map);
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
this.hnMap.map.map.on("click", this.config.id, handleClick);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// 添加自定义dom弹窗
|
|
45
|
-
addCustomPopup(getCustomDom: any) {
|
|
46
|
-
this.removePopup();
|
|
47
|
-
this.infoWindow = new SGMap.Popup({
|
|
48
|
-
offset: { bottom: [0, 0] },
|
|
49
|
-
className: "my-customPopup-class",
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
const handleClick = (e: any) => {
|
|
53
|
-
const data = this.option.data;
|
|
54
|
-
// const data = e.features[0].properties;
|
|
55
|
-
const dom = getCustomDom(data);
|
|
56
|
-
this.infoWindow.setHTML(dom);
|
|
57
|
-
this.infoWindow.setLngLat(e.lngLat).addTo(this.hnMap.map.map);
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
this.hnMap.map.map.on("click", this.config.id, handleClick);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// 弹窗删除
|
|
64
|
-
removePopup() {
|
|
65
|
-
if (this.infoWindow) {
|
|
66
|
-
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;
|
|
67
18
|
}
|
|
68
|
-
|
|
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
|
-
|
|
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);
|
|
94
52
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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
|
+
}
|
|
113
74
|
};
|
|
114
|
-
|
|
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
|
+
}
|
|
115
84
|
}
|
|
116
|
-
this.hnMap.map.map.on(eventType, eventId, this.event[eventType]);
|
|
117
|
-
} // 监听事件
|
|
118
85
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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
|
+
}
|
|
123
146
|
}
|
|
124
|
-
}
|
|
125
147
|
}
|