@hzab/map-combine 0.4.2-alpha.7 → 0.4.2-alpha.8
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/CHANGELOG.md +77 -75
- package/README.md +83 -83
- package/package.json +3 -4
- package/src/amap/AMapEvent.ts +55 -0
- package/src/amap/AMapPoint.ts +3 -0
- package/src/amap/AMapPolygon.ts +29 -11
- package/src/amap/AMapPolyline.ts +16 -3
- package/src/amap/loader.ts +58 -58
- package/src/basic/MapCombine.ts +102 -102
- package/src/basic/ReactPoint.tsx +363 -363
- package/src/cesium/CesiumMap.ts +17 -0
- package/src/cesium/CesiumTile3D.ts +225 -225
- package/src/mine/MineEvent.ts +16 -1
- package/src/mine/MineMap.ts +125 -125
- package/src/mine/MinePoint.ts +6 -0
- package/src/mine/MinePolygon.ts +4 -0
- package/src/mine/MinePolyline.ts +4 -0
- package/src/utils/color.ts +49 -0
package/src/mine/MineMap.ts
CHANGED
|
@@ -1,125 +1,125 @@
|
|
|
1
|
-
import { MapCombine } from "../basic/MapCombine";
|
|
2
|
-
import { PointOption, Point } from "../basic/Point";
|
|
3
|
-
import { PointAggregationOption, PointAggregation } from "../basic/PointAggregation";
|
|
4
|
-
import { PolygonOption, Polygon } from "../basic/Polygon";
|
|
5
|
-
import { PolylineOption, Polyline } from "../basic/Polyline";
|
|
6
|
-
import { Tile3DOption, Tile3D } from "../basic/Tile3D";
|
|
7
|
-
import { bindEvent } from "./MineEvent";
|
|
8
|
-
import { drawPoint } from "./MinePoint";
|
|
9
|
-
import { drawPolygon } from "./MinePolygon";
|
|
10
|
-
import { drawPolyline } from "./MinePolyline";
|
|
11
|
-
import { drawTile3D } from "./MineTile3D";
|
|
12
|
-
|
|
13
|
-
const MAX_ZOOM = 18;
|
|
14
|
-
|
|
15
|
-
export class MineMap extends MapCombine {
|
|
16
|
-
viewer: any;
|
|
17
|
-
container: HTMLDivElement;
|
|
18
|
-
|
|
19
|
-
get cursor(): string {
|
|
20
|
-
return this.viewer.getCursor();
|
|
21
|
-
}
|
|
22
|
-
set cursor(val: string) {
|
|
23
|
-
this.viewer.setCursor(val);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
get moveable(): boolean {
|
|
27
|
-
return this.viewer.dragPan.isEnabled();
|
|
28
|
-
}
|
|
29
|
-
set moveable(val: boolean) {
|
|
30
|
-
val ? this.viewer.dragPan.enable() : this.viewer.dragPan.disable();
|
|
31
|
-
}
|
|
32
|
-
get center(): number[] {
|
|
33
|
-
const p = this.viewer.getCenter();
|
|
34
|
-
return [p.lng, p.lat];
|
|
35
|
-
}
|
|
36
|
-
set center(val: number[]) {
|
|
37
|
-
this.viewer.setCenter(val);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
get zoom(): number {
|
|
41
|
-
return this.viewer.getZoom();
|
|
42
|
-
}
|
|
43
|
-
set zoom(val: number) {
|
|
44
|
-
this.viewer.setZoom(val);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
constructor(viewer: any) {
|
|
48
|
-
super();
|
|
49
|
-
this.viewer = viewer;
|
|
50
|
-
this.container = viewer.getContainer();
|
|
51
|
-
this.container.children.item(1).appendChild(this.htmllayer);
|
|
52
|
-
this.cursor = "default";
|
|
53
|
-
bindEvent(this);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
canvasTgeography(p: number[]): number[] {
|
|
57
|
-
const res = this.viewer.getTDSpaceCoord({ point: p, disableLayer: true });
|
|
58
|
-
return [res.lngLat.lng, res.lngLat.lat, 0];
|
|
59
|
-
}
|
|
60
|
-
geographyTcanvas(p: number[]): number[] {
|
|
61
|
-
const res = this.viewer.project([p[0], p[1]], p[2] ?? 0);
|
|
62
|
-
return [res.x, res.y];
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
createPoint<K>(option?: Partial<PointOption<K>>): Point<K> {
|
|
66
|
-
const e = new Point(this, option);
|
|
67
|
-
drawPoint(this, e);
|
|
68
|
-
return e;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
createPointAggregation(option?: PointAggregationOption): PointAggregation {
|
|
72
|
-
const e = new PointAggregation(this, option);
|
|
73
|
-
return e;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
createPolyline<K>(option?: Partial<PolylineOption<K>>): Polyline<K> {
|
|
77
|
-
const e = new Polyline(this, option);
|
|
78
|
-
drawPolyline(this, e);
|
|
79
|
-
return e;
|
|
80
|
-
}
|
|
81
|
-
createPolygon<K>(option?: Partial<PolygonOption<K>>): Polygon<K> {
|
|
82
|
-
const e = new Polygon(this, option);
|
|
83
|
-
drawPolygon(this, e);
|
|
84
|
-
return e;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* 所有点位移动至视口,调整位置及层级
|
|
89
|
-
* @param points
|
|
90
|
-
* @param opt
|
|
91
|
-
* @param {Array<number> = [0,0,0,0]} opt.avoid 距离边框的内边距,顺序:上、下、左、右
|
|
92
|
-
*/
|
|
93
|
-
flyToViewer(points, opt = { avoid: [0, 0, 0, 0], maxZoom: MAX_ZOOM }) {
|
|
94
|
-
if (points?.length === 0) {
|
|
95
|
-
return this.flyTo(points[0], opt);
|
|
96
|
-
}
|
|
97
|
-
const rectangle = this.getBounds(points, { canvas: this.viewer.getCanvas(), ...opt });
|
|
98
|
-
|
|
99
|
-
// 设置地图视图,使用调整后的边界范围
|
|
100
|
-
this.viewer.fitBounds(
|
|
101
|
-
[
|
|
102
|
-
[rectangle[0], rectangle[1]],
|
|
103
|
-
[rectangle[2], rectangle[3]],
|
|
104
|
-
],
|
|
105
|
-
{
|
|
106
|
-
maxZoom: opt?.maxZoom ?? MAX_ZOOM,
|
|
107
|
-
},
|
|
108
|
-
);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* 移动点位到中心点
|
|
113
|
-
* @param point
|
|
114
|
-
*/
|
|
115
|
-
flyTo(point, opt = {}) {
|
|
116
|
-
// 设置相机视角
|
|
117
|
-
this.viewer.flyTo({ center: point, ...opt });
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
createTile3D(option?: Partial<Tile3DOption>): Tile3D {
|
|
121
|
-
const e = new Tile3D(this, option);
|
|
122
|
-
drawTile3D(this, e);
|
|
123
|
-
return e;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
1
|
+
import { MapCombine } from "../basic/MapCombine";
|
|
2
|
+
import { PointOption, Point } from "../basic/Point";
|
|
3
|
+
import { PointAggregationOption, PointAggregation } from "../basic/PointAggregation";
|
|
4
|
+
import { PolygonOption, Polygon } from "../basic/Polygon";
|
|
5
|
+
import { PolylineOption, Polyline } from "../basic/Polyline";
|
|
6
|
+
import { Tile3DOption, Tile3D } from "../basic/Tile3D";
|
|
7
|
+
import { bindEvent } from "./MineEvent";
|
|
8
|
+
import { drawPoint } from "./MinePoint";
|
|
9
|
+
import { drawPolygon } from "./MinePolygon";
|
|
10
|
+
import { drawPolyline } from "./MinePolyline";
|
|
11
|
+
import { drawTile3D } from "./MineTile3D";
|
|
12
|
+
|
|
13
|
+
const MAX_ZOOM = 18;
|
|
14
|
+
|
|
15
|
+
export class MineMap extends MapCombine {
|
|
16
|
+
viewer: any;
|
|
17
|
+
container: HTMLDivElement;
|
|
18
|
+
|
|
19
|
+
get cursor(): string {
|
|
20
|
+
return this.viewer.getCursor();
|
|
21
|
+
}
|
|
22
|
+
set cursor(val: string) {
|
|
23
|
+
this.viewer.setCursor(val);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
get moveable(): boolean {
|
|
27
|
+
return this.viewer.dragPan.isEnabled();
|
|
28
|
+
}
|
|
29
|
+
set moveable(val: boolean) {
|
|
30
|
+
val ? this.viewer.dragPan.enable() : this.viewer.dragPan.disable();
|
|
31
|
+
}
|
|
32
|
+
get center(): number[] {
|
|
33
|
+
const p = this.viewer.getCenter();
|
|
34
|
+
return [p.lng, p.lat];
|
|
35
|
+
}
|
|
36
|
+
set center(val: number[]) {
|
|
37
|
+
this.viewer.setCenter(val);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
get zoom(): number {
|
|
41
|
+
return this.viewer.getZoom();
|
|
42
|
+
}
|
|
43
|
+
set zoom(val: number) {
|
|
44
|
+
this.viewer.setZoom(val);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
constructor(viewer: any) {
|
|
48
|
+
super();
|
|
49
|
+
this.viewer = viewer;
|
|
50
|
+
this.container = viewer.getContainer();
|
|
51
|
+
this.container.children.item(1).appendChild(this.htmllayer);
|
|
52
|
+
this.cursor = "default";
|
|
53
|
+
bindEvent(this);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
canvasTgeography(p: number[]): number[] {
|
|
57
|
+
const res = this.viewer.getTDSpaceCoord({ point: p, disableLayer: true });
|
|
58
|
+
return [res.lngLat.lng, res.lngLat.lat, 0];
|
|
59
|
+
}
|
|
60
|
+
geographyTcanvas(p: number[]): number[] {
|
|
61
|
+
const res = this.viewer.project([p[0], p[1]], p[2] ?? 0);
|
|
62
|
+
return [res.x, res.y];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
createPoint<K>(option?: Partial<PointOption<K>>): Point<K> {
|
|
66
|
+
const e = new Point(this, option);
|
|
67
|
+
drawPoint(this, e);
|
|
68
|
+
return e;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
createPointAggregation(option?: PointAggregationOption): PointAggregation {
|
|
72
|
+
const e = new PointAggregation(this, option);
|
|
73
|
+
return e;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
createPolyline<K>(option?: Partial<PolylineOption<K>>): Polyline<K> {
|
|
77
|
+
const e = new Polyline(this, option);
|
|
78
|
+
drawPolyline(this, e);
|
|
79
|
+
return e;
|
|
80
|
+
}
|
|
81
|
+
createPolygon<K>(option?: Partial<PolygonOption<K>>): Polygon<K> {
|
|
82
|
+
const e = new Polygon(this, option);
|
|
83
|
+
drawPolygon(this, e);
|
|
84
|
+
return e;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* 所有点位移动至视口,调整位置及层级
|
|
89
|
+
* @param points
|
|
90
|
+
* @param opt
|
|
91
|
+
* @param {Array<number> = [0,0,0,0]} opt.avoid 距离边框的内边距,顺序:上、下、左、右
|
|
92
|
+
*/
|
|
93
|
+
flyToViewer(points, opt = { avoid: [0, 0, 0, 0], maxZoom: MAX_ZOOM }) {
|
|
94
|
+
if (points?.length === 0) {
|
|
95
|
+
return this.flyTo(points[0], opt);
|
|
96
|
+
}
|
|
97
|
+
const rectangle = this.getBounds(points, { canvas: this.viewer.getCanvas(), ...opt });
|
|
98
|
+
|
|
99
|
+
// 设置地图视图,使用调整后的边界范围
|
|
100
|
+
this.viewer.fitBounds(
|
|
101
|
+
[
|
|
102
|
+
[rectangle[0], rectangle[1]],
|
|
103
|
+
[rectangle[2], rectangle[3]],
|
|
104
|
+
],
|
|
105
|
+
{
|
|
106
|
+
maxZoom: opt?.maxZoom ?? MAX_ZOOM,
|
|
107
|
+
},
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* 移动点位到中心点
|
|
113
|
+
* @param point
|
|
114
|
+
*/
|
|
115
|
+
flyTo(point, opt = {}) {
|
|
116
|
+
// 设置相机视角
|
|
117
|
+
this.viewer.flyTo({ center: point, ...opt });
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
createTile3D(option?: Partial<Tile3DOption>): Tile3D {
|
|
121
|
+
const e = new Tile3D(this, option);
|
|
122
|
+
drawTile3D(this, e);
|
|
123
|
+
return e;
|
|
124
|
+
}
|
|
125
|
+
}
|
package/src/mine/MinePoint.ts
CHANGED
|
@@ -28,10 +28,16 @@ export function drawPoint(map: MineMap, point: Point<unknown>) {
|
|
|
28
28
|
};
|
|
29
29
|
|
|
30
30
|
const marker = new minemap.Marker({
|
|
31
|
+
id: point.name,
|
|
31
32
|
draggable: point.editable,
|
|
32
33
|
rotation: 0,
|
|
33
34
|
offset: [-size[0] * center[0], -size[1] * center[1]],
|
|
34
35
|
element: img,
|
|
36
|
+
extData: {
|
|
37
|
+
name: point.name,
|
|
38
|
+
target: point,
|
|
39
|
+
userdata: point.userdata,
|
|
40
|
+
},
|
|
35
41
|
});
|
|
36
42
|
|
|
37
43
|
if (point.coordinates) {
|
package/src/mine/MinePolygon.ts
CHANGED
package/src/mine/MinePolyline.ts
CHANGED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 解析十六进制颜色字符串,拆分为颜色值和透明度
|
|
3
|
+
* @param {string} hexColor - 十六进制颜色字符串,支持格式:#RGB, #RRGGBB, #RRGGBBAA, #RGBA
|
|
4
|
+
* @param {number} defaultOpacity - 默认透明度(0-1),当颜色没有透明度时使用
|
|
5
|
+
* @returns {Object} { color: string, opacity: number }
|
|
6
|
+
* @throws {Error} 如果颜色格式无效
|
|
7
|
+
*/
|
|
8
|
+
export function parseHexColor(hexColor, defaultOpacity = 1) {
|
|
9
|
+
// 移除开头的 # 号(如果有)
|
|
10
|
+
let hex = hexColor.replace(/^#/, "");
|
|
11
|
+
|
|
12
|
+
// 验证是否为有效的十六进制字符串
|
|
13
|
+
if (!/^[0-9a-fA-F]+$/.test(hex)) {
|
|
14
|
+
throw new Error(`无效的颜色格式: "${hexColor}"`);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
let color = "";
|
|
18
|
+
let opacity = defaultOpacity;
|
|
19
|
+
|
|
20
|
+
switch (hex.length) {
|
|
21
|
+
case 3: // #RGB
|
|
22
|
+
color = `#${hex[0]}${hex[0]}${hex[1]}${hex[1]}${hex[2]}${hex[2]}`;
|
|
23
|
+
opacity = defaultOpacity;
|
|
24
|
+
break;
|
|
25
|
+
|
|
26
|
+
case 4: // #RGBA
|
|
27
|
+
color = `#${hex[0]}${hex[0]}${hex[1]}${hex[1]}${hex[2]}${hex[2]}`;
|
|
28
|
+
opacity = parseInt(hex[3] + hex[3], 16) / 255;
|
|
29
|
+
break;
|
|
30
|
+
|
|
31
|
+
case 6: // #RRGGBB
|
|
32
|
+
color = `#${hex}`;
|
|
33
|
+
opacity = defaultOpacity;
|
|
34
|
+
break;
|
|
35
|
+
|
|
36
|
+
case 8: // #RRGGBBAA
|
|
37
|
+
color = `#${hex.slice(0, 6)}`;
|
|
38
|
+
opacity = parseInt(hex.slice(6, 8), 16) / 255;
|
|
39
|
+
break;
|
|
40
|
+
|
|
41
|
+
default:
|
|
42
|
+
throw new Error(`不支持的十六进制颜色长度: "${hexColor}",长度必须为 3、4、6 或 8`);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// 确保透明度在 0-1 范围内
|
|
46
|
+
opacity = Math.max(0, Math.min(1, opacity));
|
|
47
|
+
|
|
48
|
+
return { color, opacity };
|
|
49
|
+
}
|