Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: map 事件属性丢失 #2436

Merged
merged 3 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading