@@ -6,23 +6,13 @@ import { registerDialogContainer } from "../../components";
66import { PointData } from "../../data" ;
77// eslint-disable-next-line @typescript-eslint/no-unused-vars
88import { isHoverTextData , HoverTextData } from "../../data/hover" ;
9- // eslint-disable-next-line @typescript-eslint/no-unused-vars
10- import { isLinkData , LinkData } from "../../data/link" ;
119import { GlobeLayerAttachHook } from "../layer" ;
12- import { isLabelsData } from "../../data/label" ;
13- import {
14- addClickListener ,
15- addMouseEventListener ,
16- MouseInteractionLayer ,
17- } from "./mouseevents" ;
10+ import { addMouseEventListener , MouseInteractionLayer } from "./mouseevents" ;
1811
1912/**
20- * Globe layer for all objects that implement {@link HoverTextData} or {@link LinkData}.
21- *
22- * If an object also has a label attached, then hover window is opened on click only.
23- * If both hover text and link are provided, link is available when clicking on the opened hover window.
13+ * Globe layer for all objects that implement {@link HoverTextData}.
2414 *
25- * Implements {@link MouseInteractionLayer} to provide hover and click functionality .
15+ * Implements {@link MouseInteractionLayer} to provide hover.
2616 */
2717export class HoverTextObjectsLayer
2818 implements
@@ -37,8 +27,6 @@ export class HoverTextObjectsLayer
3727 private hoverWindow : HTMLDivElement | null = null ;
3828 private hoverWindowPosition = new THREE . Vector3 ( ) ;
3929 private hoverLabelText : HTMLParagraphElement | null = null ;
40- private urlToOpen : string | null = null ;
41- private openUrlInNewWindow : boolean = true ;
4230
4331 attachToGlobe (
4432 _globe : ThreeGlobe ,
@@ -62,19 +50,6 @@ export class HoverTextObjectsLayer
6250 ` ;
6351 this . hoverWindow =
6452 hoverDialogContainer . querySelector < HTMLDivElement > ( "#hoverDialog" ) ;
65- const dialogArea =
66- hoverDialogContainer . querySelector < HTMLDivElement > ( "#hoverDialogArea" ) ! ;
67- dialogArea . addEventListener ( "click" , ( _event : Event ) => {
68- if ( this . urlToOpen ) {
69- window . open (
70- this . urlToOpen ,
71- this . openUrlInNewWindow ? "_blank" : "_self" ,
72- ) ;
73- }
74- if ( this . hoverWindow ) {
75- this . hoverWindow . hidden = true ;
76- }
77- } ) ;
7853 this . hoverLabelText =
7954 hoverDialogContainer . querySelector < HTMLParagraphElement > (
8055 "#hoverDialogText" ,
@@ -83,43 +58,25 @@ export class HoverTextObjectsLayer
8358
8459 buildObject ( parent : Object3D , object : PointData ) : void {
8560 if ( isHoverTextData ( object ) && object . hover_text ) {
86- addMouseEventListener (
87- isLabelsData ( object ) && object . display_text ? "click" : "hover" ,
88- parent ,
89- ( ) => {
90- this . hadMouseHits = true ;
91- if ( this . hoverLabelText ) {
92- this . hoverLabelText . innerText = object . hover_text ?? "" ;
93- }
94- if ( this . hoverWindow ) {
95- parent . getWorldPosition ( this . hoverWindowPosition ) ;
96- this . hoverWindow . hidden = false ;
97- this . hoverWindowPosition . project ( this . cachedCamera ! ) ;
98- this . hoverWindowPosition . x =
99- ( this . hoverWindowPosition . x * window . innerWidth ) / 2 +
100- window . innerWidth / 2 ;
101- this . hoverWindowPosition . y =
102- - ( ( this . hoverWindowPosition . y * window . innerHeight ) / 2 ) +
103- window . innerHeight / 2 ;
104- this . hoverWindow . style . top =
105- this . hoverWindowPosition . y . toString ( ) + "px" ;
106- this . hoverWindow . style . left =
107- this . hoverWindowPosition . x . toString ( ) + "px" ;
108- if ( isLinkData ( object ) && object . link_url ) {
109- this . urlToOpen = object . link_url ;
110- this . openUrlInNewWindow =
111- object . new_window == true || object . new_window == null ;
112- }
113- }
114- } ,
115- ) ;
116- } else if ( isLinkData ( object ) && object . link_url ) {
117- addClickListener ( parent , ( ) => {
118- if ( object . link_url ) {
119- window . open (
120- object . link_url ,
121- object . new_window === false ? "_self" : "_blank" ,
122- ) ;
61+ addMouseEventListener ( "hover" , parent , ( ) => {
62+ this . hadMouseHits = true ;
63+ if ( this . hoverLabelText ) {
64+ this . hoverLabelText . innerText = object . hover_text ?? "" ;
65+ }
66+ if ( this . hoverWindow ) {
67+ parent . getWorldPosition ( this . hoverWindowPosition ) ;
68+ this . hoverWindow . hidden = false ;
69+ this . hoverWindowPosition . project ( this . cachedCamera ! ) ;
70+ this . hoverWindowPosition . x =
71+ ( this . hoverWindowPosition . x * window . innerWidth ) / 2 +
72+ window . innerWidth / 2 ;
73+ this . hoverWindowPosition . y =
74+ - ( ( this . hoverWindowPosition . y * window . innerHeight ) / 2 ) +
75+ window . innerHeight / 2 ;
76+ this . hoverWindow . style . top =
77+ this . hoverWindowPosition . y . toString ( ) + "px" ;
78+ this . hoverWindow . style . left =
79+ this . hoverWindowPosition . x . toString ( ) + "px" ;
12380 }
12481 } ) ;
12582 }
0 commit comments