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.
@@ -1,464 +1,479 @@
1
- import {deepMerge} from "../util";
1
+ import { deepMerge } from "../util";
2
2
 
3
3
  export default (hnMap: any) => {
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
- }
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
- formatConfig(option: any) {
23
- return option;
24
- }
22
+ formatConfig(option: any) {
23
+ return option;
24
+ }
25
25
 
26
- getEntity(id: any) {
27
- return this.children.find((v: any) => v.id === id);
28
- }
26
+ getEntity(id: any) {
27
+ return this.children.find((v: any) => v.id === id);
28
+ }
29
29
 
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();
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
- removeEntity(entityParam: any) {
43
- const entity = this.getEntity(entityParam);
44
- if (entity) {
45
- this.layerEntity.removeGraphic(entity.graphic);
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
- clearEntity() {
50
- this.children.forEach((v: any) => v.destroy());
51
- this.children = [];
52
- this.layerEntity.clear();
53
- }
49
+ clearEntity() {
50
+ this.children.forEach((v: any) => v.destroy());
51
+ this.children = [];
52
+ this.layerEntity.clear();
53
+ }
54
54
 
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
- }
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
- show() {
64
- this.layerEntity.show = true;
65
- }
63
+ show() {
64
+ this.layerEntity.show = true;
65
+ }
66
66
 
67
- hide() {
68
- this.layerEntity.show = false;
69
- }
67
+ hide() {
68
+ this.layerEntity.show = false;
69
+ }
70
70
 
71
- flyTo() {
72
- this.layerEntity.flyTo();
73
- }
71
+ flyTo() {
72
+ this.layerEntity.flyTo();
73
+ }
74
74
 
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
- }
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
- 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
- }
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
- // 添加自定义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
- }
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
- 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;
157
- }
159
+ formatConfig(option: any) {
160
+ return option;
161
+ }
158
162
 
159
- formatConfig(option: any) {
160
- return option;
161
- }
163
+ getEntity(entityParam: any) {
164
+ return this.children.find((v: any) => v.id === entityParam);
165
+ }
162
166
 
