hn-map 1.1.1 → 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/src/map.ts CHANGED
@@ -1,433 +1,439 @@
1
- import {deepMerge, getHeightToLevel, getLevelMiddleHeight} from "./util";
1
+ import { deepMerge, getHeightToLevel, getLevelMiddleHeight } from "./util";
2
2
 
3
3
  export default (hnMap: any) => {
4
- const defaultOption = {
5
- // 经度
6
- lat: 37.7979042,
7
- // 纬度
8
- lng: 112.55074,
9
- // 缩放级别
10
- level: 11,
11
- // 旋转角度
12
- heading: 0,
13
- // 俯仰角度
14
- pitch: -60,
15
- // 翻滚角度
16
- roll: 0,
17
- mars3d_config: "",
18
- // 高德地图key
19
- gaode_key: "",
20
- // 思极key
21
- sj_app_key: "",
22
- sj_app_secret: "",
23
- style: "aegis://styles/aegis/Streets-Raster512",
24
- };
25
-
26
- class mars3d_map {
27
- map: any = null;
28
-
29
- option: any = JSON.parse(JSON.stringify(defaultOption));
30
- config: any = null;
31
-
32
- // 图层集合
33
- layerList: any = [];
34
-
35
- event: any = {};
36
-
37
- level: any = null;
38
-
39
- private constructor(id: string, option: any) {
40
- this.layerList = [];
41
- this.level = this.option.level;
42
- deepMerge(this.option, option);
43
- this.config = this.formatConfig(this.option);
44
- this.map = new mars3d.Map(id, this.config);
45
-
46
- this.map.on("cameraMoveEnd", (e: any) => {
47
- const height = this.map.getCameraView().alt;
48
- this.level = getHeightToLevel(height);
49
- });
50
- }
51
-
52
- static async create(id: string, option: any) {
53
- const instance = new mars3d_map(id, option);
54
- // 返回一个 Promise,等待地图的 'load' 事件
55
- await new Promise<void>((resolve) => {
56
- resolve();
57
- });
58
- // 地图加载完成后,返回实例
59
- return instance;
60
- }
61
-
62
- formatConfig(option: any) {
63
- const alt = getLevelMiddleHeight(option.level);
64
- return {
65
- ...option.mars3d_config,
66
- control: {
67
- locationBar: {fps: true},
68
- },
69
- scene: {
70
- center: {
71
- lat: option.lat,
72
- lng: option.lng,
73
- alt: alt,
74
- heading: 360 - option.heading || 0,
75
- pitch: option.pitch || 0,
76
- roll: option.roll || 0,
77
- },
78
- fxaa: true,
79
- requestRenderMode: true, // 显式渲染
80
- },
81
- };
82
- }
83
-
84
- addLayer(layer: any) {
85
- if (this.layerList.find((v: any) => v.id === layer.id)) {
86
- console.error("已存在同名图层" + layer.id);
87
- } else {
88
- this.layerList.push(layer);
89
- this.map.addLayer(layer.layerEntity);
90
- return layer;
91
- }
92
- }
93
-
94
- getLayer(layerId: any) {
95
- return this.layerList.find((v: any) => v.id === layerId);
96
- }
97
-
98
- // 删除图层
99
- removeLayer(layerId: any) {
100
- const layer = this.getLayer(layerId);
101
- if (layer) {
102
- this.layerList = this.layerList.filter((v: any) => v.id !== layerId);
103
- layer.destroy();
104
- }
105
- }
106
-
107
- // 清空图层
108
- clearLayer(layerId: any) {
109
- const layer = this.getLayer(layerId);
110
- if (layer) {
111
- layer.children = [];
112
- layer.clearEntity();
113
- }
114
- }
4
+ const defaultOption = {
5
+ // 经度
6
+ lat: 37.7979042,
7
+ // 纬度
8
+ lng: 112.55074,
9
+ // 缩放级别
10
+ level: 11,
11
+ // 旋转角度
12
+ heading: 0,
13
+ // 俯仰角度
14
+ pitch: -60,
15
+ // 翻滚角度
16
+ roll: 0,
17
+ mars3d_config: "",
18
+ // 高德地图key
19
+ gaode_key: "",
20
+ // 思极key
21
+ sj_app_key: "",
22
+ sj_app_secret: "",
23
+ sj_style: "aegis://styles/aegis/Streets-Raster512",
24
+ };
25
+
26
+ class mars3d_map {
27
+ map: any = null;
28
+
29
+ option: any = JSON.parse(JSON.stringify(defaultOption));
30
+ config: any = null;
31
+
32
+ // 图层集合
33
+ layerList: any = [];
34
+
35
+ event: any = {};
36
+
37
+ level: any = null;
38
+
39
+ private constructor(id: string, option: any) {
40
+ this.layerList = [];
41
+ this.level = 10;
42
+ deepMerge(this.option, option);
43
+ this.config = this.formatConfig(this.option);
44
+ this.map = new mars3d.Map(id, this.config);
45
+
46
+ this.map.on("cameraMoveEnd", (e: any) => {
47
+ const height = this.map.getCameraView().alt;
48
+ this.level = getHeightToLevel(height);
49
+ });
50
+ }
115
51
 
116
- on(eventType: any, callback: any) {
117
- this.off(eventType);
118
- switch (eventType) {
119
- case "click":
120
- this.event[eventType] = (event: any) => {
121
- const point = mars3d.LngLatPoint.fromCartesian(event.cartesian); //转为经纬度
122
- point.format(); // 经度、纬度、高度
123
- const position = {
124
- lng: point.lng,
125
- lat: point.lat,
126
- alt: point.alt,
127
- };
128
- callback(position);
129
- };
130
- break;
131
- case "cameraMoveEnd":
132
- this.event[eventType] = (event: any) => {
133
- callback(event);
134
- };
135
- break;
136
- }
137
- this.map.on(eventType, this.event[eventType]);
138
- }
52
+ static async create(id: string, option: any) {
53
+ const instance = new mars3d_map(id, option);
54
+ // 返回一个 Promise,等待地图的 'load' 事件
55
+ await new Promise<void>((resolve) => {
56
+ resolve();
57
+ });
58
+ // 地图加载完成后,返回实例
59
+ return instance;
60
+ }
139
61
 
140
- off(eventType: any) {
141
- if (this.event[eventType]) {
142
- this.map.off(eventType, this.event[eventType]);
143
- delete this.event[eventType];
144
- }
145
- }
62
+ formatConfig(option: any) {
63
+ const alt = getLevelMiddleHeight(option.level);
64
+ return {
65
+ ...option.mars3d_config,
66
+ control: {
67
+ locationBar: { fps: true },
68
+ },
69
+ scene: {
70
+ center: {
71
+ lat: option.lat,
72
+ lng: option.lng,
73
+ alt: alt,
74
+ heading: 360 - option.heading || 0,
75
+ pitch: option.pitch || 0,
76
+ roll: option.roll || 0,
77
+ },
78
+ fxaa: true,
79
+ requestRenderMode: true, // 显式渲染
80
+ },
81
+ };
82
+ }
146
83
 
147
- /**
148
- * 获取当前视口的经纬度范围
149
- * 返回参数 {xmin,xmax,ymin,ymax}
150
- * @returns {*}
151
- */
152
- getExtent() {
153
- return this.map.getExtent();
154
- }
84
+ addLayer(layer: any) {
85
+ if (this.layerList.find((v: any) => v.id === layer.id)) {
86
+ console.error("已存在同名图层" + layer.id);
87
+ } else {
88
+ this.layerList.push(layer);
89
+ this.map.addLayer(layer.layerEntity);
90
+ return layer;
91
+ }
92
+ }
155
93
 
156
- /**
157
- * 获取当前视高
158
- * 返回参数 {alt}
159
- * @returns {any}
160
- */
161
- getCameraView() {
162
- return this.map.getCameraView();
163
- }
94
+ getLayer(layerId: any) {
95
+ return this.layerList.find((v: any) => v.id === layerId);
96
+ }
164
97
 
165
- flyToPoint(position: any) {
166
- const pos = new mars3d.LngLatPoint(position[0], position[1], position[2]);
167
- this.map.flyToPoint(pos);
168
- }
98
+ // 删除图层
99
+ removeLayer(layerId: any) {
100
+ const layer = this.getLayer(layerId);
101
+ if (layer) {
102
+ this.layerList = this.layerList.filter((v: any) => v.id !== layerId);
103
+ layer.destroy();
104
+ }
105
+ }
169
106
 
170
- closePopup() {
171
- this.map.closePopup();
172
- }
107
+ // 清空图层
108
+ clearLayer(layerId: any) {
109
+ const layer = this.getLayer(layerId);
110
+ if (layer) {
111
+ layer.children = [];
112
+ layer.clearEntity();
113
+ }
114
+ }
173
115
 
174
- // 设置投影模式 2d/3d
175
- setMode(mode: any) {
176
- const obj: any = {
177
- "2d": Cesium.SceneMode.SCENE2D,
178
- "3d": Cesium.SceneMode.SCENE3D,
116
+ on(eventType: any, callback: any) {
117
+ this.off(eventType);
118
+ switch (eventType) {
119
+ case "click":
120
+ this.event[eventType] = (event: any) => {
121
+ const point = mars3d.LngLatPoint.fromCartesian(event.cartesian); //转为经纬度
122
+ point.format(); // 经度、纬度、高度
123
+ const position = {
124
+ lng: point.lng,
125
+ lat: point.lat,
126
+ alt: point.alt,
179
127
  };
180
- this.map.scene.mode = obj[mode.toLowerCase()];
181
- }
128
+ callback(position);
129
+ };
130
+ break;
131
+ case "cameraMoveEnd":
132
+ this.event[eventType] = (event: any) => {
133
+ callback(event);
134
+ };
135
+ break;
136
+ }
137
+ this.map.on(eventType, this.event[eventType]);
182
138
  }
183
139
 
184
- class gaode_map {
185
- map: any = null;
186
-
187
- option: any = JSON.parse(JSON.stringify(defaultOption));
188
- config: any = null;
189
-
190
- // 图层集合
191
- layerList: any = [];
140
+ off(eventType: any) {
141
+ if (this.event[eventType]) {
142
+ this.map.off(eventType, this.event[eventType]);
143
+ delete this.event[eventType];
144
+ }
145
+ }
192
146
 
193
- private constructor(id: any, option: any) {
194
- this.layerList = [];
195
- deepMerge(this.option, option);
196
- this.config = this.formatConfig(this.option);
197
- this.map = new AMap.Map(id, this.config);
198
- }
147
+ /**
148
+ * 获取当前视口的经纬度范围
149
+ * 返回参数 {xmin,xmax,ymin,ymax}
150
+ * @returns {*}
151
+ */
152
+ getExtent() {
153
+ return this.map.getExtent();
154
+ }
199
155
 
200
- static async create(id: string, option: any) {
201
- const instance = new gaode_map(id, option);
156
+ /**
157
+ * 获取当前视高
158
+ * 返回参数 {alt}
159
+ * @returns {any}
160
+ */
161
+ getCameraView() {
162
+ return this.map.getCameraView();
163
+ }
202
164
 
203
- // 返回一个 Promise,等待地图的 'load' 事件
204
- await new Promise<void>((resolve) => {
205
- resolve();
206
- });
165
+ flyToPoint(position: any) {
166
+ const pos = new mars3d.LngLatPoint(position[0], position[1], position[2]);
167
+ this.map.flyToPoint(pos);
168
+ }
207
169
 
208
- // 地图加载完成后,返回实例
209
- return instance;
210
- }
170
+ closePopup() {
171
+ this.map.closePopup();
172
+ }
211
173
 
212
- formatConfig(option: any) {
213
- return {
214
- viewMode: "2D", // 是否为3D地图模式
215
- level: option.level, // 初始化地图级别
216
- pitch: option.pitch,
217
- rotation: option.heading,
218
- rotateEnable: true,
219
- pitchEnable: true,
220
- terrain: true, // 开启地形图
221
- center: [option.lng, option.lat], // 初始化地图中心点位置
222
- };
223
- }
174
+ // 设置投影模式 2d/3d
175
+ setMode(mode: any) {
176
+ const obj: any = {
177
+ "2d": Cesium.SceneMode.SCENE2D,
178
+ "3d": Cesium.SceneMode.SCENE3D,
179
+ };
180
+ this.map.scene.mode = obj[mode.toLowerCase()];
181
+ }
182
+ }
224
183
 
225
- addLayer(layer: any) {
226
- if (this.layerList.find((v: any) => v.id === layer.id)) {
227
- console.error("已存在同名图层");
228
- } else {
229
- this.layerList.push(layer);
230
- this.map.add(layer.layerEntity);
231
- return layer;
232
- }
233
- }
184
+ class gaode_map {
185
+ map: any = null;
234
186
 
235
- getLayer(layerId: any) {
236
- return this.layerList.find((v: any) => v.id === layerId);
237
- }
187
+ option: any = JSON.parse(JSON.stringify(defaultOption));
188
+ config: any = null;
238
189
 
239
- removeLayer(layerId: any) {
240
- const layer = this.getLayer(layerId);
241
- if (layer) {
242
- layer.destroy();
243
- this.layerList = this.layerList.filter((v: any) => v.id !== layerId);
244
- }
245
- }
190
+ // 图层集合
191
+ layerList: any = [];
246
192
 
247
- clearLayer(layerId: any) {
248
- const layer = this.getLayer(layerId);
249
- if (layer) {
250
- layer.children = [];
251
- layer.clearEntity();
252
- }
253
- }
193
+ private constructor(id: any, option: any) {
194
+ this.layerList = [];
195
+ deepMerge(this.option, option);
196
+ this.config = this.formatConfig(this.option);
197
+ this.map = new AMap.Map(id, this.config);
254
198
  }
255
199
 
256
- class siji_map {
257
- id: any = null;
258
- map: any = null;
200
+ static async create(id: string, option: any) {
201
+ const instance = new gaode_map(id, option);
259
202
 
260
- option: any = JSON.parse(JSON.stringify(defaultOption));
261
- config: any = null;
203
+ // 返回一个 Promise,等待地图的 'load' 事件
204
+ await new Promise<void>((resolve) => {
205
+ resolve();
206
+ });
262
207
 
263
- // 图层集合
264
- layerList: any = [];
265
- event: any = {};
266
- level: any = null;
208
+ // 地图加载完成后,返回实例
209
+ return instance;
210
+ }
267
211
 
268
- private constructor(id: any, option: any) {
269
- this.id = id;
270
- this.layerList = [];
212
+ formatConfig(option: any) {
213
+ return {
214
+ viewMode: "2D", // 是否为3D地图模式
215
+ level: option.level, // 初始化地图级别
216
+ pitch: option.pitch,
217
+ rotation: option.heading,
218
+ rotateEnable: true,
219
+ pitchEnable: true,
220
+ terrain: true, // 开启地形图
221
+ center: [option.lng, option.lat], // 初始化地图中心点位置
222
+ };
223
+ }
271
224
 
272
- this.level = this.option.level;
273
- deepMerge(this.option, option);
274
- this.config = this.formatConfig(this.option);
275
- this.map = new SGMap.Map(this.config);
276
- this.map.on("moveend", (e: any) => this.updateMapParams(e)); // 地图移动完成
277
- this.map.on("zoomend", (e: any) => this.updateMapParams(e)); // 地图缩放完成
278
- this.map.on("pitchend", (e: any) => this.updateMapParams(e)); // 地图俯仰角度完成
279
- }
225
+ addLayer(layer: any) {
226
+ if (this.layerList.find((v: any) => v.id === layer.id)) {
227
+ console.error("已存在同名图层");
228
+ } else {
229
+ this.layerList.push(layer);
230
+ this.map.add(layer.layerEntity);
231
+ return layer;
232
+ }
233
+ }
280
234
 
281
- static async create(id: string, option: any) {
282
- const instance = new siji_map(id, option);
235
+ getLayer(layerId: any) {
236
+ return this.layerList.find((v: any) => v.id === layerId);
237
+ }
283
238
 
284
- // 返回一个 Promise,等待地图的 'load' 事件
285
- await new Promise((resolve) => {
286
- instance.map.on("load", (e: any) => {
287
- resolve(e);
288
- });
289
- });
239
+ removeLayer(layerId: any) {
240
+ const layer = this.getLayer(layerId);
241
+ if (layer) {
242
+ layer.destroy();
243
+ this.layerList = this.layerList.filter((v: any) => v.id !== layerId);
244
+ }
245
+ }
290
246
 
291
- // 地图加载完成后,返回实例
292
- return instance;
293
- }
247
+ clearLayer(layerId: any) {
248
+ const layer = this.getLayer(layerId);
249
+ if (layer) {
250
+ layer.children = [];
251
+ layer.clearEntity();
252
+ }
253
+ }
254
+ }
255
+
256
+ class siji_map {
257
+ id: any = null;
258
+ map: any = null;
259
+ geocodingTask: any = null;
260
+ option: any = JSON.parse(JSON.stringify(defaultOption));
261
+ config: any = null;
262
+
263
+ // 图层集合
264
+ layerList: any = [];
265
+ event: any = {};
266
+ level: any = null;
267
+
268
+ private constructor(id: any, option: any) {
269
+ this.id = id;
270
+ this.layerList = [];
271
+
272
+ this.level = this.option.level;
273
+ deepMerge(this.option, option);
274
+ this.config = this.formatConfig(this.option);
275
+ this.map = new SGMap.Map(this.config);
276
+ this.geocodingTask = new SGMap.GeocodingTask();
277
+ this.map.on("moveend", (e: any) => this.updateMapParams(e)); // 地图移动完成
278
+ this.map.on("zoomend", (e: any) => this.updateMapParams(e)); // 地图缩放完成
279
+ this.map.on("pitchend", (e: any) => this.updateMapParams(e)); // 地图俯仰角度完成
280
+ this.map.on("load", (e: any) => {
281
+ // 路况展示
282
+ let roadNetLayer = new SGMap.RoadNetLayer({ map: this.map });
283
+ roadNetLayer.render();
284
+ });
285
+ }
294
286
 
295
- formatConfig(option: any) {
296
- return {
297
- container: this.id,
298
- style: "aegis://styles/aegis/Streets-v2",
299
- // 默认缩放层级
300
- zoom: option.level,
301
- // 地图中心点
302
- center: [option.lng, option.lat],
303
- // 地图默认字体
304
- localIdeographFontFamily: "Microsoft YaHei Regular",
305
- };
306
- }
287
+ static async create(id: string, option: any) {
288
+ const instance = new siji_map(id, option);
307
289
 
308
- addLayer(layer: any) {
309
- if (this.layerList.find((v: any) => v.id === layer.id)) {
310
- console.error("已存在同名图层");
311
- } else {
312
- if (this.map) {
313
- this.layerList.push(layer);
314
- // this.map.addLayer(layer.config);
315
- return layer;
316
- }
317
- }
318
- }
290
+ // 返回一个 Promise,等待地图的 'load' 事件
291
+ await new Promise((resolve) => {
292
+ instance.map.on("load", (e: any) => {
293
+ resolve(e);
294
+ });
295
+ });
319
296
 
320
- getLayer(layerId: any) {
321
- return this.layerList.find((v: any) => v.id === layerId);
322
- }
297
+ // 地图加载完成后,返回实例
298
+ return instance;
299
+ }
323
300
 
324
- removeLayer(layerId: any) {
325
- const layer = this.getLayer(layerId);
301
+ formatConfig(option: any) {
302
+ return {
303
+ container: this.id,
304
+ style: option.sj_style || "aegis://styles/aegis/StreetsDark-v2",
305
+ // 默认缩放层级
306
+ zoom: option.level,
307
+ // 地图中心点
308
+ center: [option.lng, option.lat],
309
+ // 地图默认字体
310
+ localIdeographFontFamily: "Microsoft YaHei Regular",
311
+ };
312
+ }
326
313
 
327
- if (layer.id) {
328
- this.layerList = this.layerList.filter((v: any) => v.id !== layerId);
329
- layer.destroy();
330
- }
314
+ addLayer(layer: any) {
315
+ if (this.layerList.find((v: any) => v.id === layer.id)) {
316
+ console.error("已存在同名图层");
317
+ } else {
318
+ if (this.map) {
319
+ this.layerList.push(layer);
320
+ // this.map.addLayer(layer.config);
321
+ return layer;
331
322
  }
323
+ }
324
+ }
332
325
 
333
- clearLayer(layerId: any) {
334
- const layer = this.getLayer(layerId);
335
- if (layer) {
336
- layer.children = [];
337
- layer.clearEntity();
338
- }
339
- }
326
+ getLayer(layerId: any) {
327
+ return this.layerList.find((v: any) => v.id === layerId);
328
+ }
340
329
 
341
- getExtent() {
342
- const data = this.map.getBounds();
343
- return {
344
- xmin: data._sw.lng,
345
- ymin: data._sw.lat,
346
- xmax: data._ne.lng,
347
- ymax: data._ne.lat,
348
- };
349
- }
330
+ removeLayer(layerId: any) {
331
+ const layer = this.getLayer(layerId);
350
332
 
351
- on(eventType: any, callback: any) {
352
- this.off(eventType);
353
- switch (eventType) {
354
- case "click":
355
- this.event[eventType] = (event: any) => {
356
- callback(event.lngLat);
357
- };
358
- break;
359
- case "dblclick":
360
- this.event[eventType] = (event: any) => {
361
- callback(event);
362
- };
363
- break;
364
- case "cameraMoveEnd":
365
- this.event[eventType] = () => {
366
- this.map.on("moveend", (event: any) => callback(event)); // 地图移动完成
367
- this.map.on("zoomend", (event: any) => callback(event)); // 地图缩放完成
368
- this.map.on("pitchend", (event: any) => callback(event)); // 地图俯仰角度完成
369
- };
370
- this.event[eventType]()
371
- break;
372
- //镜头移动事件
373
- case "moveend":
374
- this.event[eventType] = (event: any) => {
375
- callback(event);
376
- };
377
- break;
378
- case "zoomend": //"levelend"
379
- this.event[eventType] = (event: any) => {
380
- callback(event);
381
- };
382
- break;
383
- case "mouseenter":
384
- this.event[eventType] = (event: any) => {
385
- callback(event);
386
- };
387
- break;
388
- case "mouseleave":
389
- this.event[eventType] = (event: any) => {
390
- callback(event);
391
- };
392
- break;
393
- case "mousemove":
394
- this.event[eventType] = (event: any) => {
395
- callback(event);
396
- };
397
- break;
398
- }
399
- this.map.on(eventType, this.event[eventType]);
400
- }
333
+ if (layer.id) {
334
+ this.layerList = this.layerList.filter((v: any) => v.id !== layerId);
335
+ layer.destroy();
336
+ }
337
+ }
401
338
 
402
- off(eventType: any) {
403
- if (this.event[eventType]) {
404
- this.map.off(eventType, this.event[eventType]);
405
- delete this.event[eventType];
406
- }
407
- }
339
+ clearLayer(layerId: any) {
340
+ const layer = this.getLayer(layerId);
341
+ if (layer) {
342
+ layer.children = [];
343
+ layer.clearEntity();
344
+ }
345
+ }
408
346
 
409
- // 更新当前地图参数
410
- private updateMapParams(e: any) {
411
- this.level = this.map.getZoom();
412
- let viewPos = this.getExtent()
413
- console.log("当前缩放级别level:", this.level);
414
- if (this.level !== this.option.level) {
415
- this.layerList.forEach((layer: any) => {
416
- layer.children.forEach((entity: any) => {
417
- entity.option.distanceDisplayCondition && layer.updateEntity(entity,viewPos)
418
- });
419
- });
420
- } else {
421
- return;
422
- }
347
+ getExtent() {
348
+ const data = this.map.getBounds();
349
+ return {
350
+ xmin: data._sw.lng,
351
+ ymin: data._sw.lat,
352
+ xmax: data._ne.lng,
353
+ ymax: data._ne.lat,
354
+ };
355
+ }
423
356
 
424
- }
357
+ on(eventType: any, callback: any) {
358
+ this.off(eventType);
359
+ switch (eventType) {
360
+ case "click":
361
+ this.event[eventType] = (event: any) => {
362
+ callback(event);
363
+ };
364
+ break;
365
+ case "dblclick":
366
+ this.event[eventType] = (event: any) => {
367
+ callback(event);
368
+ };
369
+ break;
370
+ case "cameraMoveEnd":
371
+ this.event[eventType] = () => {
372
+ this.map.on("moveend", (event: any) => callback(event)); // 地图移动完成
373
+ this.map.on("zoomend", (event: any) => callback(event)); // 地图缩放完成
374
+ this.map.on("pitchend", (event: any) => callback(event)); // 地图俯仰角度完成
375
+ };
376
+ this.event[eventType]();
377
+ break;
378
+ //镜头移动事件
379
+ case "moveend":
380
+ this.event[eventType] = (event: any) => {
381
+ callback(event);
382
+ };
383
+ break;
384
+ case "zoomend": //"levelend"
385
+ this.event[eventType] = (event: any) => {
386
+ callback(event);
387
+ };
388
+ break;
389
+ case "mouseenter":
390
+ this.event[eventType] = (event: any) => {
391
+ callback(event);
392
+ };
393
+ break;
394
+ case "mouseleave":
395
+ this.event[eventType] = (event: any) => {
396
+ callback(event);
397
+ };
398
+ break;
399
+ case "mousemove":
400
+ this.event[eventType] = (event: any) => {
401
+ callback(event);
402
+ };
403
+ break;
404
+ }
405
+ this.map.on(eventType, this.event[eventType]);
406
+ }
407
+
408
+ off(eventType: any) {
409
+ if (this.event[eventType]) {
410
+ this.map.off(eventType, this.event[eventType]);
411
+ delete this.event[eventType];
412
+ }
425
413
  }
426
414
 
427
- const map: any = {
428
- mars3d: mars3d_map,
429
- gaode: gaode_map,
430
- siji: siji_map,
431
- };
432
- return map[hnMap.mapType];
415
+ // 更新当前地图参数
416
+ private updateMapParams(e: any) {
417
+ this.level = this.map.getZoom();
418
+ let viewPos = this.getExtent();
419
+ console.log("当前缩放级别level:", this.level);
420
+ if (this.level !== this.option.level) {
421
+ this.layerList.forEach((layer: any) => {
422
+ layer.children.forEach((entity: any) => {
423
+ entity.option.distanceDisplayCondition &&
424
+ layer.updateEntity(entity, viewPos);
425
+ });
426
+ });
427
+ } else {
428
+ return;
429
+ }
430
+ }
431
+ }
432
+
433
+ const map: any = {
434
+ mars3d: mars3d_map,
435
+ gaode: gaode_map,
436
+ siji: siji_map,
437
+ };
438
+ return map[hnMap.mapType];
433
439
  };