hn-map 1.1.2 → 1.1.3
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 +78 -21
- package/package.json +1 -1
- package/src/base/siji_entity.ts +22 -15
- package/src/graphic/imagePoint.ts +38 -7
- package/src/graphic/numPoint.ts +12 -8
- package/src/graphic/point.ts +2 -2
- package/src/index.ts +164 -160
- package/src/layer/layer.ts +430 -415
- package/src/map.ts +394 -388
- package/src/other/geocodingTask.ts +120 -0
package/src/layer/layer.ts
CHANGED
|
@@ -1,464 +1,479 @@
|
|
|
1
|
-
import {deepMerge} from "../util";
|
|
1
|
+
import { deepMerge } from "../util";
|
|
2
2
|
|
|
3
3
|
export default (hnMap: any) => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
4
|
+
const defaultOption = {};
|
|
5
|
+
|
|
6
|
+
class mars3d_class {
|
|
7
|
+
type: any = "layer";
|
|
8
|
+
id: any = null;
|
|
9
|
+
option: any = JSON.parse(JSON.stringify(defaultOption));
|
|
10
|
+
config: any = null;
|
|
11
|
+
children: any = null;
|
|
12
|
+
layerEntity: any = null;
|
|
13
|
+
|
|
14
|
+
constructor(option: any) {
|
|
15
|
+
this.id = option.id;
|
|
16
|
+
this.children = [];
|
|
17
|
+
deepMerge(this.option, option);
|
|
18
|
+
this.config = this.formatConfig(this.option);
|
|
19
|
+
this.layerEntity = new mars3d.layer.GraphicLayer(this.config); // 创建图层
|
|
20
|
+
}
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
formatConfig(option: any) {
|
|
23
|
+
return option;
|
|
24
|
+
}
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
getEntity(id: any) {
|
|
27
|
+
return this.children.find((v: any) => v.id === id);
|
|
28
|
+
}
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
}
|
|
30
|
+
addEntity(entity: any) {
|
|
31
|
+
if (this.children.find((v: any) => v.id === entity.id)) {
|
|
32
|
+
console.error("已存在同名图形" + entity.id);
|
|
33
|
+
} else {
|
|
34
|
+
this.children.push(entity);
|
|
35
|
+
this.layerEntity.addGraphic(entity.graphic); // 添加图形
|
|
36
|
+
if (entity.type == "route") {
|
|
37
|
+
entity.start();
|
|
40
38
|
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
42
|
+
removeEntity(entityParam: any) {
|
|
43
|
+
const entity = this.getEntity(entityParam);
|
|
44
|
+
if (entity) {
|
|
45
|
+
this.layerEntity.removeGraphic(entity.graphic);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
49
|
+
clearEntity() {
|
|
50
|
+
this.children.forEach((v: any) => v.destroy());
|
|
51
|
+
this.children = [];
|
|
52
|
+
this.layerEntity.clear();
|
|
53
|
+
}
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
55
|
+
destroy() {
|
|
56
|
+
this.clearEntity();
|
|
57
|
+
this.layerEntity.remove(true);
|
|
58
|
+
hnMap.map.layerList = hnMap.map.layerList.filter(
|
|
59
|
+
(v: any) => v.id !== this.id
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
62
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
show() {
|
|
64
|
+
this.layerEntity.show = true;
|
|
65
|
+
}
|
|
66
66
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
hide() {
|
|
68
|
+
this.layerEntity.show = false;
|
|
69
|
+
}
|
|
70
70
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
flyTo() {
|
|
72
|
+
this.layerEntity.flyTo();
|
|
73
|
+
}
|
|
74
74
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
75
|
+
/**
|
|
76
|
+
* 飞向指定的多个图形
|
|
77
|
+
* @param entities
|
|
78
|
+
*/
|
|
79
|
+
flyToCustomEntities(entities: any) {
|
|
80
|
+
// 计算所有线的最小最大坐标
|
|
81
|
+
let minLon = 180,
|
|
82
|
+
maxLon = -180,
|
|
83
|
+
minLat = 90,
|
|
84
|
+
maxLat = -90;
|
|
85
|
+
|
|
86
|
+
entities.forEach((line: any) => {
|
|
87
|
+
line.graphic.positions.forEach((pos: any) => {
|
|
88
|
+
const carto = mars3d.Cesium.Cartographic.fromCartesian(pos);
|
|
89
|
+
const lon = mars3d.Cesium.Math.toDegrees(carto.longitude);
|
|
90
|
+
const lat = mars3d.Cesium.Math.toDegrees(carto.latitude);
|
|
91
|
+
|
|
92
|
+
minLon = Math.min(minLon, lon);
|
|
93
|
+
maxLon = Math.max(maxLon, lon);
|
|
94
|
+
minLat = Math.min(minLat, lat);
|
|
95
|
+
maxLat = Math.max(maxLat, lat);
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
// 飞到这个矩形范围
|
|
100
|
+
hnMap.map.map.flyToExtent({
|
|
101
|
+
xmin: minLon,
|
|
102
|
+
xmax: maxLon,
|
|
103
|
+
ymin: minLat,
|
|
104
|
+
ymax: maxLat,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
107
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
108
|
+
// 添加属性弹窗
|
|
109
|
+
addPopupByAttr() {
|
|
110
|
+
this.layerEntity.bindPopup((event: any) => {
|
|
111
|
+
console.log(event.graphic, "====event.graphic==");
|
|
112
|
+
if (event.graphic.attr) {
|
|
113
|
+
const data = event.graphic.attr;
|
|
114
|
+
return mars3d.Util.getTemplateHtml({
|
|
115
|
+
title: "详情",
|
|
116
|
+
template: "all",
|
|
117
|
+
attr: data,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
122
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
123
|
+
// 添加自定义dom弹窗
|
|
124
|
+
addCustomPopup(getCustomDom: any, option = { offsetY: -20 }) {
|
|
125
|
+
this.layerEntity.bindPopup(async (event: any) => {
|
|
126
|
+
if (event.graphic.attr) {
|
|
127
|
+
const data = event.graphic.attr || {};
|
|
128
|
+
const dom = await getCustomDom(data);
|
|
129
|
+
if (dom) {
|
|
130
|
+
return dom;
|
|
131
|
+
} else {
|
|
132
|
+
hnMap.map.closePopup();
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}, option);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
class gaode_class {
|
|
140
|
+
id: any = null;
|
|
141
|
+
option: any = JSON.parse(JSON.stringify(defaultOption));
|
|
142
|
+
config: any = null;
|
|
143
|
+
children: any = null;
|
|
144
|
+
layerEntity: any = null;
|
|
145
|
+
// 创建全局信息窗口实例
|
|
146
|
+
propsInfoWindow: any = null;
|
|
147
|
+
customInfoWindow: any = null;
|
|
148
|
+
getCustomDom: any = null;
|
|
149
|
+
|
|
150
|
+
constructor(option: any) {
|
|
151
|
+
this.id = option.id;
|
|
152
|
+
this.children = [];
|
|
153
|
+
deepMerge(this.option, option);
|
|
154
|
+
this.config = this.formatConfig(this.option);
|
|
155
|
+
this.layerEntity = new AMap.OverlayGroup([]); // 创建图层
|
|
156
|
+
this.layerEntity.id = option.id;
|
|
137
157
|
}
|
|
138
158
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
config: any = null;
|
|
143
|
-
children: any = null;
|
|
144
|
-
layerEntity: any = null;
|
|
145
|
-
// 创建全局信息窗口实例
|
|
146
|
-
propsInfoWindow: any = null;
|
|
147
|
-
customInfoWindow: any = null;
|
|
148
|
-
getCustomDom: any = null;
|
|
149
|
-
|
|
150
|
-
constructor(option: any) {
|
|
151
|
-
this.id = option.id;
|
|
152
|
-
this.children = [];
|
|
153
|
-
deepMerge(this.option, option);
|
|
154
|
-
this.config = this.formatConfig(this.option);
|
|
155
|
-
this.layerEntity = new AMap.OverlayGroup([]); // 创建图层
|
|
156
|
-
this.layerEntity.id = option.id;
|
|
157
|
-
}
|
|
159
|
+
formatConfig(option: any) {
|
|
160
|
+
return option;
|
|
161
|
+
}
|
|
158
162
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
163
|
+
getEntity(entityParam: any) {
|
|
164
|
+
return this.children.find((v: any) => v.id === entityParam);
|
|
165
|
+
}
|
|
162
166
|
|
|
163
|
-
|
|
164
|
-
|
|
167
|
+
addEntity(entity: any) {
|
|
168
|
+
if (this.children.find((v: any) => v.id === entity.id)) {
|
|
169
|
+
console.error("已存在同名图形" + entity.id);
|
|
170
|
+
} else {
|
|
171
|
+
alert(entity.id);
|
|
172
|
+
this.children.push(entity);
|
|
173
|
+
this.layerEntity.addOverlay(entity.graphic); // 添加图形
|
|
174
|
+
|
|
175
|
+
// 图层添加新图形后,需要重新调用绑定点击弹窗方法
|
|
176
|
+
if (this.propsInfoWindow) {
|
|
177
|
+
this.addPopupByAttr();
|
|
165
178
|
}
|
|
166
179
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
console.error("已存在同名图形" + entity.id);
|
|
170
|
-
} else {
|
|
171
|
-
this.children.push(entity);
|
|
172
|
-
this.layerEntity.addOverlay(entity.graphic); // 添加图形
|
|
173
|
-
|
|
174
|
-
// 图层添加新图形后,需要重新调用绑定点击弹窗方法
|
|
175
|
-
if (this.propsInfoWindow) {
|
|
176
|
-
this.addPopupByAttr();
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
if (this.customInfoWindow) {
|
|
180
|
-
// this.addCustomPopup()
|
|
181
|
-
}
|
|
182
|
-
}
|
|
180
|
+
if (this.customInfoWindow) {
|
|
181
|
+
// this.addCustomPopup()
|
|
183
182
|
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
184
185
|
|
|
185
|
-
|
|
186
|
-
|
|
186
|
+
removeEntity(entityParam: any) {
|
|
187
|
+
const entity = this.getEntity(entityParam);
|
|
187
188
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
189
|
+
if (entity) {
|
|
190
|
+
this.children = this.children.filter((v: any): any => {
|
|
191
|
+
return v.id !== entity.id;
|
|
192
|
+
});
|
|
192
193
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
194
|
+
this.layerEntity.removeOverlay(entity.graphic);
|
|
195
|
+
entity.destroy();
|
|
196
|
+
}
|
|
197
|
+
}
|
|
197
198
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
199
|
+
clearEntity() {
|
|
200
|
+
this.children = [];
|
|
201
|
+
this.layerEntity.clearOverlays();
|
|
202
|
+
}
|
|
202
203
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
204
|
+
destroy() {
|
|
205
|
+
this.clearEntity();
|
|
206
|
+
hnMap.map.map.remove(this.layerEntity);
|
|
207
|
+
hnMap.map.layerList = hnMap.map.layerList.filter(
|
|
208
|
+
(v: any) => v.id !== this.id
|
|
209
|
+
);
|
|
210
|
+
}
|
|
210
211
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
212
|
+
// 添加属性弹窗
|
|
213
|
+
addPopupByAttr() {
|
|
214
|
+
if (!this.propsInfoWindow) {
|
|
215
|
+
this.propsInfoWindow = new AMap.InfoWindow({
|
|
216
|
+
offset: new AMap.Pixel(0, -30),
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
const handleClick = (e: any) => {
|
|
220
|
+
const overlay = e.target; // 获取被点击的具体覆盖物
|
|
221
|
+
const data = overlay.getOptions().extData.data;
|
|
222
|
+
let content = "";
|
|
223
|
+
for (const key in data) {
|
|
224
|
+
content += `<div>${key}: ${data[key]}</div>`;
|
|
225
|
+
}
|
|
226
|
+
this.propsInfoWindow.setContent(content);
|
|
227
|
+
this.propsInfoWindow.open(hnMap.map.map, e.lnglat);
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
this.layerEntity.off("click", handleClick);
|
|
231
|
+
this.layerEntity.on("click", handleClick);
|
|
232
|
+
}
|
|
232
233
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
234
|
+
// 添加自定义dom弹窗
|
|
235
|
+
addCustomPopup(getCustomDom: any) {
|
|
236
|
+
if (!this.customInfoWindow) {
|
|
237
|
+
this.customInfoWindow = new AMap.InfoWindow({
|
|
238
|
+
offset: new AMap.Pixel(0, -30),
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
if (getCustomDom) {
|
|
242
|
+
this.getCustomDom = getCustomDom;
|
|
243
|
+
}
|
|
244
|
+
const handleClick = (e: any) => {
|
|
245
|
+
const overlay = e.target; // 获取被点击的具体覆盖物
|
|
246
|
+
const data = overlay.getOptions().extData.data;
|
|
247
|
+
const dom = this.getCustomDom(data);
|
|
248
|
+
this.customInfoWindow.setContent(dom);
|
|
249
|
+
this.customInfoWindow.open(hnMap.map.map, e.lnglat);
|
|
250
|
+
};
|
|
251
|
+
this.layerEntity.off("click", handleClick);
|
|
252
|
+
this.layerEntity.on("click", handleClick);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
class siji_class {
|
|
257
|
+
id = null;
|
|
258
|
+
option: any = JSON.parse(JSON.stringify(defaultOption));
|
|
259
|
+
config: any = null;
|
|
260
|
+
children: any = null;
|
|
261
|
+
hideChildrenMap: any = null;
|
|
262
|
+
layerEntity: any = null;
|
|
263
|
+
infoWindow: any = null;
|
|
264
|
+
entity: any = null;
|
|
265
|
+
|
|
266
|
+
constructor(option: any) {
|
|
267
|
+
this.id = option.id;
|
|
268
|
+
this.children = [];
|
|
269
|
+
this.hideChildrenMap = {};
|
|
270
|
+
deepMerge(this.option, option);
|
|
271
|
+
this.config = this.formatConfig(this.option);
|
|
253
272
|
}
|
|
254
273
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
config: any = null;
|
|
259
|
-
children: any = null;
|
|
260
|
-
hideChildrenMap: any = null;
|
|
261
|
-
layerEntity: any = null;
|
|
262
|
-
infoWindow: any = null;
|
|
263
|
-
entity: any = null;
|
|
264
|
-
|
|
265
|
-
constructor(option: any) {
|
|
266
|
-
this.id = option.id;
|
|
267
|
-
this.children = [];
|
|
268
|
-
this.hideChildrenMap = {};
|
|
269
|
-
deepMerge(this.option, option);
|
|
270
|
-
this.config = this.formatConfig(this.option);
|
|
271
|
-
}
|
|
274
|
+
formatConfig(option: any) {
|
|
275
|
+
return option;
|
|
276
|
+
}
|
|
272
277
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
278
|
+
updateEntity(entity: any, viewPos: any) {
|
|
279
|
+
const isUpdateEntity =
|
|
280
|
+
hnMap.map.level >= Number(entity.option.distanceDisplayCondition_far) &&
|
|
281
|
+
hnMap.map.level <= Number(entity.option.distanceDisplayCondition_near);
|
|
282
|
+
if (isUpdateEntity) {
|
|
283
|
+
if (
|
|
284
|
+
!entity.show &&
|
|
285
|
+
this.isIncludesLabel(entity.option.position, viewPos)
|
|
286
|
+
) {
|
|
287
|
+
this.addLevelEntity(entity);
|
|
288
|
+
}
|
|
289
|
+
} else {
|
|
290
|
+
if (entity.show) {
|
|
291
|
+
this.removeLevelEntity(entity);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
276
295
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
}
|
|
296
|
+
// 判断坐标是否在视口范围内
|
|
297
|
+
isIncludesLabel(p: any, viewPos: any) {
|
|
298
|
+
return (
|
|
299
|
+
p[0] > viewPos.xmin &&
|
|
300
|
+
p[0] < viewPos.xmax &&
|
|
301
|
+
p[1] > viewPos.ymin &&
|
|
302
|
+
p[1] < viewPos.ymax
|
|
303
|
+
);
|
|
304
|
+
}
|
|
289
305
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
}
|
|
306
|
+
getEntity(id: any) {
|
|
307
|
+
return this.children.find((v: any) => v.id === id);
|
|
308
|
+
}
|
|
294
309
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
310
|
+
addEntity(entity: any) {
|
|
311
|
+
if (this.children.find((v: any) => v.id === entity.id)) {
|
|
312
|
+
console.error("已存在同名图形" + entity.id);
|
|
313
|
+
} else {
|
|
314
|
+
this.children.push(entity);
|
|
315
|
+
const isUpdateEntity =
|
|
316
|
+
hnMap.map.level >=
|
|
317
|
+
Number(entity.option.distanceDisplayCondition_far) &&
|
|
318
|
+
hnMap.map.level <=
|
|
319
|
+
Number(entity.option.distanceDisplayCondition_near);
|
|
320
|
+
if (!entity.option.distanceDisplayCondition || isUpdateEntity) {
|
|
321
|
+
this.addLevelEntity(entity);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
298
325
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
}
|
|
309
|
-
}
|
|
326
|
+
removeEntity(entityParam: any) {
|
|
327
|
+
const entity = this.getEntity(entityParam);
|
|
328
|
+
if (entity) {
|
|
329
|
+
this.children = this.children.filter((v: any) => {
|
|
330
|
+
return v.id !== entity.id;
|
|
331
|
+
});
|
|
332
|
+
this.removeLevelEntity(entity);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
310
335
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
336
|
+
addLevelEntity(entity: any) {
|
|
337
|
+
if (entity.type == "imagePoint") {
|
|
338
|
+
hnMap.map.map.loadImage(
|
|
339
|
+
entity.option.image,
|
|
340
|
+
function (error: any, image: any) {
|
|
341
|
+
entity.config.layout["icon-size"] =
|
|
342
|
+
entity.option.width / image.width;
|
|
343
|
+
hnMap.map.map.addImage(entity.id + "_image", image);
|
|
344
|
+
hnMap.map.map.addLayer(entity.config);
|
|
345
|
+
}
|
|
346
|
+
);
|
|
347
|
+
} else if (entity.type == "numPoint") {
|
|
348
|
+
hnMap.map.map.addLayer(entity.config);
|
|
349
|
+
hnMap.map.map.addLayer(entity.configLabel);
|
|
350
|
+
} else if (entity.type == "divPoint") {
|
|
351
|
+
entity.graphic.setLngLat(entity.option.position).addTo(hnMap.map.map);
|
|
352
|
+
} else if (entity.type == "circle") {
|
|
353
|
+
let featureArr = {
|
|
354
|
+
type: "Feature",
|
|
355
|
+
properties: {
|
|
356
|
+
centerPoint: entity.option.position,
|
|
357
|
+
radius: entity.option.radius,
|
|
358
|
+
},
|
|
359
|
+
geometry: {
|
|
360
|
+
type: "Polygon",
|
|
361
|
+
coordinates: [],
|
|
362
|
+
},
|
|
363
|
+
};
|
|
364
|
+
entity.graphic.addFeature(featureArr);
|
|
365
|
+
// entity.graphic = new SGMap.DrawCircleHandler(entity.config);
|
|
366
|
+
} else if (entity.type == "route") {
|
|
367
|
+
hnMap.map.map.addLayer(entity.config_routeline);
|
|
368
|
+
hnMap.map.map.addLayer(entity.config_routeplay);
|
|
369
|
+
entity.createCar();
|
|
370
|
+
entity.chunkData = entity.joinLinePoint();
|
|
371
|
+
entity.start();
|
|
372
|
+
} else {
|
|
373
|
+
hnMap.map.map.addLayer(entity.config);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
entity.show = true;
|
|
377
|
+
}
|
|
320
378
|
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
};
|
|
347
|
-
entity.graphic.addFeature(featureArr);
|
|
348
|
-
// entity.graphic = new SGMap.DrawCircleHandler(entity.config);
|
|
349
|
-
} else if (entity.type == "route") {
|
|
350
|
-
hnMap.map.map.addLayer(entity.config_routeline);
|
|
351
|
-
hnMap.map.map.addLayer(entity.config_routeplay);
|
|
352
|
-
entity.createCar();
|
|
353
|
-
entity.chunkData = entity.joinLinePoint();
|
|
354
|
-
entity.start();
|
|
355
|
-
} else {
|
|
356
|
-
|
|
357
|
-
hnMap.map.map.addLayer(entity.config);
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
entity.show = true;
|
|
361
|
-
}
|
|
379
|
+
removeLevelEntity(entity: any) {
|
|
380
|
+
if (entity) {
|
|
381
|
+
if (entity.type == "circle") {
|
|
382
|
+
entity.graphic.remove();
|
|
383
|
+
entity.graphic.clearData();
|
|
384
|
+
} else if (entity.type == "numPoint") {
|
|
385
|
+
hnMap.map.map.removeLayer(entity.config.id);
|
|
386
|
+
hnMap.map.map.removeSource(entity.config.id);
|
|
387
|
+
hnMap.map.map.removeLayer(entity.configLabel.id);
|
|
388
|
+
hnMap.map.map.removeSource(entity.configLabel.id);
|
|
389
|
+
} else if (entity.type == "divPoint") {
|
|
390
|
+
entity.graphic.remove();
|
|
391
|
+
} else if (entity.type == "route") {
|
|
392
|
+
hnMap.map.map.removeLayer(entity.config_routeline.id);
|
|
393
|
+
hnMap.map.map.removeSource(entity.config_routeline.id);
|
|
394
|
+
hnMap.map.map.removeLayer(entity.config_routeplay.id);
|
|
395
|
+
hnMap.map.map.removeSource(entity.config_routeplay.id);
|
|
396
|
+
entity.imgMarker.remove();
|
|
397
|
+
} else {
|
|
398
|
+
hnMap.map.map.removeLayer(entity.id);
|
|
399
|
+
hnMap.map.map.removeSource(entity.id);
|
|
400
|
+
}
|
|
401
|
+
entity.show = false;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
362
404
|
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
} else if (entity.type == "numPoint") {
|
|
370
|
-
hnMap.map.map.removeLayer(entity.config.id);
|
|
371
|
-
hnMap.map.map.removeSource(entity.config.id);
|
|
372
|
-
hnMap.map.map.removeLayer(entity.configLabel.id);
|
|
373
|
-
hnMap.map.map.removeSource(entity.configLabel.id);
|
|
374
|
-
} else if (entity.type == "divPoint") {
|
|
375
|
-
entity.graphic.remove();
|
|
376
|
-
} else if (entity.type == "route") {
|
|
377
|
-
hnMap.map.map.removeLayer(entity.config_routeline.id);
|
|
378
|
-
hnMap.map.map.removeSource(entity.config_routeline.id);
|
|
379
|
-
hnMap.map.map.removeLayer(entity.config_routeplay.id);
|
|
380
|
-
hnMap.map.map.removeSource(entity.config_routeplay.id);
|
|
381
|
-
entity.imgMarker.remove();
|
|
382
|
-
} else {
|
|
383
|
-
hnMap.map.map.removeLayer(entity.id);
|
|
384
|
-
hnMap.map.map.removeSource(entity.id);
|
|
385
|
-
}
|
|
386
|
-
entity.show = false;
|
|
387
|
-
}
|
|
388
|
-
}
|
|
405
|
+
clearEntity() {
|
|
406
|
+
this.children.forEach((v: any) => {
|
|
407
|
+
this.removeEntity(v.id);
|
|
408
|
+
});
|
|
409
|
+
this.children = [];
|
|
410
|
+
}
|
|
389
411
|
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
412
|
+
destroy() {
|
|
413
|
+
this.clearEntity();
|
|
414
|
+
hnMap.map.layerList = hnMap.map.layerList.filter(
|
|
415
|
+
(v: any) => v.id !== this.id
|
|
416
|
+
);
|
|
417
|
+
}
|
|
396
418
|
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
}
|
|
419
|
+
// 添加属性弹窗
|
|
420
|
+
addPopupByAttr() {
|
|
421
|
+
// 如果已有弹窗,先关闭
|
|
422
|
+
this.removePopup();
|
|
423
|
+
this.infoWindow = new SGMap.Popup({
|
|
424
|
+
offset: { bottom: [0, 0] },
|
|
425
|
+
className: "my-attrPopup-class",
|
|
426
|
+
});
|
|
403
427
|
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
// 如果已有弹窗,先关闭
|
|
407
|
-
this.removePopup();
|
|
408
|
-
this.infoWindow = new SGMap.Popup({
|
|
409
|
-
offset: {bottom: [0, 0]},
|
|
410
|
-
className: "my-attrPopup-class",
|
|
411
|
-
});
|
|
412
|
-
|
|
413
|
-
const handleClick = (e: any) => {
|
|
414
|
-
let data = e.features[0].properties;
|
|
415
|
-
|
|
416
|
-
// 创建弹窗内容
|
|
417
|
-
let content = "";
|
|
418
|
-
for (const key in data) {
|
|
419
|
-
content += `<div>${key}: ${data[key]}</div>`;
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
this.infoWindow.setHTML(content);
|
|
423
|
-
console.log("e.lngLat===", e.lngLat);
|
|
424
|
-
this.infoWindow.setLngLat(e.lngLat).addTo(hnMap.map.map);
|
|
425
|
-
};
|
|
426
|
-
|
|
427
|
-
hnMap.map.map.on("click", this.config.id, handleClick);
|
|
428
|
-
}
|
|
428
|
+
const handleClick = (e: any) => {
|
|
429
|
+
let data = e.features[0].properties;
|
|
429
430
|
|
|
430
|
-
//
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
this.infoWindow = new SGMap.Popup({
|
|
435
|
-
offset: {bottom: [0, 0]},
|
|
436
|
-
className: "my-customPopup-class",
|
|
437
|
-
});
|
|
438
|
-
|
|
439
|
-
const handleClick = (e: any) => {
|
|
440
|
-
const data = e.features[0].properties;
|
|
441
|
-
const dom = getCustomDom(data);
|
|
442
|
-
this.infoWindow.setHTML(dom);
|
|
443
|
-
this.infoWindow.setLngLat(e.lngLat).addTo(hnMap.map.map);
|
|
444
|
-
};
|
|
445
|
-
|
|
446
|
-
hnMap.map.map.on("click", this.config.id, handleClick);
|
|
431
|
+
// 创建弹窗内容
|
|
432
|
+
let content = "";
|
|
433
|
+
for (const key in data) {
|
|
434
|
+
content += `<div>${key}: ${data[key]}</div>`;
|
|
447
435
|
}
|
|
448
436
|
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
437
|
+
this.infoWindow.setHTML(content);
|
|
438
|
+
console.log("e.lngLat===", e.lngLat);
|
|
439
|
+
this.infoWindow.setLngLat(e.lngLat).addTo(hnMap.map.map);
|
|
440
|
+
};
|
|
441
|
+
|
|
442
|
+
hnMap.map.map.on("click", this.config.id, handleClick);
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
// 添加自定义dom弹窗
|
|
446
|
+
addCustomPopup(getCustomDom: any) {
|
|
447
|
+
// 如果已有弹窗,先关闭
|
|
448
|
+
this.removePopup();
|
|
449
|
+
this.infoWindow = new SGMap.Popup({
|
|
450
|
+
offset: { bottom: [0, 0] },
|
|
451
|
+
className: "my-customPopup-class",
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
const handleClick = (e: any) => {
|
|
455
|
+
const data = e.features[0].properties;
|
|
456
|
+
const dom = getCustomDom(data);
|
|
457
|
+
this.infoWindow.setHTML(dom);
|
|
458
|
+
this.infoWindow.setLngLat(e.lngLat).addTo(hnMap.map.map);
|
|
459
|
+
};
|
|
460
|
+
|
|
461
|
+
hnMap.map.map.on("click", this.config.id, handleClick);
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
// 弹窗删除
|
|
465
|
+
removePopup() {
|
|
466
|
+
if (this.infoWindow) {
|
|
467
|
+
this.infoWindow.remove();
|
|
468
|
+
}
|
|
455
469
|
}
|
|
470
|
+
}
|
|
456
471
|
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
472
|
+
const fn: any = {
|
|
473
|
+
mars3d: mars3d_class,
|
|
474
|
+
gaode: gaode_class,
|
|
475
|
+
siji: siji_class,
|
|
476
|
+
};
|
|
462
477
|
|
|
463
|
-
|
|
478
|
+
return fn[hnMap.mapType];
|
|
464
479
|
};
|