@hzab/map-combine 0.3.1-alpha.1 → 0.4.1
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 +11 -1
- package/package.json +1 -4
- package/src/amap/AMap.ts +306 -300
- package/src/amap/AMapEvent.ts +54 -49
- package/src/amap/AMapPolygon.ts +195 -195
- package/src/amap/AMapPolyline.ts +185 -185
- package/src/basic/MapCombine.ts +98 -94
- package/src/basic/PointAggregation.tsx +16 -11
- package/src/basic/ReactPoint.tsx +363 -363
- package/src/cesium/CesiumEvent.ts +84 -84
- package/src/cesium/CesiumMap.ts +6 -0
- package/src/cesium/CesiumTile3D.ts +225 -225
- package/src/mine/MineEvent.ts +46 -42
- package/src/mine/MineMap.ts +6 -0
- package/src/openlayer/OpenlayerEvent.ts +87 -83
- package/src/openlayer/OpenlayerMap.ts +14 -0
package/src/mine/MineEvent.ts
CHANGED
|
@@ -1,42 +1,46 @@
|
|
|
1
|
-
import { MineMap } from "./MineMap";
|
|
2
|
-
|
|
3
|
-
export function bindEvent(map: MineMap) {
|
|
4
|
-
const { event, viewer, container } = map;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
event.trigger("
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
container.addEventListener("
|
|
11
|
-
event.trigger("pointer-
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
event.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
event.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
});
|
|
42
|
-
|
|
1
|
+
import { MineMap } from "./MineMap";
|
|
2
|
+
|
|
3
|
+
export function bindEvent(map: MineMap) {
|
|
4
|
+
const { event, viewer, container } = map;
|
|
5
|
+
|
|
6
|
+
viewer.on("moveend", (e) => {
|
|
7
|
+
event.trigger("view-moveEnd");
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
container.addEventListener("mousedown", (e) => {
|
|
11
|
+
event.trigger("pointer-down");
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
container.addEventListener("mouseup", (e) => {
|
|
15
|
+
event.trigger("pointer-up");
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
// 解决 ReactPoint 点击事件无法触发的问题
|
|
19
|
+
container.addEventListener("click", (e) => {
|
|
20
|
+
event.trigger("left-click");
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
viewer.on("mousemove", (e) => {
|
|
24
|
+
event.canvas = [e.point.x, e.point.y];
|
|
25
|
+
event.geography = [e.lngLat.lng, e.lngLat.lat, 0];
|
|
26
|
+
});
|
|
27
|
+
container.addEventListener("pointermove", (e) => {
|
|
28
|
+
event.trigger("pointer-move");
|
|
29
|
+
});
|
|
30
|
+
viewer.on("move", () => {
|
|
31
|
+
event.trigger("view-change");
|
|
32
|
+
});
|
|
33
|
+
viewer.on("mouseup", () => {
|
|
34
|
+
event.trigger("pointer-up");
|
|
35
|
+
});
|
|
36
|
+
viewer.on("mousedown", () => {
|
|
37
|
+
event.trigger("pointer-down");
|
|
38
|
+
});
|
|
39
|
+
viewer.on("click", () => {
|
|
40
|
+
event.trigger("left-click");
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
event.on("destroy", () => {
|
|
44
|
+
viewer.remove();
|
|
45
|
+
});
|
|
46
|
+
}
|
package/src/mine/MineMap.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { MapCombine } from "../basic/MapCombine";
|
|
2
2
|
import { PointOption, Point } from "../basic/Point";
|
|
3
|
+
import { PointAggregationOption, PointAggregation } from "../basic/PointAggregation";
|
|
3
4
|
import { PolygonOption, Polygon } from "../basic/Polygon";
|
|
4
5
|
import { PolylineOption, Polyline } from "../basic/Polyline";
|
|
5
6
|
import { Tile3DOption, Tile3D } from "../basic/Tile3D";
|
|
@@ -67,6 +68,11 @@ export class MineMap extends MapCombine {
|
|
|
67
68
|
return e;
|
|
68
69
|
}
|
|
69
70
|
|
|
71
|
+
createPointAggregation(option?: PointAggregationOption): PointAggregation {
|
|
72
|
+
const e = new PointAggregation(this, option);
|
|
73
|
+
return e;
|
|
74
|
+
}
|
|
75
|
+
|
|
70
76
|
createPolyline<K>(option?: Partial<PolylineOption<K>>): Polyline<K> {
|
|
71
77
|
const e = new Polyline(this, option);
|
|
72
78
|
drawPolyline(this, e);
|
|
@@ -1,83 +1,87 @@
|
|
|
1
|
-
import { OpenlayerMap } from "./OpenlayerMap";
|
|
2
|
-
|
|
3
|
-
export function bindEvent(map: OpenlayerMap) {
|
|
4
|
-
const { event, viewer, container } = map;
|
|
5
|
-
let target: any;
|
|
6
|
-
let moving = false;
|
|
7
|
-
|
|
8
|
-
const frame = () => {
|
|
9
|
-
if (map.isAlive) {
|
|
10
|
-
requestAnimationFrame(frame);
|
|
11
|
-
event.trigger("view-preRender");
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
frame();
|
|
15
|
-
|
|
16
|
-
viewer.on("
|
|
17
|
-
event.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
_target
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
-
|
|
1
|
+
import { OpenlayerMap } from "./OpenlayerMap";
|
|
2
|
+
|
|
3
|
+
export function bindEvent(map: OpenlayerMap) {
|
|
4
|
+
const { event, viewer, container } = map;
|
|
5
|
+
let target: any;
|
|
6
|
+
let moving = false;
|
|
7
|
+
|
|
8
|
+
const frame = () => {
|
|
9
|
+
if (map.isAlive) {
|
|
10
|
+
requestAnimationFrame(frame);
|
|
11
|
+
event.trigger("view-preRender");
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
frame();
|
|
15
|
+
|
|
16
|
+
viewer.on("moveend", (e) => {
|
|
17
|
+
event.trigger("view-moveEnd");
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
viewer.on("pointermove", (e) => {
|
|
21
|
+
event.canvas = e.pixel;
|
|
22
|
+
event.geography = map.canvasTgeography(event.canvas);
|
|
23
|
+
let _target: any;
|
|
24
|
+
if (moving) {
|
|
25
|
+
event.trigger("pointer-move");
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const res = viewer.getFeaturesAtPixel(event.canvas)[0];
|
|
29
|
+
_target = res ? res.get("event") : undefined;
|
|
30
|
+
if (_target?.silent) {
|
|
31
|
+
_target = undefined;
|
|
32
|
+
}
|
|
33
|
+
if (_target !== target) {
|
|
34
|
+
target?.onPointerOut?.();
|
|
35
|
+
_target?.onPointerIn?.();
|
|
36
|
+
target = _target;
|
|
37
|
+
}
|
|
38
|
+
event.trigger("pointer-move");
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
container.addEventListener("mousedown", () => {
|
|
42
|
+
if (target) {
|
|
43
|
+
moving = true;
|
|
44
|
+
target.onPointerDown?.();
|
|
45
|
+
}
|
|
46
|
+
event.trigger("pointer-down");
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
container.addEventListener("mouseup", () => {
|
|
50
|
+
if (target) {
|
|
51
|
+
moving = false;
|
|
52
|
+
target.onPointerUp?.();
|
|
53
|
+
}
|
|
54
|
+
event.trigger("pointer-up");
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
container.addEventListener("contextmenu", (e) => {
|
|
58
|
+
e.preventDefault();
|
|
59
|
+
if (target) {
|
|
60
|
+
target.onRClick?.();
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
viewer.on("click", () => {
|
|
65
|
+
if (target) {
|
|
66
|
+
target.onLClick?.();
|
|
67
|
+
}
|
|
68
|
+
event.trigger("left-click");
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
viewer.on("dblclick", () => {
|
|
72
|
+
if (target) {
|
|
73
|
+
target.onDbClick?.();
|
|
74
|
+
}
|
|
75
|
+
map.event.trigger("double-click");
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
let key = 0;
|
|
79
|
+
|
|
80
|
+
viewer.on("precompose", () => {
|
|
81
|
+
const _key = map.center.reduce((a, b) => a + b, map.zoom);
|
|
82
|
+
if (key != _key) {
|
|
83
|
+
key = _key;
|
|
84
|
+
event.trigger("view-change");
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
@@ -15,6 +15,7 @@ import * as olExtent from "ol/extent";
|
|
|
15
15
|
|
|
16
16
|
import { MapCombine } from "../basic/MapCombine";
|
|
17
17
|
import { PointOption, Point } from "../basic/Point";
|
|
18
|
+
import { PointAggregationOption, PointAggregation } from "../basic/PointAggregation";
|
|
18
19
|
import { Projection } from "../utils/Projection";
|
|
19
20
|
import { bindEvent } from "./OpenlayerEvent";
|
|
20
21
|
import { PolylineOption, Polyline } from "../basic/Polyline";
|
|
@@ -156,6 +157,11 @@ export class OpenlayerMap extends MapCombine {
|
|
|
156
157
|
return e;
|
|
157
158
|
}
|
|
158
159
|
|
|
160
|
+
createPointAggregation(option?: PointAggregationOption): PointAggregation {
|
|
161
|
+
const e = new PointAggregation(this, option);
|
|
162
|
+
return e;
|
|
163
|
+
}
|
|
164
|
+
|
|
159
165
|
createPolyline<K>(option?: Partial<PolylineOption<K>>): Polyline<K> {
|
|
160
166
|
const e = new Polyline(this, option);
|
|
161
167
|
drawPolyline(this, e);
|
|
@@ -255,6 +261,10 @@ export class OpenlayerMap extends MapCombine {
|
|
|
255
261
|
}
|
|
256
262
|
canvasTspace(p: number[]): number[] {
|
|
257
263
|
const coordinates = this.viewer.getCoordinateFromPixel(p);
|
|
264
|
+
// 解决 coordinates 为 null 异常情况
|
|
265
|
+
if (!coordinates) {
|
|
266
|
+
return [];
|
|
267
|
+
}
|
|
258
268
|
return [coordinates[0] - this.offset[0], coordinates[1] - this.offset[1], 0];
|
|
259
269
|
}
|
|
260
270
|
|
|
@@ -264,6 +274,10 @@ export class OpenlayerMap extends MapCombine {
|
|
|
264
274
|
|
|
265
275
|
canvasTgeography(p: number[]): number[] {
|
|
266
276
|
const coordinates = this.viewer.getCoordinateFromPixel(p);
|
|
277
|
+
// 解决 coordinates 为 null 异常情况
|
|
278
|
+
if (!coordinates) {
|
|
279
|
+
return [];
|
|
280
|
+
}
|
|
267
281
|
return [Projection.xToLon(coordinates[0]), Projection.yToLat(coordinates[1]), 0];
|
|
268
282
|
}
|
|
269
283
|
|