163
- getEntity(entityParam: any) {
164
- return this.children.find((v: any) => v.id === entityParam);
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
- addEntity(entity: any) {
168
- if (this.children.find((v: any) => v.id === entity.id)) {
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
- removeEntity(entityParam: any) {
186
- const entity = this.getEntity(entityParam);
186
+ removeEntity(entityParam: any) {
187
+ const entity = this.getEntity(entityParam);
187
188
 
188
- if (entity) {
189
- this.children = this.children.filter((v: any): any => {
190
- return v.id !== entity.id;
191
- });
189
+ if (entity) {
190
+ this.children = this.children.filter((v: any): any => {
191
+ return v.id !== entity.id;
192
+ });
192
193
 
193
- this.layerEntity.removeOverlay(entity.graphic);
194
- entity.destroy();
195
- }
196
- }
194
+ this.layerEntity.removeOverlay(entity.graphic);
195
+ entity.destroy();
196
+ }
197
+ }
197
198
 
198
- clearEntity() {
199
- this.children = [];
200
- this.layerEntity.clearOverlays();
201
- }
199
+ clearEntity() {
200
+ this.children = [];
201
+ this.layerEntity.clearOverlays();
202
+ }
202
203
 
203
- destroy() {
204
- this.clearEntity();
205
- hnMap.map.map.remove(this.layerEntity);
206
- hnMap.map.layerList = hnMap.map.layerList.filter(
207
- (v: any) => v.id !== this.id
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
- addPopupByAttr() {
213
- if (!this.propsInfoWindow) {
214
- this.propsInfoWindow = new AMap.InfoWindow({
215
- offset: new AMap.Pixel(0, -30),
216
- });
217
- }
218
- const handleClick = (e: any) => {
219
- const overlay = e.target; // 获取被点击的具体覆盖物
220
- const data = overlay.getOptions().extData.data;
221
- let content = "";
222
- for (const key in data) {
223
- content += `<div>${key}: ${data[key]}</div>`;
224
- }
225
- this.propsInfoWindow.setContent(content);
226
- this.propsInfoWindow.open(hnMap.map.map, e.lnglat);
227
- };
228
-
229
- this.layerEntity.off("click", handleClick);
230
- this.layerEntity.on("click", handleClick);
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
- // 添加自定义dom弹窗
234
- addCustomPopup(getCustomDom: any) {
235
- if (!this.customInfoWindow) {
236
- this.customInfoWindow = new AMap.InfoWindow({
237
- offset: new AMap.Pixel(0, -30),
238
- });
239
- }
240
- if (getCustomDom) {
241
- this.getCustomDom = getCustomDom;
242
- }
243
- const handleClick = (e: any) => {
244
- const overlay = e.target; // 获取被点击的具体覆盖物
245
- const data = overlay.getOptions().extData.data;
246
- const dom = this.getCustomDom(data);
247
- this.customInfoWindow.setContent(dom);
248
- this.customInfoWindow.open(hnMap.map.map, e.lnglat);
249
- };
250
- this.layerEntity.off("click", handleClick);
251
- this.layerEntity.on("click", handleClick);
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
- class siji_class {
256
- id = null;
257
- option: any = JSON.parse(JSON.stringify(defaultOption));
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
- formatConfig(option: any) {
274
- return option;
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
- updateEntity(entity: any, viewPos: any) {
278
- const isUpdateEntity = hnMap.map.level >= Number(entity.option.distanceDisplayCondition_far) && hnMap.map.level <= Number(entity.option.distanceDisplayCondition_near)
279
- if (isUpdateEntity) {
280
- if (!entity.show && this.isIncludesLabel(entity.option.position, viewPos)) {
281
- this.addLevelEntity(entity);
282
- }
283
- } else {
284
- if (entity.show) {
285
- this.removeLevelEntity(entity);
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
- isIncludesLabel(p: any, viewPos: any) {
292
- return p[0] > viewPos.xmin && p[0] < viewPos.xmax && p[1] > viewPos.ymin && p[1] < viewPos.ymax
293
- }
306
+ getEntity(id: any) {
307
+ return this.children.find((v: any) => v.id === id);
308
+ }
294
309
 
295
- getEntity(id: any) {
296
- return this.children.find((v: any) => v.id === id);
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
- addEntity(entity: any) {
300
- if (this.children.find((v: any) => v.id === entity.id)) {
301
- console.error("已存在同名图形" + entity.id);
302
- } else {
303
- this.children.push(entity);
304
- const isUpdateEntity = hnMap.map.level >= Number(entity.option.distanceDisplayCondition_far) && hnMap.map.level <= Number(entity.option.distanceDisplayCondition_near)
305
- if (!entity.option.distanceDisplayCondition || isUpdateEntity) {
306
- this.addLevelEntity(entity)
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
- removeEntity(entityParam: any) {
312
- const entity = this.getEntity(entityParam);
313
- if (entity) {
314
- this.children = this.children.filter((v: any) => {
315
- return v.id !== entity.id;
316
- });
317
- this.removeLevelEntity(entity)
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
- addLevelEntity(entity: any) {
322
- if (entity.type == "imagePoint") {
323
- hnMap.map.map.loadImage(
324
- entity.option.image,
325
- function (error: any, image: any) {
326
- hnMap.map.map.addImage(entity.id + "_image", image);
327
- hnMap.map.map.addLayer(entity.config);
328
- }
329
- );
330
- } else if (entity.type == "numPoint") {
331
- hnMap.map.map.addLayer(entity.config);
332
- hnMap.map.map.addLayer(entity.configLabel);
333
- } else if (entity.type == "divPoint") {
334
- entity.graphic.setLngLat(entity.option.position).addTo(hnMap.map.map);
335
- } else if (entity.type == "circle") {
336
- let featureArr = {
337
- type: "Feature",
338
- properties: {
339
- centerPoint: entity.option.position,
340
- radius: entity.option.radius,
341
- },
342
- geometry: {
343
- type: "Polygon",
344
- coordinates: [],
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
- removeLevelEntity(entity: any) {
364
-
365
- if (entity) {
366
- if (entity.type == "circle") {
367
- entity.graphic.remove();
368
- entity.graphic.clearData();
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
- clearEntity() {
391
- this.children.forEach((v: any) => {
392
- this.removeEntity(v.id)
393
- });
394
- this.children = [];
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
- destroy() {
398
- this.clearEntity();
399
- hnMap.map.layerList = hnMap.map.layerList.filter(
400
- (v: any) => v.id !== this.id
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
- addPopupByAttr() {
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
- // 添加自定义dom弹窗
431
- addCustomPopup(getCustomDom: any) {
432
- // 如果已有弹窗,先关闭
433
- this.removePopup();
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
- removePopup() {
451
- if (this.infoWindow) {
452
- this.infoWindow.remove();
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
- const fn: any = {
458
- mars3d: mars3d_class,
459
- gaode: gaode_class,
460
- siji: siji_class,
461
- };
472
+ const fn: any = {
473
+ mars3d: mars3d_class,
474
+ gaode: gaode_class,
475
+ siji: siji_class,
476
+ };
462
477
 
463
- return fn[hnMap.mapType];
478
+ return fn[hnMap.mapType];
464
479
  };