Changeset 153 for binary-improvements/webserver/js
- Timestamp:
- Sep 2, 2014, 9:31:07 PM (10 years ago)
- Location:
- binary-improvements/webserver/js
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/webserver/js/index.js
r150 r153 124 124 } 125 125 126 var playersOnlineMarkerGroup = L.layerGroup(); 127 var playersOfflineMarkerGroup = L.layerGroup(); 128 126 129 var baseLayers = { 127 130 //"Map": tileLayer … … 129 132 130 133 var overlays = { 131 "Region files": regionLayer 134 "Region files": regionLayer, 135 "Players (online)" : playersOnlineMarkerGroup, 136 "Players (offline)" : playersOfflineMarkerGroup 132 137 }; 133 138 … … 140 145 L.DomUtil.get('pos').textContent = FormatCoord(e.latlng); 141 146 }); 147 148 var playersMappingList = {}; 149 150 var setPlayerMarkers = function(data) { 151 $.each( data, function( key, val ) { 152 var marker; 153 if (playersMappingList.hasOwnProperty(val.steamid)) { 154 marker = playersMappingList[val.steamid].currentPosMarker; 155 marker.setLatLng([val.position.z, val.position.x]); 156 } else { 157 marker = L.marker([val.position.z, val.position.x]).bindPopup(val.name); 158 playersOnlineMarkerGroup.addLayer(marker); 159 playersMappingList[val.steamid] = { online: !val.online }; 160 } 161 if (playersMappingList[val.steamid].online != val.online) { 162 if (val.online) { 163 marker.setOpacity(1.0); 164 playersOfflineMarkerGroup.removeLayer(marker); 165 playersOnlineMarkerGroup.addLayer(marker); 166 } else { 167 marker.setOpacity(0.5); 168 playersOnlineMarkerGroup.removeLayer(marker); 169 playersOfflineMarkerGroup.addLayer(marker); 170 } 171 } 172 val.currentPosMarker = marker; 173 playersMappingList[val.steamid] = val; 174 }); 175 } 176 177 var updatePlayerEvent = function() { 178 $.getJSON( "../api/getplayerslocation") 179 .done(setPlayerMarkers) 180 .fail(function() { 181 console.log("Error fetching players list"); 182 }) 183 .always(function() { 184 window.setTimeout(updatePlayerEvent, 2000); 185 }); 186 } 187 188 window.setTimeout(updatePlayerEvent, 500); 189
Note:
See TracChangeset
for help on using the changeset viewer.