@hzab/map-combine 0.4.0-alpha.0 → 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.
@@ -1,54 +1,54 @@
1
- import { AMap } from "./AMap";
2
-
3
- /**
4
- * 高德地图事件
5
- * 高德地图 元素事件由各自元素处理
6
- * @param map
7
- */
8
- export function bindEvent(map: AMap) {
9
- const { event, viewer, container } = map;
10
-
11
- const frame = () => {
12
- if (map.isAlive) {
13
- requestAnimationFrame(frame);
14
- event.trigger("view-preRender");
15
- }
16
- };
17
- frame();
18
-
19
- viewer.on("moveend", (e) => {
20
- event.trigger("view-moveEnd");
21
- event.trigger("view-change");
22
- });
23
-
24
- container.addEventListener("mousedown", (e) => {
25
- event.trigger("pointer-down");
26
- });
27
-
28
- container.addEventListener("mouseup", (e) => {
29
- event.trigger("pointer-up");
30
- });
31
-
32
- // 解决 ReactPoint 点击事件无法触发的问题
33
- container.addEventListener("click", (e) => {
34
- event.trigger("left-click");
35
- });
36
-
37
- viewer.on("mousemove", (e) => {
38
- event.trigger("pointer-move");
39
- event.canvas = [e.pixel.x, e.pixel.y];
40
- event.geography = [e.lnglat.lng, e.lnglat.lat];
41
- });
42
-
43
- viewer.on("mapmove", () => {
44
- event.trigger("view-change");
45
- });
46
-
47
- viewer.on("click", (e) => {
48
- event.trigger("left-click");
49
- });
50
-
51
- viewer.on("dblclick", (e) => {
52
- map.event.trigger("double-click");
53
- });
54
- }
1
+ import { AMap } from "./AMap";
2
+
3
+ /**
4
+ * 高德地图事件
5
+ * 高德地图 元素事件由各自元素处理
6
+ * @param map
7
+ */
8
+ export function bindEvent(map: AMap) {
9
+ const { event, viewer, container } = map;
10
+
11
+ const frame = () => {
12
+ if (map.isAlive) {
13
+ requestAnimationFrame(frame);
14
+ event.trigger("view-preRender");
15
+ }
16
+ };
17
+ frame();
18
+
19
+ viewer.on("moveend", (e) => {
20
+ event.trigger("view-moveEnd");
21
+ event.trigger("view-change");
22
+ });
23
+
24
+ container.addEventListener("mousedown", (e) => {
25
+ event.trigger("pointer-down");
26
+ });
27
+
28
+ container.addEventListener("mouseup", (e) => {
29
+ event.trigger("pointer-up");
30
+ });
31
+
32
+ // 解决 ReactPoint 点击事件无法触发的问题
33
+ container.addEventListener("click", (e) => {
34
+ event.trigger("left-click");
35
+ });
36
+
37
+ viewer.on("mousemove", (e) => {
38
+ event.trigger("pointer-move");
39
+ event.canvas = [e.pixel.x, e.pixel.y];
40
+ event.geography = [e.lnglat.lng, e.lnglat.lat];
41
+ });
42
+
43
+ viewer.on("mapmove", () => {
44
+ event.trigger("view-change");
45
+ });
46
+
47
+ viewer.on("click", (e) => {
48
+ event.trigger("left-click");
49
+ });
50
+
51
+ viewer.on("dblclick", (e) => {
52
+ map.event.trigger("double-click");
53
+ });
54
+ }
@@ -1,98 +1,98 @@
1
- import { ContextMenu } from "./ContextMenu";
2
- import { MapElement } from "./MapElement";
3
- import { MapEvent } from "./MapEvent";
4
- import { Point, PointOption } from "./Point";
5
- import { PointAggregation, PointAggregationOption } from "./PointAggregation";
6
- import { Polygon, PolygonOption } from "./Polygon";
7
- import { Polyline, PolylineOption } from "./Polyline";
8
- import { ReactPoint, ReactPointOption, drawReactPoint } from "./ReactPoint";
9
- import { Tile3D, Tile3DOption } from "./Tile3D";
10
- import { type BasicBusiness, type BasicBusinessOption } from "./BasicBusiness";
11
-
12
- import { getBounds } from "../utils/points-viewer";
13
-
14
- export abstract class MapCombine {
15
- /* 用于挂载html元素的根节点 */
16
- readonly htmllayer = document.createElement("div");
17
- readonly elements = new Map<string, MapElement>();
18
- readonly event = new MapEvent();
19
- readonly menu: ContextMenu;
20
- abstract get cursor(): string;
21
- abstract set cursor(val: string);
22
-
23
- abstract get moveable(): boolean;
24
- abstract set moveable(val: boolean);
25
-
26
- abstract get center(): number[];
27
- abstract set center(val);
28
-
29
- abstract get zoom(): number;
30
- abstract set zoom(val);
31
-
32
- loadPromise: Promise<this> = Promise.resolve(this);
33
-
34
- bussinesses = new Map<string, BasicBusiness<BasicBusinessOption>>();
35
-
36
- /** 地图是否存在 */
37
- isAlive = true;
38
- constructor() {
39
- const { htmllayer } = this;
40
- htmllayer.style.zIndex = "1000";
41
- htmllayer.style.position = "absolute";
42
- htmllayer.style.width = "0";
43
- htmllayer.style.height = "0";
44
- htmllayer.style.left = "0";
45
- htmllayer.style.top = "0";
46
- this.menu = new ContextMenu(this);
47
- (window as any).map = this;
48
- setTimeout(() => {
49
- this.bussinesses.forEach((e) => e.show && e.onMapLoaded?.());
50
- }, 100);
51
- }
52
-
53
- createReactPoint<K>(option?: Partial<ReactPointOption<K>>): ReactPoint<K> {
54
- const e = new ReactPoint(this, option);
55
- drawReactPoint(this, e);
56
- return e;
57
- }
58
-
59
- /**
60
- * 设置地图视图
61
- * @param option 视图参数
62
- * @param time 设置时间会动画形式调整视图
63
- */
64
- abstract createPoint<K>(option?: Partial<PointOption<K>>): Point<K>;
65
-
66
- /** 聚合点 */
67
- abstract createPointAggregation(option?: PointAggregationOption): PointAggregation;
68
-
69
- abstract createPolyline<K>(option?: Partial<PolylineOption<K>>): Polyline<K>;
70
-
71
- abstract createPolygon<K>(option?: Partial<PolygonOption<K>>): Polygon<K>;
72
-
73
- abstract createTile3D(option?: Partial<Tile3DOption>): Tile3D;
74
-
75
- abstract canvasTgeography(p: number[]): number[];
76
-
77
- abstract geographyTcanvas(p: number[]): number[];
78
-
79
- /**
80
- * 所有点位移动至视口,调整位置及层级
81
- * @param points
82
- */
83
- abstract flyToViewer(points: number[][], opt?: Object): void;
84
-
85
- /**
86
- * 移动点位到中心点
87
- * @param points
88
- */
89
- abstract flyTo(point: number[], opt?: Object): void;
90
-
91
- getBounds = getBounds;
92
-
93
- destroy() {
94
- this.isAlive = false;
95
- this.htmllayer.remove();
96
- this.event.trigger("destroy");
97
- }
98
- }
1
+ import { ContextMenu } from "./ContextMenu";
2
+ import { MapElement } from "./MapElement";
3
+ import { MapEvent } from "./MapEvent";
4
+ import { Point, PointOption } from "./Point";
5
+ import { PointAggregation, PointAggregationOption } from "./PointAggregation";
6
+ import { Polygon, PolygonOption } from "./Polygon";
7
+ import { Polyline, PolylineOption } from "./Polyline";
8
+ import { ReactPoint, ReactPointOption, drawReactPoint } from "./ReactPoint";
9
+ import { Tile3D, Tile3DOption } from "./Tile3D";
10
+ import { type BasicBusiness, type BasicBusinessOption } from "./BasicBusiness";
11
+
12
+ import { getBounds } from "../utils/points-viewer";
13
+
14
+ export abstract class MapCombine {
15
+ /* 用于挂载html元素的根节点 */
16
+ readonly htmllayer = document.createElement("div");
17
+ readonly elements = new Map<string, MapElement>();
18
+ readonly event = new MapEvent();
19
+ readonly menu: ContextMenu;
20
+ abstract get cursor(): string;
21
+ abstract set cursor(val: string);
22
+
23
+ abstract get moveable(): boolean;
24
+ abstract set moveable(val: boolean);
25
+
26
+ abstract get center(): number[];
27
+ abstract set center(val);
28
+
29
+ abstract get zoom(): number;
30
+ abstract set zoom(val);
31
+
32
+ loadPromise: Promise<this> = Promise.resolve(this);
33
+
34
+ bussinesses = new Map<string, BasicBusiness<BasicBusinessOption>>();
35
+
36
+ /** 地图是否存在 */
37
+ isAlive = true;
38
+ constructor() {
39
+ const { htmllayer } = this;
40
+ htmllayer.style.zIndex = "1000";
41
+ htmllayer.style.position = "absolute";
42
+ htmllayer.style.width = "0";
43
+ htmllayer.style.height = "0";
44
+ htmllayer.style.left = "0";
45
+ htmllayer.style.top = "0";
46
+ this.menu = new ContextMenu(this);
47
+ (window as any).map = this;
48
+ setTimeout(() => {
49
+ this.bussinesses.forEach((e) => e.show && e.onMapLoaded?.());
50
+ }, 100);
51
+ }
52
+
53
+ createReactPoint<K>(option?: Partial<ReactPointOption<K>>): ReactPoint<K> {
54
+ const e = new ReactPoint(this, option);
55
+ drawReactPoint(this, e);
56
+ return e;
57
+ }
58
+
59
+ /**
60
+ * 设置地图视图
61
+ * @param option 视图参数
62
+ * @param time 设置时间会动画形式调整视图
63
+ */
64
+ abstract createPoint<K>(option?: Partial<PointOption<K>>): Point<K>;
65
+
66
+ /** 聚合点 */
67
+ abstract createPointAggregation(option?: PointAggregationOption): PointAggregation;
68
+
69
+ abstract createPolyline<K>(option?: Partial<PolylineOption<K>>): Polyline<K>;
70
+
71
+ abstract createPolygon<K>(option?: Partial<PolygonOption<K>>): Polygon<K>;
72
+
73
+ abstract createTile3D(option?: Partial<Tile3DOption>): Tile3D;
74
+
75
+ abstract canvasTgeography(p: number[]): number[];
76
+
77
+ abstract geographyTcanvas(p: number[]): number[];
78
+
79
+ /**
80
+ * 所有点位移动至视口,调整位置及层级
81
+ * @param points
82
+ */
83
+ abstract flyToViewer(points: number[][], opt?: Object): void;
84
+
85
+ /**
86
+ * 移动点位到中心点
87
+ * @param points
88
+ */
89
+ abstract flyTo(point: number[], opt?: Object): void;
90
+
91
+ getBounds = getBounds;
92
+
93
+ destroy() {
94
+ this.isAlive = false;
95
+ this.htmllayer.remove();
96
+ this.event.trigger("destroy");
97
+ }
98
+ }
@@ -67,6 +67,7 @@ export class PointAggregation {
67
67
  private _current = 0;
68
68
  private _map: MapCombine;
69
69
  private _option: PointAggregationOption;
70
+ private _onAfterViewChange;
70
71
 
71
72
  /** 唯一标识 */
72
73
  get name() {
@@ -89,10 +90,10 @@ export class PointAggregation {
89
90
  this._map = map;
90
91
  this._option = option;
91
92
  const { event } = map;
93
+ // _onAfterViewChange 解决元素销毁 事件取消监听异常问题
94
+ this._onAfterViewChange = this.onAfterViewChange.bind(this);
92
95
  this.onAfterViewChange();
93
- event.on("view-moveEnd", () => {
94
- this.onAfterViewChange();
95
- });
96
+ event.on("view-moveEnd", this._onAfterViewChange);
96
97
  }
97
98
 
98
99
  private _turnon(zoom: number) {
@@ -182,7 +183,7 @@ export class PointAggregation {
182
183
  /** 销毁组件 */
183
184
  destroy() {
184
185
  const { event } = this._map;
185
- event.on("view-moveEnd", null);
186
+ event.off("view-moveEnd", this._onAfterViewChange);
186
187
  this._map.elements.delete(this.name);
187
188
  this._cache.forEach((e) => {
188
189
  e.forEach((f) => {