@@ -15,6 +15,8 @@ export default class PlayerMarker extends Marker {
1515
1616 this . animationRunning = false ;
1717 this . lastFrame = - 1 ;
18+
19+ this . follow = false ;
1820 }
1921
2022 setVisible ( visible ) {
@@ -23,17 +25,18 @@ export default class PlayerMarker extends Marker {
2325 this . blueMap . updateFrame = true ;
2426
2527 if ( ! this . renderObject ) {
26- let iconElement = $ ( `<div class="marker-player"><img src="assets/playerheads/${ this . player } .png" onerror="this.onerror=null;this.src='${ STEVE } ';"><div class="nameplate">${ this . label } </div></div>` ) ;
27- iconElement . find ( "img" ) . click ( this . onClick ) ;
28+ this . iconElement = $ ( `<div class="marker-player"><img src="assets/playerheads/${ this . player } .png" onerror="this.onerror=null;this.src='${ STEVE } ';"><div class="nameplate">${ this . label } </div></div>` ) ;
29+ this . iconElement . find ( "img" ) . click ( this . onClick ) ;
30+ $ ( window ) . on ( 'mousedown touchstart' , this . onStopFollowing ) ;
2831
29- this . renderObject = new CSS2DObject ( iconElement [ 0 ] ) ;
32+ this . renderObject = new CSS2DObject ( this . iconElement [ 0 ] ) ;
3033 this . renderObject . position . copy ( this . position ) ;
3134 this . renderObject . onBeforeRender = ( renderer , scene , camera ) => {
3235 let distanceSquared = this . position . distanceToSquared ( camera . position ) ;
3336 if ( distanceSquared > 1000000 ) {
34- iconElement . addClass ( "distant" ) ;
37+ this . iconElement . addClass ( "distant" ) ;
3538 } else {
36- iconElement . removeClass ( "distant" ) ;
39+ this . iconElement . removeClass ( "distant" ) ;
3740 }
3841
3942 this . updateRenderObject ( this . renderObject , scene , camera ) ;
@@ -57,6 +60,11 @@ export default class PlayerMarker extends Marker {
5760 } else {
5861 this . renderObject . position . copy ( this . position ) ;
5962 }
63+
64+ if ( this . follow ) {
65+ this . blueMap . controls . targetPosition . x = this . position . x ;
66+ this . blueMap . controls . targetPosition . z = this . position . z ;
67+ }
6068 }
6169 } ;
6270
@@ -86,7 +94,18 @@ export default class PlayerMarker extends Marker {
8694 } ;
8795
8896 onClick = ( ) => {
97+ this . follow = true ;
98+ this . iconElement . addClass ( "following" ) ;
8999
90- }
100+ this . blueMap . controls . targetPosition . x = this . position . x ;
101+ this . blueMap . controls . targetPosition . z = this . position . z ;
102+ } ;
103+
104+ onStopFollowing = event => {
105+ if ( this . follow ) {
106+ this . follow = true ;
107+ this . iconElement . removeClass ( "following" ) ;
108+ }
109+ } ;
91110
92111}
0 commit comments