@@ -296,17 +296,6 @@ function getPlayerInfoHtml(plr) {
296296 return html ;
297297}
298298
299- function updatePopups ( ) {
300- console . log ( "Updating?" ) ;
301- for ( const key in localCache ) {
302- //MarkerStore[localCache[plr.identifer].marker].unbindPopup();
303- //MarkerStore[localCache[plr.identifer].marker].bindPopup(infoContent);
304- MarkerStore [ localCache [ key ] . marker ] . setPopupContent ( localCache [ key ] . lastHtml ) ;
305- }
306- }
307-
308- setInterval ( updatePopups , 5000 ) ;
309-
310299function doPlayerUpdate ( players ) {
311300
312301 if ( config . debug ) {
@@ -351,23 +340,41 @@ function doPlayerUpdate(players) {
351340
352341 var infoContent = '<div class="info-window"><div class="info-header-box"><div class="info-header">' + plr . name + '</div></div><div class="clear"></div><div id=info-body>' + html + "</div></div>" ;
353342
354- //console.log(infoContent !== localCache[plr.identifer].lastHtml);
355- if ( infoContent !== localCache [ plr . identifer ] . lastHtml ) {
343+ var m = localCache [ plr . identifer ] . marker ;
344+ var marker = MarkerStore [ m ] ;
345+ var popup = PopupStore [ m ] ;
346+
347+ if ( infoContent != localCache [ plr . identifer ] . lastHtml ) {
348+ popup . setContent ( infoContent ) ;
356349 localCache [ plr . identifer ] . lastHtml = infoContent ;
357- //MarkerStore[localCache[plr.identifer].marker].unbindPopup();
358- //MarkerStore[localCache[plr.identifer].marker].bindPopup(infoContent);
350+ }
351+
352+ if ( popup . isOpen ( ) ) {
353+ if ( popup . getLatLng ( ) . distanceTo ( marker . getLatLng ( ) ) != 0 ) {
354+ popup . setLatLng ( marker . getLatLng ( ) ) ;
355+ }
359356 }
360357
361358
362359 } else {
360+ localCache [ plr . identifer ] . lastHtml = infoContent ;
361+ var html = getPlayerInfoHtml ( plr ) ;
362+ var infoContent = '<div class="info-window"><div class="info-header-box"><div class="info-icon"></div><div class="info-header">' + plr . name + '</div></div><div class="clear"></div><div id=info-body>' + html + "</div></div>" ;
363363
364364 var obj = new MarkerObject ( plr . name , new Coordinates ( plr . pos . x , plr . pos . y , plr . pos . z ) , MarkerTypes [ 6 ] , "" , { isPlayer : true , player : plr } ) ;
365365 var m = localCache [ plr . identifer ] . marker = createMarker ( false , false , obj , plr . name ) - 1 ;
366366
367- var html = getPlayerInfoHtml ( plr ) ;
368-
369- var infoContent = '<div class="info-window"><div class="info-header-box"><div class="info-icon"></div><div class="info-header">' + plr . name + '</div></div><div class="clear"></div><div id=info-body>' + html + "</div></div>" ;
370- localCache [ plr . identifer ] . lastHtml = infoContent ;
367+ MarkerStore [ m ] . unbindPopup ( ) ; // We want to handle the popups ourselfs.
368+ PopupStore [ m ] = L . popup ( )
369+ . setContent ( infoContent )
370+ . setLatLng ( MarkerStore [ m ] . getLatLng ( ) ) ; // Make a new marker
371+
372+ MarkerStore [ m ] . on ( "click" , function ( e ) {
373+ console . _log ( e ) ;
374+ Map . closePopup ( Map . _popup ) ;
375+ PopupStore [ e . target . options . id ] . setLatLng ( e . latlng ) ;
376+ Map . openPopup ( PopupStore [ e . target . options . id ] ) ;
377+ } ) ;
371378 }
372379
373380 } ) ;
0 commit comments