Skip to content

Commit

Permalink
Add pointerEventsFilter prop
Browse files Browse the repository at this point in the history
  • Loading branch information
vasturiano committed Jul 27, 2020
1 parent fbe6693 commit 7f7e015
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ Globe({ configOptions })(<domElement>)
| <b>pauseAnimation</b>() | Pauses the rendering cycle of the component, effectively freezing the current view and cancelling all user interaction. This method can be used to save performance in circumstances when a static image is sufficient. | |
| <b>resumeAnimation</b>() | Resumes the rendering cycle of the component, and re-enables the user interaction. This method can be used together with `pauseAnimation` for performance optimization purposes. | |
| <b>enablePointerInteraction</b>([<i>boolean</i>]) | Getter/setter for whether to enable the mouse tracking events. This activates an internal tracker of the canvas mouse position and enables the functionality of object hover/click and tooltip labels, at the cost of performance. If you're looking for maximum gain in your globe performance it's recommended to switch off this property. | `true` |
| <b>pointerEventsFilter</b>([<i>fn</i>]) | Getter/setter for the filter function which defines whether a particular object can be the target of pointer interactions. In general, objects that are closer to the camera get precedence in capturing pointer events. This function allows having ignored object layers so that pointer events can be passed through to deeper objects in the various globe layers. The ThreeJS object and its associated data (if any) are passed as arguments: `pointerEventsFilter(obj, data)`. The function should return a boolean value. | `() => true` |
| <b>onZoom</b>(<i>fn</i>) | Callback function for point-of-view changes by zooming or rotating the globe using the orbit controls. The current point of view (with the syntax `{ lat, lng, altitude }`) is included as sole argument. | |
| <b>scene</b>() | Access the internal ThreeJS [Scene](https://threejs.org/docs/#api/scenes/Scene). Can be used to extend the current scene with additional objects not related to globe.gl. | |
| <b>camera</b>() | Access the internal ThreeJS [Camera](https://threejs.org/docs/#api/cameras/PerspectiveCamera). | |
Expand Down
5 changes: 5 additions & 0 deletions src/globe.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ export default Kapsule({
onCustomLayerClick: { default: () => {}, triggerUpdate: false },
onCustomLayerRightClick: { default: () => {}, triggerUpdate: false },
onCustomLayerHover: { default: () => {}, triggerUpdate: false },
pointerEventsFilter: {
default: () => true,
triggerUpdate: false,
onChange: (filterFn, state) => state.renderObjs.hoverFilter(obj => filterFn(obj, obj.__data))
},
...linkedGlobeProps,
...linkedRenderObjsProps
},
Expand Down
6 changes: 5 additions & 1 deletion src/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Scene, Camera, WebGLRenderer, WebGLRendererParameters } from 'three';
import { Object3D, Scene, Camera, WebGLRenderer, WebGLRendererParameters } from 'three';
import { EffectComposer } from 'three/examples/jsm/postprocessing/EffectComposer.js';
import { ThreeGlobeGeneric, ConfigOptions as ThreeGlobeConfigOptions } from 'three-globe';

Expand All @@ -21,6 +21,8 @@ interface GeoCoords {
altitude: number;
}

type PointerEventsFilterFn = (object: Object3D, data: object) => boolean;

export interface GlobeGenericInstance<ChainableInstance> extends ThreeGlobeGeneric<ChainableInstance> {
(element: HTMLElement): ChainableInstance;
resetProps(): ChainableInstance;
Expand Down Expand Up @@ -87,6 +89,8 @@ export interface GlobeGenericInstance<ChainableInstance> extends ThreeGlobeGener
resumeAnimation(): ChainableInstance;
enablePointerInteraction(): boolean;
enablePointerInteraction(enable: boolean): ChainableInstance;
pointerEventsFilter(): PointerEventsFilterFn;
pointerEventsFilter(filterFn: PointerEventsFilterFn): ChainableInstance;
onZoom(callback: (pov: GeoCoords) => void): ChainableInstance;
scene(): Scene;
camera(): Camera;
Expand Down

0 comments on commit 7f7e015

Please sign in to comment.