@@ -296,17 +296,6 @@ function getPlayerInfoHtml(plr) {
296
296
return html ;
297
297
}
298
298
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
-
310
299
function doPlayerUpdate ( players ) {
311
300
312
301
if ( config . debug ) {
@@ -351,23 +340,41 @@ function doPlayerUpdate(players) {
351
340
352
341
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>" ;
353
342
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 ) ;
356
349
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
+ }
359
356
}
360
357
361
358
362
359
} 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>" ;
363
363
364
364
var obj = new MarkerObject ( plr . name , new Coordinates ( plr . pos . x , plr . pos . y , plr . pos . z ) , MarkerTypes [ 6 ] , "" , { isPlayer : true , player : plr } ) ;
365
365
var m = localCache [ plr . identifer ] . marker = createMarker ( false , false , obj , plr . name ) - 1 ;
366
366
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
+ } ) ;
371
378
}
372
379
373
380
} ) ;
0 commit comments