mirror of https://gitee.com/antv-l7/antv-l7
Merge pull request #539 from antvis/feat_event_compose
feat(core): interaction
This commit is contained in:
commit
6b1f5eecf3
|
@ -12,6 +12,7 @@ export interface IInteractionTarget {
|
||||||
lngLat: ILngLat;
|
lngLat: ILngLat;
|
||||||
type: string;
|
type: string;
|
||||||
featureId?: number;
|
featureId?: number;
|
||||||
|
target: MouseEvent | TouchEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IInteractionService {
|
export interface IInteractionService {
|
||||||
|
|
|
@ -148,7 +148,7 @@ export default class InteractionService extends EventEmitter
|
||||||
clientY -= top;
|
clientY -= top;
|
||||||
}
|
}
|
||||||
const lngLat = this.mapService.containerToLngLat([clientX, clientY]);
|
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) => {
|
private onHover = (event: MouseEvent) => {
|
||||||
const { clientX, clientY } = event;
|
const { clientX, clientY } = event;
|
||||||
|
@ -180,6 +180,7 @@ export default class InteractionService extends EventEmitter
|
||||||
y,
|
y,
|
||||||
lngLat,
|
lngLat,
|
||||||
type,
|
type,
|
||||||
|
target: event,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -125,7 +125,7 @@ export default class PickingService implements IPickingService {
|
||||||
}
|
}
|
||||||
private pickFromPickingFBO = (
|
private pickFromPickingFBO = (
|
||||||
layer: ILayer,
|
layer: ILayer,
|
||||||
{ x, y, lngLat, type }: IInteractionTarget,
|
{ x, y, lngLat, type, target }: IInteractionTarget,
|
||||||
) => {
|
) => {
|
||||||
let isPicked = false;
|
let isPicked = false;
|
||||||
const { getViewportSize, readPixels, getContainer } = this.rendererService;
|
const { getViewportSize, readPixels, getContainer } = this.rendererService;
|
||||||
|
@ -173,13 +173,14 @@ export default class PickingService implements IPickingService {
|
||||||
type = 'mouseenter';
|
type = 'mouseenter';
|
||||||
}
|
}
|
||||||
|
|
||||||
const target = {
|
const layerTarget = {
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
type,
|
type,
|
||||||
lngLat,
|
lngLat,
|
||||||
featureId: pickedFeatureIdx,
|
featureId: pickedFeatureIdx,
|
||||||
feature: rawFeature,
|
feature: rawFeature,
|
||||||
|
target,
|
||||||
};
|
};
|
||||||
if (!rawFeature) {
|
if (!rawFeature) {
|
||||||
// this.logger.error(
|
// this.logger.error(
|
||||||
|
@ -189,11 +190,11 @@ export default class PickingService implements IPickingService {
|
||||||
// trigger onHover/Click callback on layer
|
// trigger onHover/Click callback on layer
|
||||||
isPicked = true;
|
isPicked = true;
|
||||||
layer.setCurrentPickId(pickedFeatureIdx);
|
layer.setCurrentPickId(pickedFeatureIdx);
|
||||||
this.triggerHoverOnLayer(layer, target); // 触发拾取事件
|
this.triggerHoverOnLayer(layer, layerTarget); // 触发拾取事件
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 未选中
|
// 未选中
|
||||||
const target = {
|
const layerTarget = {
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
lngLat,
|
lngLat,
|
||||||
|
@ -202,13 +203,14 @@ export default class PickingService implements IPickingService {
|
||||||
? 'mouseout'
|
? 'mouseout'
|
||||||
: 'un' + type,
|
: 'un' + type,
|
||||||
featureId: null,
|
featureId: null,
|
||||||
|
target,
|
||||||
feature: null,
|
feature: null,
|
||||||
};
|
};
|
||||||
this.triggerHoverOnLayer(layer, {
|
this.triggerHoverOnLayer(layer, {
|
||||||
...target,
|
...layerTarget,
|
||||||
type: 'unpick',
|
type: 'unpick',
|
||||||
});
|
});
|
||||||
this.triggerHoverOnLayer(layer, target);
|
this.triggerHoverOnLayer(layer, layerTarget);
|
||||||
layer.setCurrentPickId(null);
|
layer.setCurrentPickId(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -141,9 +141,6 @@ export default class TextLayerDemo extends React.Component {
|
||||||
});
|
});
|
||||||
scene.addLayer(layer);
|
scene.addLayer(layer);
|
||||||
this.scene = scene;
|
this.scene = scene;
|
||||||
layer.on('remapping', () => {
|
|
||||||
console.log('remapinbg event');
|
|
||||||
});
|
|
||||||
const gui = new dat.GUI();
|
const gui = new dat.GUI();
|
||||||
this.gui = gui;
|
this.gui = gui;
|
||||||
const styleOptions = {
|
const styleOptions = {
|
||||||
|
|
Loading…
Reference in New Issue