diff --git a/packages/core/src/services/interaction/IInteractionService.ts b/packages/core/src/services/interaction/IInteractionService.ts index 98173b740c..b7d4a2df77 100644 --- a/packages/core/src/services/interaction/IInteractionService.ts +++ b/packages/core/src/services/interaction/IInteractionService.ts @@ -12,6 +12,7 @@ export interface IInteractionTarget { lngLat: ILngLat; type: string; featureId?: number; + target: MouseEvent | TouchEvent; } export interface IInteractionService { diff --git a/packages/core/src/services/interaction/InteractionService.ts b/packages/core/src/services/interaction/InteractionService.ts index af0bd2c2ed..6bb0ff6d04 100644 --- a/packages/core/src/services/interaction/InteractionService.ts +++ b/packages/core/src/services/interaction/InteractionService.ts @@ -148,7 +148,7 @@ export default class InteractionService extends EventEmitter clientY -= top; } const lngLat = this.mapService.containerToLngLat([clientX, clientY]); - return { x: clientX, y: clientY, lngLat, type }; + return { x: clientX, y: clientY, lngLat, type, target: target.srcEvent }; } private onHover = (event: MouseEvent) => { const { clientX, clientY } = event; @@ -180,6 +180,7 @@ export default class InteractionService extends EventEmitter y, lngLat, type, + target: event, }); } }; diff --git a/packages/core/src/services/interaction/PickingService.ts b/packages/core/src/services/interaction/PickingService.ts index 21004e0c18..6fb1fdf92a 100644 --- a/packages/core/src/services/interaction/PickingService.ts +++ b/packages/core/src/services/interaction/PickingService.ts @@ -125,7 +125,7 @@ export default class PickingService implements IPickingService { } private pickFromPickingFBO = ( layer: ILayer, - { x, y, lngLat, type }: IInteractionTarget, + { x, y, lngLat, type, target }: IInteractionTarget, ) => { let isPicked = false; const { getViewportSize, readPixels, getContainer } = this.rendererService; @@ -173,13 +173,14 @@ export default class PickingService implements IPickingService { type = 'mouseenter'; } - const target = { + const layerTarget = { x, y, type, lngLat, featureId: pickedFeatureIdx, feature: rawFeature, + target, }; if (!rawFeature) { // this.logger.error( @@ -189,11 +190,11 @@ export default class PickingService implements IPickingService { // trigger onHover/Click callback on layer isPicked = true; layer.setCurrentPickId(pickedFeatureIdx); - this.triggerHoverOnLayer(layer, target); // 触发拾取事件 + this.triggerHoverOnLayer(layer, layerTarget); // 触发拾取事件 } } else { // 未选中 - const target = { + const layerTarget = { x, y, lngLat, @@ -202,13 +203,14 @@ export default class PickingService implements IPickingService { ? 'mouseout' : 'un' + type, featureId: null, + target, feature: null, }; this.triggerHoverOnLayer(layer, { - ...target, + ...layerTarget, type: 'unpick', }); - this.triggerHoverOnLayer(layer, target); + this.triggerHoverOnLayer(layer, layerTarget); layer.setCurrentPickId(null); } diff --git a/stories/Layers/components/polygon.tsx b/stories/Layers/components/polygon.tsx index b098683fa9..f0d6a84bcf 100644 --- a/stories/Layers/components/polygon.tsx +++ b/stories/Layers/components/polygon.tsx @@ -141,9 +141,6 @@ export default class TextLayerDemo extends React.Component { }); scene.addLayer(layer); this.scene = scene; - layer.on('remapping', () => { - console.log('remapinbg event'); - }); const gui = new dat.GUI(); this.gui = gui; const styleOptions = {