hn-map 1.1.3 → 1.1.5
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 +45 -8
- package/package.json +1 -1
- package/src/graphic/circle.ts +7 -3
- package/src/layer/layer.ts +11 -1
- package/src/map.ts +33 -6
- package/src/util.ts +145 -136
- package/src/other/geocodingTask.ts +0 -120
package/dist/index.js
CHANGED
|
@@ -767,13 +767,6 @@
|
|
|
767
767
|
this.map.on("pitchend", function (e) {
|
|
768
768
|
return _this2.updateMapParams(e);
|
|
769
769
|
}); // 地图俯仰角度完成
|
|
770
|
-
this.map.on("load", function (e) {
|
|
771
|
-
// 路况展示
|
|
772
|
-
var roadNetLayer = new SGMap.RoadNetLayer({
|
|
773
|
-
map: _this2.map
|
|
774
|
-
});
|
|
775
|
-
roadNetLayer.render();
|
|
776
|
-
});
|
|
777
770
|
}
|
|
778
771
|
return _createClass(siji_map, [{
|
|
779
772
|
key: "formatConfig",
|
|
@@ -850,7 +843,11 @@
|
|
|
850
843
|
switch (eventType) {
|
|
851
844
|
case "click":
|
|
852
845
|
this.event[eventType] = function (event) {
|
|
853
|
-
callback(
|
|
846
|
+
callback({
|
|
847
|
+
lng: event.lngLat.lng,
|
|
848
|
+
lat: event.lngLat.lat,
|
|
849
|
+
alt: event.lngLat.alt || 0
|
|
850
|
+
});
|
|
854
851
|
};
|
|
855
852
|
break;
|
|
856
853
|
case "dblclick":
|
|
@@ -939,6 +936,32 @@
|
|
|
939
936
|
_context3.n = 1;
|
|
940
937
|
return new Promise(function (resolve) {
|
|
941
938
|
instance.map.on("load", function (e) {
|
|
939
|
+
// 路况展示
|
|
940
|
+
var roadNetLayer = new SGMap.RoadNetLayer({
|
|
941
|
+
map: instance.map
|
|
942
|
+
});
|
|
943
|
+
roadNetLayer.render();
|
|
944
|
+
//添加天空图层
|
|
945
|
+
instance.map.addLayer({
|
|
946
|
+
"id": "sky",
|
|
947
|
+
"type": "sky",
|
|
948
|
+
"paint": {
|
|
949
|
+
"sky-type": "atmosphere",
|
|
950
|
+
"sky-atmosphere-sun": [0, 0],
|
|
951
|
+
"sky-atmosphere-sun-intensity": 15
|
|
952
|
+
}
|
|
953
|
+
});
|
|
954
|
+
// 加载地形(需要v3.1.0,且需要新的key和secret)
|
|
955
|
+
// !instance.map.getSource('terrain') && instance.map.addSource('terrain',{
|
|
956
|
+
// type:'raster-dem',
|
|
957
|
+
// url:"aegis://aegis.Terrain3D",//地形高程数据源名称
|
|
958
|
+
// tileSize:512,
|
|
959
|
+
//
|
|
960
|
+
// })
|
|
961
|
+
// instance.map.setTerrain({
|
|
962
|
+
// source:'terrain',
|
|
963
|
+
// exaggeration:1,//地形夸张比例
|
|
964
|
+
// })
|
|
942
965
|
resolve(e);
|
|
943
966
|
});
|
|
944
967
|
});
|
|
@@ -1389,6 +1412,10 @@
|
|
|
1389
1412
|
hnMap.map.map.removeLayer(entity.config_routeplay.id);
|
|
1390
1413
|
hnMap.map.map.removeSource(entity.config_routeplay.id);
|
|
1391
1414
|
entity.imgMarker.remove();
|
|
1415
|
+
} else if (entity.type == "imagePoint") {
|
|
1416
|
+
hnMap.map.map.removeImage(entity.id + "_image");
|
|
1417
|
+
hnMap.map.map.removeLayer(entity.id);
|
|
1418
|
+
hnMap.map.map.removeSource(entity.id);
|
|
1392
1419
|
} else {
|
|
1393
1420
|
hnMap.map.map.removeLayer(entity.id);
|
|
1394
1421
|
hnMap.map.map.removeSource(entity.id);
|
|
@@ -1396,6 +1423,15 @@
|
|
|
1396
1423
|
entity.show = false;
|
|
1397
1424
|
}
|
|
1398
1425
|
}
|
|
1426
|
+
// 控制图层层高
|
|
1427
|
+
}, {
|
|
1428
|
+
key: "moveEntity",
|
|
1429
|
+
value: function moveEntity(layerIds) {
|
|
1430
|
+
// 数组转字符串
|
|
1431
|
+
var s = layerIds.join(",");
|
|
1432
|
+
console.log("s===", s);
|
|
1433
|
+
hnMap.map.map.moveLayer(s);
|
|
1434
|
+
}
|
|
1399
1435
|
}, {
|
|
1400
1436
|
key: "clearEntity",
|
|
1401
1437
|
value: function clearEntity() {
|
|
@@ -5297,6 +5333,7 @@
|
|
|
5297
5333
|
case 0:
|
|
5298
5334
|
// 判断是否在子路径下
|
|
5299
5335
|
basePath = window.location.pathname.endsWith("/") ? window.location.pathname : window.location.pathname.substring(0, window.location.pathname.lastIndexOf("/") + 1);
|
|
5336
|
+
console.log(basePath);
|
|
5300
5337
|
_context.n = 1;
|
|
5301
5338
|
return loadResource(basePath + "lib/turf/turf.min.js", "js");
|
|
5302
5339
|
case 1:
|
package/package.json
CHANGED
package/src/graphic/circle.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {deepMerge, getLevelMiddleHeight, wgs84ToGcj02Format} from "../util";
|
|
1
|
+
import { deepMerge, getLevelMiddleHeight, wgs84ToGcj02Format } from "../util";
|
|
2
2
|
import mars3d_entity from "../base/mars3d_entity";
|
|
3
3
|
import gaode_entity from "../base/gaode_entity";
|
|
4
4
|
import siji_entity from "../base/siji_entity";
|
|
@@ -42,8 +42,12 @@ export default (hnMap: any) => {
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
formatConfig(option: any) {
|
|
45
|
-
const distanceDisplayCondition_far = getLevelMiddleHeight(
|
|
46
|
-
|
|
45
|
+
const distanceDisplayCondition_far = getLevelMiddleHeight(
|
|
46
|
+
option.distanceDisplayCondition_far
|
|
47
|
+
);
|
|
48
|
+
const distanceDisplayCondition_near = getLevelMiddleHeight(
|
|
49
|
+
option.distanceDisplayCondition_near
|
|
50
|
+
);
|
|
47
51
|
let config: any = {
|
|
48
52
|
id: option.id,
|
|
49
53
|
position: new mars3d.LngLatPoint(
|
package/src/layer/layer.ts
CHANGED
|
@@ -394,6 +394,10 @@ export default (hnMap: any) => {
|
|
|
394
394
|
hnMap.map.map.removeLayer(entity.config_routeplay.id);
|
|
395
395
|
hnMap.map.map.removeSource(entity.config_routeplay.id);
|
|
396
396
|
entity.imgMarker.remove();
|
|
397
|
+
} else if (entity.type == "imagePoint") {
|
|
398
|
+
hnMap.map.map.removeImage(entity.id + "_image");
|
|
399
|
+
hnMap.map.map.removeLayer(entity.id);
|
|
400
|
+
hnMap.map.map.removeSource(entity.id);
|
|
397
401
|
} else {
|
|
398
402
|
hnMap.map.map.removeLayer(entity.id);
|
|
399
403
|
hnMap.map.map.removeSource(entity.id);
|
|
@@ -401,7 +405,13 @@ export default (hnMap: any) => {
|
|
|
401
405
|
entity.show = false;
|
|
402
406
|
}
|
|
403
407
|
}
|
|
404
|
-
|
|
408
|
+
// 控制图层层高
|
|
409
|
+
moveEntity(layerIds: Array<string>) {
|
|
410
|
+
// 数组转字符串
|
|
411
|
+
let s = layerIds.join(",");
|
|
412
|
+
console.log("s===", s);
|
|
413
|
+
hnMap.map.map.moveLayer(s);
|
|
414
|
+
}
|
|
405
415
|
clearEntity() {
|
|
406
416
|
this.children.forEach((v: any) => {
|
|
407
417
|
this.removeEntity(v.id);
|
package/src/map.ts
CHANGED
|
@@ -277,11 +277,6 @@ export default (hnMap: any) => {
|
|
|
277
277
|
this.map.on("moveend", (e: any) => this.updateMapParams(e)); // 地图移动完成
|
|
278
278
|
this.map.on("zoomend", (e: any) => this.updateMapParams(e)); // 地图缩放完成
|
|
279
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
280
|
}
|
|
286
281
|
|
|
287
282
|
static async create(id: string, option: any) {
|
|
@@ -290,6 +285,34 @@ export default (hnMap: any) => {
|
|
|
290
285
|
// 返回一个 Promise,等待地图的 'load' 事件
|
|
291
286
|
await new Promise((resolve) => {
|
|
292
287
|
instance.map.on("load", (e: any) => {
|
|
288
|
+
// 路况展示
|
|
289
|
+
let roadNetLayer = new SGMap.RoadNetLayer({ map: instance.map });
|
|
290
|
+
roadNetLayer.render();
|
|
291
|
+
//添加天空图层
|
|
292
|
+
instance.map.addLayer({
|
|
293
|
+
"id": "sky",
|
|
294
|
+
"type": "sky",
|
|
295
|
+
"paint": {
|
|
296
|
+
"sky-type": "atmosphere",
|
|
297
|
+
"sky-atmosphere-sun": [
|
|
298
|
+
0,
|
|
299
|
+
0
|
|
300
|
+
],
|
|
301
|
+
"sky-atmosphere-sun-intensity": 15
|
|
302
|
+
}
|
|
303
|
+
})
|
|
304
|
+
|
|
305
|
+
// 加载地形(需要v3.1.0,且需要新的key和secret)
|
|
306
|
+
// !instance.map.getSource('terrain') && instance.map.addSource('terrain',{
|
|
307
|
+
// type:'raster-dem',
|
|
308
|
+
// url:"aegis://aegis.Terrain3D",//地形高程数据源名称
|
|
309
|
+
// tileSize:512,
|
|
310
|
+
//
|
|
311
|
+
// })
|
|
312
|
+
// instance.map.setTerrain({
|
|
313
|
+
// source:'terrain',
|
|
314
|
+
// exaggeration:1,//地形夸张比例
|
|
315
|
+
// })
|
|
293
316
|
resolve(e);
|
|
294
317
|
});
|
|
295
318
|
});
|
|
@@ -359,7 +382,11 @@ export default (hnMap: any) => {
|
|
|
359
382
|
switch (eventType) {
|
|
360
383
|
case "click":
|
|
361
384
|
this.event[eventType] = (event: any) => {
|
|
362
|
-
callback(
|
|
385
|
+
callback({
|
|
386
|
+
lng: event.lngLat.lng,
|
|
387
|
+
lat: event.lngLat.lat,
|
|
388
|
+
alt: event.lngLat.alt || 0,
|
|
389
|
+
});
|
|
363
390
|
};
|
|
364
391
|
break;
|
|
365
392
|
case "dblclick":
|
package/src/util.ts
CHANGED
|
@@ -15,36 +15,36 @@
|
|
|
15
15
|
|
|
16
16
|
// 对象深度合并
|
|
17
17
|
export function deepMerge(target: any, source: any): any {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
18
|
+
for (let key of Object.keys(source)) {
|
|
19
|
+
if (source[key] instanceof Object && !Array.isArray(source[key])) {
|
|
20
|
+
if (!target[key]) Object.assign(target, { [key]: {} });
|
|
21
|
+
deepMerge(target[key], source[key]);
|
|
22
|
+
} else {
|
|
23
|
+
Object.assign(target, { [key]: source[key] });
|
|
25
24
|
}
|
|
26
|
-
|
|
25
|
+
}
|
|
26
|
+
return target;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
// 递归格式化高德坐标系
|
|
30
30
|
export function wgs84ToGcj02Format(position: any): any {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
31
|
+
// 判断是否是数组
|
|
32
|
+
if (position.every((item: any) => Array.isArray(item))) {
|
|
33
|
+
return position.map((item: any) => {
|
|
34
|
+
return wgs84ToGcj02Format(item);
|
|
35
|
+
});
|
|
36
|
+
} else if (position.every((item: any) => typeof item === "object")) {
|
|
37
|
+
return position.map((item: any) => {
|
|
38
|
+
let data = wgs84ToGcj02Format([item.lng, item.lat]);
|
|
39
|
+
return {
|
|
40
|
+
...item,
|
|
41
|
+
lng: data[0],
|
|
42
|
+
lat: data[1],
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
} else {
|
|
46
|
+
return wgs84ToGcj02(position[0], position[1]);
|
|
47
|
+
}
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
/**
|
|
@@ -54,66 +54,66 @@ export function wgs84ToGcj02Format(position: any): any {
|
|
|
54
54
|
* @returns {[number, number]} GCJ-02经纬度数组
|
|
55
55
|
*/
|
|
56
56
|
export function wgs84ToGcj02(wgsLng: any, wgsLat: any): any {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
57
|
+
if (!isCorrectPosition(wgsLng, wgsLat)) {
|
|
58
|
+
return [wgsLng, wgsLat];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const a = 6378245.0; // 长半轴
|
|
62
|
+
const ee = 0.00669342162296594323; // 扁率
|
|
63
|
+
|
|
64
|
+
function transformLat(x: any, y: any): any {
|
|
65
|
+
let ret =
|
|
66
|
+
-100.0 +
|
|
67
|
+
2.0 * x +
|
|
68
|
+
3.0 * y +
|
|
69
|
+
0.2 * y * y +
|
|
70
|
+
0.1 * x * y +
|
|
71
|
+
0.2 * Math.sqrt(Math.abs(x));
|
|
72
|
+
ret +=
|
|
73
|
+
((20.0 * Math.sin(6.0 * x * Math.PI) +
|
|
74
|
+
20.0 * Math.sin(2.0 * x * Math.PI)) *
|
|
75
|
+
2.0) /
|
|
76
|
+
3.0;
|
|
77
|
+
ret +=
|
|
78
|
+
((160.0 * Math.sin((y * Math.PI) / 3.0) +
|
|
79
|
+
320 * Math.sin((y * Math.PI) / 30.0)) *
|
|
80
|
+
2.0) /
|
|
81
|
+
3.0;
|
|
82
|
+
return ret;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function transformLng(x: any, y: any): any {
|
|
86
|
+
let ret =
|
|
87
|
+
300.0 +
|
|
88
|
+
x +
|
|
89
|
+
2.0 * y +
|
|
90
|
+
0.1 * x * x +
|
|
91
|
+
0.1 * x * y +
|
|
92
|
+
0.1 * Math.sqrt(Math.abs(x));
|
|
93
|
+
ret +=
|
|
94
|
+
((20.0 * Math.sin(6.0 * x * Math.PI) + 20.0 * Math.sin(x * Math.PI)) *
|
|
95
|
+
2.0) /
|
|
96
|
+
3.0;
|
|
97
|
+
ret +=
|
|
98
|
+
((150.0 * Math.sin((x * Math.PI) / 3.0) +
|
|
99
|
+
300.0 * Math.sin((x * Math.PI) / 15.0)) *
|
|
100
|
+
2.0) /
|
|
101
|
+
3.0;
|
|
102
|
+
return ret;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
let dLat = transformLat(wgsLng - 105.0, wgsLat - 35.0);
|
|
106
|
+
let dLng = transformLng(wgsLng - 105.0, wgsLat - 35.0);
|
|
107
|
+
const radLat = (wgsLat / 180.0) * Math.PI;
|
|
108
|
+
let magic = Math.sin(radLat);
|
|
109
|
+
magic = 1 - ee * magic * magic;
|
|
110
|
+
const sqrtMagic = Math.sqrt(magic);
|
|
111
|
+
dLat = (dLat * 180.0) / (((a * (1 - ee)) / (magic * sqrtMagic)) * Math.PI);
|
|
112
|
+
dLng = (dLng * 180.0) / ((a / sqrtMagic) * Math.cos(radLat) * Math.PI);
|
|
113
|
+
const gcjLat = wgsLat + dLat;
|
|
114
|
+
const gcjLng = wgsLng + dLng;
|
|
115
|
+
|
|
116
|
+
return [gcjLng, gcjLat];
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
/**
|
|
@@ -123,46 +123,46 @@ export function wgs84ToGcj02(wgsLng: any, wgsLat: any): any {
|
|
|
123
123
|
* @returns {boolean}
|
|
124
124
|
*/
|
|
125
125
|
export function isCorrectPosition(lng: any, lat: any): boolean {
|
|
126
|
-
|
|
126
|
+
return lng <= 180 && lng >= -180 && lat <= 90 && lat >= -90;
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
// 根据矩形左上角和右上角坐标计算矩形坐标对
|
|
130
130
|
export function createRectangleCoordinates(leftTop: any, rightBottom: any) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
131
|
+
const [leftTopLng, leftTopLat] = leftTop;
|
|
132
|
+
const [rightBottomLng, rightBottomLat] = rightBottom;
|
|
133
|
+
|
|
134
|
+
// 计算四个角点
|
|
135
|
+
const leftTopPoint = [Number(leftTopLng), Number(leftTopLat)];
|
|
136
|
+
const rightTopPoint = [Number(rightBottomLng), Number(leftTopLat)];
|
|
137
|
+
const rightBottomPoint = [Number(rightBottomLng), Number(rightBottomLat)];
|
|
138
|
+
const leftBottomPoint = [Number(leftTopLng), Number(rightBottomLat)];
|
|
139
|
+
|
|
140
|
+
// 返回五个点的坐标对(首尾相同)
|
|
141
|
+
return [
|
|
142
|
+
leftTopPoint,
|
|
143
|
+
rightTopPoint,
|
|
144
|
+
rightBottomPoint,
|
|
145
|
+
leftBottomPoint,
|
|
146
|
+
leftTopPoint, // 闭合矩形
|
|
147
|
+
];
|
|
148
148
|
}
|
|
149
149
|
|
|
150
150
|
export function getMapRangeHeightByLevel(level: number) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
}
|
|
151
|
+
// 输入校验:限制在 1~18
|
|
152
|
+
level = Math.max(1, Math.min(18, Math.floor(level)));
|
|
153
|
+
|
|
154
|
+
// 计算指定 level 对应的高度(level >= 2 时使用指数衰减)
|
|
155
|
+
function getHeight(lvl: number) {
|
|
156
|
+
if (lvl === 1) {
|
|
157
|
+
return Infinity; // level=1 表示“最大高度”,逻辑上为无穷大
|
|
158
|
+
} else {
|
|
159
|
+
return 32000000 / Math.pow(2, lvl - 2);
|
|
161
160
|
}
|
|
161
|
+
}
|
|
162
162
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
163
|
+
const endHeight = getHeight(level); // 当前 level 的“粗略”高度
|
|
164
|
+
const startHeight = level < 18 ? getHeight(level + 1) : 0; // 下一级更细
|
|
165
|
+
return { startHeight, endHeight };
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
/**
|
|
@@ -172,18 +172,17 @@ export function getMapRangeHeightByLevel(level: number) {
|
|
|
172
172
|
* @returns {number} 中间高度(米)
|
|
173
173
|
*/
|
|
174
174
|
export function getLevelMiddleHeight(level: number): number {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
175
|
+
const { startHeight, endHeight } = getMapRangeHeightByLevel(level);
|
|
176
|
+
// 如果 startHeight 为 0(如 level=18),几何平均会为 0,不合理
|
|
177
|
+
// 所以 level=18 特殊处理:返回 (0 + end)/2 或直接返回 end * 0.7 左右
|
|
178
|
+
if (startHeight === 0) {
|
|
179
|
+
return endHeight * 0.7; // 经验值,贴近“中间感知”
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// 几何平均:√(start × end)
|
|
183
|
+
return Math.sqrt(startHeight * endHeight);
|
|
184
184
|
}
|
|
185
185
|
|
|
186
|
-
|
|
187
186
|
/**
|
|
188
187
|
* 根据地图缩放级别(level),返回对应的视野高度范围
|
|
189
188
|
* 规则:
|
|
@@ -194,8 +193,8 @@ export function getLevelMiddleHeight(level: number): number {
|
|
|
194
193
|
* @returns {[number, number]} [开始高度, 结束高度](单位:米)
|
|
195
194
|
*/
|
|
196
195
|
export function getLevelHeightRange(level: number): [number, number] {
|
|
197
|
-
|
|
198
|
-
|
|
196
|
+
const { startHeight, endHeight } = getMapRangeHeightByLevel(level);
|
|
197
|
+
return [startHeight, endHeight];
|
|
199
198
|
}
|
|
200
199
|
|
|
201
200
|
/**
|
|
@@ -203,14 +202,24 @@ export function getLevelHeightRange(level: number): [number, number] {
|
|
|
203
202
|
* @param {number} height - 当前视野高度(米)
|
|
204
203
|
* @returns {number} level
|
|
205
204
|
*/
|
|
206
|
-
export function getHeightToLevel(height:number): number {
|
|
207
|
-
|
|
208
|
-
|
|
205
|
+
export function getHeightToLevel(height: number): number {
|
|
206
|
+
if (height > 32000000) return 1;
|
|
207
|
+
if (height <= 0) return 18;
|
|
209
208
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
209
|
+
// 解公式:height = 32e6 / 2^(level-2)
|
|
210
|
+
let level = 2 + Math.log(32000000 / height) / Math.log(2);
|
|
211
|
+
level = Math.floor(level);
|
|
213
212
|
|
|
214
|
-
|
|
215
|
-
|
|
213
|
+
// 限制在 1~18
|
|
214
|
+
return Math.max(1, Math.min(18, level));
|
|
215
|
+
}
|
|
216
|
+
// 將坐标数组中的元素字符串类型统一处理为number类型
|
|
217
|
+
export function convertPosition(
|
|
218
|
+
position: string[] | string[][]
|
|
219
|
+
): number[] | number[][] {
|
|
220
|
+
return position.map((item) =>
|
|
221
|
+
Array.isArray(item)
|
|
222
|
+
? (item as string[]).map((str) => Number(str))
|
|
223
|
+
: Number(item)
|
|
224
|
+
) as number[] | number[][];
|
|
216
225
|
}
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { deepMerge, wgs84ToGcj02Format } from "../util";
|
|
2
|
-
|
|
3
|
-
export default (hnMap: any) => {
|
|
4
|
-
const defaultOption = {
|
|
5
|
-
id: "",
|
|
6
|
-
position: [],
|
|
7
|
-
addressName: "", //地址名称
|
|
8
|
-
region: "", //地址
|
|
9
|
-
isEncode: false, //是否进行坐标转换
|
|
10
|
-
iconSize: 13,
|
|
11
|
-
offfset: [0, 0],
|
|
12
|
-
color: "#fff",
|
|
13
|
-
text: "",
|
|
14
|
-
data: null,
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
class mars3d_class {
|
|
18
|
-
type: any = "geocodingTask";
|
|
19
|
-
id: any = null;
|
|
20
|
-
option: any = JSON.parse(JSON.stringify(defaultOption));
|
|
21
|
-
config: any = null;
|
|
22
|
-
layerEntity: any = null;
|
|
23
|
-
|
|
24
|
-
constructor(option: any) {
|
|
25
|
-
this.id = option.id;
|
|
26
|
-
deepMerge(this.option, option);
|
|
27
|
-
this.config = this.formatConfig(this.option);
|
|
28
|
-
this.layerEntity = new mars3d.layer.HeatLayer(
|
|
29
|
-
JSON.parse(JSON.stringify(this.config))
|
|
30
|
-
);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
formatConfig(option: any) {
|
|
34
|
-
return {
|
|
35
|
-
id: option.id,
|
|
36
|
-
positions: option.position,
|
|
37
|
-
|
|
38
|
-
style: {
|
|
39
|
-
opacity: option.opacity,
|
|
40
|
-
scaleByDistance: option.scaleByDistance,
|
|
41
|
-
clampToGround: option.clampToGround,
|
|
42
|
-
},
|
|
43
|
-
|
|
44
|
-
attr: option.data,
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
set(option: any) {
|
|
49
|
-
deepMerge(this.option, option);
|
|
50
|
-
this.config = this.formatConfig(this.option);
|
|
51
|
-
this.layerEntity.setOptions(this.config);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
destroy() {
|
|
55
|
-
this.layerEntity.remove(true);
|
|
56
|
-
hnMap.map.layerList = hnMap.map.layerList.filter(
|
|
57
|
-
(v: any) => v.id !== this.id
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
flyTo() {
|
|
62
|
-
this.layerEntity.flyTo();
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
clear() {
|
|
66
|
-
this.layerEntity.clear();
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
setPosition(position: any) {
|
|
70
|
-
deepMerge(this.option, { position });
|
|
71
|
-
this.layerEntity.setPositions(position);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
show() {
|
|
75
|
-
this.layerEntity.show = true;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
hide() {
|
|
79
|
-
this.layerEntity.show = false;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
class siji_class {
|
|
84
|
-
id: any = null;
|
|
85
|
-
option: any = JSON.parse(JSON.stringify(defaultOption));
|
|
86
|
-
config: any = null;
|
|
87
|
-
layerEntity: any = null;
|
|
88
|
-
|
|
89
|
-
constructor(option: any) {
|
|
90
|
-
this.id = option.id;
|
|
91
|
-
deepMerge(this.option, option);
|
|
92
|
-
this.layerEntity = new SGMap.GeocodingTask();
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
getLnglat(option: any) {
|
|
96
|
-
// return new Promise((resolve, reject) => {
|
|
97
|
-
this.layerEntity
|
|
98
|
-
.getLocation({
|
|
99
|
-
address: option.addressName,
|
|
100
|
-
region: option.region,
|
|
101
|
-
isEncode: option.isEncode,
|
|
102
|
-
})
|
|
103
|
-
.then(function (res: any) {
|
|
104
|
-
return res.location;
|
|
105
|
-
});
|
|
106
|
-
// });
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
easeTo(option: any) {
|
|
110
|
-
hnMap.map.map.easeTo(option);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const fn: any = {
|
|
115
|
-
mars3d: mars3d_class,
|
|
116
|
-
siji: siji_class,
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
return fn[hnMap.mapType];
|
|
120
|
-
};
|