Merge branch 'master' of https://github.com/NathanWolf/dynmap
This commit is contained in:
commit
f04185f8fc
1 changed files with 53 additions and 3 deletions
56
web/map.js
56
web/map.js
|
|
@ -75,6 +75,7 @@ DynMap.prototype = {
|
||||||
registeredTiles: new Array(),
|
registeredTiles: new Array(),
|
||||||
clock: null,
|
clock: null,
|
||||||
markers: new Array(),
|
markers: new Array(),
|
||||||
|
chatPopups: new Array(),
|
||||||
lasttimestamp: '0',
|
lasttimestamp: '0',
|
||||||
followingPlayer: '',
|
followingPlayer: '',
|
||||||
initialize: function() {
|
initialize: function() {
|
||||||
|
|
@ -180,6 +181,10 @@ DynMap.prototype = {
|
||||||
},
|
},
|
||||||
update: function() {
|
update: function() {
|
||||||
var me = this;
|
var me = this;
|
||||||
|
|
||||||
|
// TODO: is there a better place for this?
|
||||||
|
this.cleanPopups();
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: me.options.updateUrl + me.lasttimestamp,
|
url: me.options.updateUrl + me.lasttimestamp,
|
||||||
success: function(res) {
|
success: function(res) {
|
||||||
|
|
@ -258,18 +263,63 @@ DynMap.prototype = {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
cleanPopups: function() {
|
||||||
|
var POPUP_LIFE = 8000;
|
||||||
|
var d = new Date();
|
||||||
|
var now = d.getTime();
|
||||||
|
for (var popupIndex in this.chatPopups)
|
||||||
|
{
|
||||||
|
var popup = this.chatPopups[popupIndex];
|
||||||
|
if (now - popup.popupTime > POPUP_LIFE)
|
||||||
|
{
|
||||||
|
popup.infoWindow.close();
|
||||||
|
popup.infoWindow = null;
|
||||||
|
this.chatPopups[popupIndex] = popup;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
onPlayerChat: function(playerName, message) {
|
onPlayerChat: function(playerName, message) {
|
||||||
var me = this;
|
var me = this;
|
||||||
var markers = me.markers;
|
var markers = me.markers;
|
||||||
|
var chatPopups = this.chatPopups;
|
||||||
var map = me.map;
|
var map = me.map;
|
||||||
var mid = "player_" + playerName;
|
var mid = "player_" + playerName;
|
||||||
var playerMarker = markers[mid];
|
var playerMarker = markers[mid];
|
||||||
if (playerMarker)
|
if (playerMarker)
|
||||||
{
|
{
|
||||||
var infowindow = new google.maps.InfoWindow({
|
var popup = chatPopups[playerName];
|
||||||
content: message
|
if (popup == null)
|
||||||
|
{
|
||||||
|
popup = new Object();
|
||||||
|
popup.lines = new Array();
|
||||||
|
popup.lines[0] = message;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (popup.infoWindow != null)
|
||||||
|
{
|
||||||
|
popup.infoWindow.close();
|
||||||
|
}
|
||||||
|
popup.lines[popup.lines.length] = message;
|
||||||
|
}
|
||||||
|
var MAX_LINES = 5;
|
||||||
|
if (popup.lines.length > MAX_LINES)
|
||||||
|
{
|
||||||
|
popup.lines = popup.lines.slice(1);
|
||||||
|
}
|
||||||
|
htmlMessage = '<div id="content"><b>' + playerName + "</b><br/><br/>"
|
||||||
|
for (var line in popup.lines)
|
||||||
|
{
|
||||||
|
htmlMessage = htmlMessage + popup.lines[line] + "<br/>";
|
||||||
|
}
|
||||||
|
htmlMessage = htmlMessage + "</div>"
|
||||||
|
var now = new Date();
|
||||||
|
popup.popupTime = now.getTime();
|
||||||
|
popup.infoWindow = new google.maps.InfoWindow({
|
||||||
|
content: htmlMessage
|
||||||
});
|
});
|
||||||
infowindow.open(map,playerMarker);
|
popup.infoWindow.open(map, playerMarker);
|
||||||
|
this.chatPopups[playerName] = popup;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onTileUpdated: function(tileName) {
|
onTileUpdated: function(tileName) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue