mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2025-06-28 06:12:08 +02:00
Added players layer and update data in manual and auto mode.
This commit is contained in:
@ -1,7 +1,8 @@
|
||||
L.Control.AutoUpdate = L.Control.extend({
|
||||
options: {
|
||||
position: 'topleft',
|
||||
label: 'Automatic update'
|
||||
label: 'Automatic update',
|
||||
layer: undefined
|
||||
},
|
||||
pressed: true,
|
||||
|
||||
@ -37,27 +38,46 @@ L.Control.AutoUpdate = L.Control.extend({
|
||||
},
|
||||
|
||||
autoUpdate: function() {
|
||||
var me = this;
|
||||
this.socket = new WebSocket('ws://' + window.location.host + '/ws');
|
||||
|
||||
this.socket.onmessage = function(evt) {
|
||||
|
||||
var updatePlayers = function(json) {
|
||||
if (!(typeof json === "string")) {
|
||||
return;
|
||||
}
|
||||
var players;
|
||||
try {
|
||||
players = JSON.parse(json);
|
||||
}
|
||||
catch (err) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (players.players) {
|
||||
me.options.layer.clearLayers();
|
||||
me.options.layer.addData(players.players);
|
||||
}
|
||||
}(evt.data);
|
||||
|
||||
var invalidate = function(json) {
|
||||
var invalidateAll = function(x, y, z) { return true; };
|
||||
|
||||
if (!(typeof json === "string")) {
|
||||
return invalidateAll;
|
||||
}
|
||||
var msg;
|
||||
var tiles;
|
||||
var tileData;
|
||||
try {
|
||||
msg = JSON.parse(json);
|
||||
var tileData = JSON.parse(json);
|
||||
} catch (err) {
|
||||
return invalidateAll;
|
||||
}
|
||||
|
||||
var tiles = msg.tiles;
|
||||
if !tiles {
|
||||
continue;
|
||||
if (!tileData.tiles) {
|
||||
return invalidateAll;
|
||||
}
|
||||
tiles = tileData.tiles;
|
||||
|
||||
var pyramid = new Array(9);
|
||||
var last = new Object();
|
||||
@ -119,7 +139,7 @@ L.Control.AutoUpdate = L.Control.extend({
|
||||
}
|
||||
});
|
||||
|
||||
L.autoUpdate = function(cbLabel, cbFunc, cbMap) {
|
||||
L.autoUpdate = function(cbLabel, cbFunc, layer, cbMap) {
|
||||
var control = new L.Control.AutoUpdate();
|
||||
if (cbLabel) {
|
||||
control.options.label = cbLabel;
|
||||
@ -129,6 +149,10 @@ L.autoUpdate = function(cbLabel, cbFunc, cbMap) {
|
||||
control.intendedFunction = cbFunc;
|
||||
}
|
||||
|
||||
if (layer) {
|
||||
control.options.layer = layer;
|
||||
}
|
||||
|
||||
if (cbMap === '') {
|
||||
return control;
|
||||
}
|
||||
|
Reference in New Issue
Block a user