Skip to content

Commit

Permalink
fix: map 事件属性丢失 (#2436)
Browse files Browse the repository at this point in the history
* fix: map 事件属性丢失

* fix: mis property

* chore: add changeset
  • Loading branch information
lvisei authored Apr 29, 2024
1 parent 5b44f5a commit a57bb39
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/flat-stingrays-sell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@antv/l7-map': patch
---

fix: map 事件属性丢失
4 changes: 2 additions & 2 deletions packages/map/src/handler/events/event.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// tslint:disable-next-line:no-submodule-imports
import { lodashUtil } from '@antv/l7-utils';
const { merge } = lodashUtil;

export class Event {
public type: string;
constructor(type: string, data: any = {}) {
constructor(type: string, data = {}) {
merge(this, data);
this.type = type;
}
Expand Down
11 changes: 7 additions & 4 deletions packages/map/src/handler/events/map_mouse_event.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// @ts-ignore
// tslint:disable-next-line:no-submodule-imports
import { lodashUtil } from '@antv/l7-utils';
import type { EarthMap } from '../../earthmap';
import type LngLat from '../../geo/lng_lat';
import type Point from '../../geo/point';
import type { Map } from '../../map';
import DOM from '../../utils/dom';
import { Event } from './event';
const { merge } = lodashUtil;

export default class MapMouseEvent extends Event {
/**
* `true` if `preventDefault` has been called.
Expand Down Expand Up @@ -51,10 +50,14 @@ export default class MapMouseEvent extends Event {
/**
* @private
*/
constructor(type: string, map: Map | EarthMap, originalEvent: MouseEvent, data: any = {}) {
constructor(type: string, map: Map | EarthMap, originalEvent: MouseEvent) {
super(type);
const point = DOM.mousePos(map.getCanvasContainer(), originalEvent);
const lngLat = map.unproject(point);
super(type, merge({ point, lngLat, originalEvent }, data));

this.point = point;
this.lngLat = lngLat;
this.originalEvent = originalEvent;
this.defaultPrevented = false;
this.target = map;
}
Expand Down
9 changes: 8 additions & 1 deletion packages/map/src/handler/events/map_touch_event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Point from '../../geo/point';
import type { Map } from '../../map';
import DOM from '../../utils/dom';
import { Event } from './event';

export default class MapTouchEvent extends Event {
/**
* The event type.
Expand Down Expand Up @@ -55,6 +56,7 @@ export default class MapTouchEvent extends Event {
* @private
*/
constructor(type: string, map: Map | EarthMap, originalEvent: TouchEvent) {
super(type);
const touches = type === 'touchend' ? originalEvent.changedTouches : originalEvent.touches;
const points = DOM.touchPos(map.getCanvasContainer(), touches);
const lngLats = points.map((t: Point) => map.unproject(t));
Expand All @@ -65,7 +67,12 @@ export default class MapTouchEvent extends Event {
new Point(0, 0),
);
const lngLat = map.unproject(point);
super(type, { points, point, lngLats, lngLat, originalEvent });

this.points = points;
this.point = point;
this.lngLats = lngLats;
this.lngLat = lngLat;
this.originalEvent = originalEvent;
this.defaultPrevented = false;
}

Expand Down
3 changes: 2 additions & 1 deletion packages/map/src/handler/events/map_wheel_event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export default class MapWheelEvent extends Event {
* @private
*/
constructor(type: string, map: Map | EarthMap, originalEvent: WheelEvent) {
super(type, { originalEvent });
super(type);
this.originalEvent = originalEvent;
this.defaultPrevented = false;
}

Expand Down
5 changes: 5 additions & 0 deletions packages/map/src/handler/events/render_event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@ import { Event } from './event';
export default class RenderFrameEvent extends Event {
public type: string = 'renderFrame';
public timeStamp: number;

constructor(type: string, timeStamp: number) {
super(type);
this.timeStamp = timeStamp;
}
}
2 changes: 1 addition & 1 deletion packages/map/src/handler/handler_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ class HandlerManager {
this.frameId = this.map.requestRenderFrame((timeStamp: number) => {
// @ts-ignore
delete this.frameId;
this.handleEvent(new RenderFrameEvent('renderFrame', { timeStamp }));
this.handleEvent(new RenderFrameEvent('renderFrame', timeStamp));
this.applyChanges();
});
}
Expand Down

0 comments on commit a57bb39

Please sign in to comment.