Skip to content
Snippets Groups Projects
Commit 25279041 authored by L4168's avatar L4168
Browse files

mapdrawing replay wip

parent a0e0dfc2
No related branches found
No related tags found
2 merge requests!46Development to testing,!45Mapdrawing replay
This commit is part of merge request !45. Comments created here will be created in the context of that merge request.
...@@ -73,7 +73,10 @@ export default class ReplayMap extends React.Component { ...@@ -73,7 +73,10 @@ export default class ReplayMap extends React.Component {
}).addTo(this.map); }).addTo(this.map);
// import options from ReplayConfig.js // import options from ReplayConfig.js
this.trackplayback = new L.TrackPlayBack(this.state, this.map, options); this.trackplayback = new L.TrackPlayBack(this.state, this.map, options);
this.trackplaybackControl = L.trackplaybackcontrol(this.trackplayback); this.trackplaybackControl = L.trackplaybackcontrol(
this.trackplayback,
this.map
);
this.trackplaybackControl.addTo(this.map); this.trackplaybackControl.addTo(this.map);
}; };
......
...@@ -9,10 +9,60 @@ export const TrackPlayBackControl = L.Control.extend({ ...@@ -9,10 +9,60 @@ export const TrackPlayBackControl = L.Control.extend({
autoPlay: false autoPlay: false
}, },
initialize: function(trackplayback, options) { initialize: function(trackplayback, map, options) {
this.map = map;
L.Control.prototype.initialize.call(this, options); L.Control.prototype.initialize.call(this, options);
this.trackPlayBack = trackplayback; this.trackPlayBack = trackplayback;
this.trackPlayBack.on("tick", this._tickCallback, this); this.trackPlayBack.on("tick", this._tickCallback, this);
this.leafletDrawings = [];
},
// init object to pass drawing data to right function
_drawFunction: function(data) {
// create leaflet objects
var createMarker = data => {
return L.polyline(data.geometry.coordinates).addTo(this.map);
};
var createPolyline = data => {
data.geometry.coordinates = data.geometry.coordinates.map(cords => {
return [cords[1], cords[0]];
});
return L.polyline(data.geometry.coordinates, {
color: data.properties.color
}).addTo(this.map);
};
var createPolygon = data => {
// geoJSON has lat lng wrong way so turn them around
data.geometry.coordinates = data.geometry.coordinates[0].map(cords => {
return [cords[1], cords[0]];
});
return L.polygon(data.geometry.coordinates, {
color: data.properties.color
}).addTo(this.map);
};
var createRectangle = data => {
return L.rectangle(data.geometry.coordinates, {
color: data.properties.color
}).addTo(this.map);
};
var createCircle = data => {
return L.circle(data.geometry.coordinates, {
radius: data.properties.radius
}).addTo(this.map);
};
// handle faulty cords
if (!data.geometry.coordinates[0][0]) {
return null;
}
var obj = {
Marker: createMarker,
LineString: createPolyline,
Polygon: createPolygon,
Rectangle: createRectangle,
Circle: createCircle
};
return obj[data.geometry.type](data);
}, },
onAdd: function(map) { onAdd: function(map) {
...@@ -383,6 +433,23 @@ export const TrackPlayBackControl = L.Control.extend({ ...@@ -383,6 +433,23 @@ export const TrackPlayBackControl = L.Control.extend({
for (let i = 0; i < this._factionScoreboxes.length; i++) { for (let i = 0; i < this._factionScoreboxes.length; i++) {
this._factionScoreboxes[i].innerHTML = this.trackPlayBack.passScores(i); this._factionScoreboxes[i].innerHTML = this.trackPlayBack.passScores(i);
} }
// tick drawings
let drawings = this.trackPlayBack.passDrawings();
for (let i = 0; i < drawings.length; i++) {
// skip if undefined
if (!drawings[i]) return;
// remove if it's not active
if (!drawings[i].drawingIsActive && this.leafletDrawings[i]) {
this.map.removeLayer(this.leafletDrawings[i]);
this.leafletDrawings[i] = null;
return;
}
// else draw the marker if it's not drawn
if (!this.leafletDrawings[i]) {
this.leafletDrawings[i] = this._drawFunction(drawings[i].data);
}
}
//
// 更新时间轴 // 更新时间轴
this._slider.value = e.time; this._slider.value = e.time;
// 播放结束后改变播放按钮样式 // 播放结束后改变播放按钮样式
...@@ -395,6 +462,6 @@ export const TrackPlayBackControl = L.Control.extend({ ...@@ -395,6 +462,6 @@ export const TrackPlayBackControl = L.Control.extend({
} }
}); });
export const trackplaybackcontrol = function(trackplayback, options) { export const trackplaybackcontrol = function(trackplayback, map, options) {
return new TrackPlayBackControl(trackplayback, options); return new TrackPlayBackControl(trackplayback, map, options);
}; };
...@@ -8,12 +8,14 @@ import { Track } from "./track"; ...@@ -8,12 +8,14 @@ import { Track } from "./track";
* 控制轨迹和绘制 * 控制轨迹和绘制
*/ */
export const TrackController = L.Class.extend({ export const TrackController = L.Class.extend({
initialize: function(tracks = [], draw, allScores, options) { initialize: function(data, draw, options) {
L.setOptions(this, options); L.setOptions(this, options);
this._activeScores = [0, 0]; this._activeScores = [];
this._tracks = []; this._activeDrawings = [];
this._scores = allScores; this._tracks = data.tracks;
this.addTrack(tracks); this._scores = data.scores;
this._drawings = data.drawings;
this.addTrack(data.tracks || []);
this._draw = draw; this._draw = draw;
...@@ -45,11 +47,13 @@ export const TrackController = L.Class.extend({ ...@@ -45,11 +47,13 @@ export const TrackController = L.Class.extend({
drawTracksByTime: function(time) { drawTracksByTime: function(time) {
this._draw.clear(); this._draw.clear();
// draw player locations
for (let i = 0, len = this._tracks.length; i < len; i++) { for (let i = 0, len = this._tracks.length; i < len; i++) {
let track = this._tracks[i]; let track = this._tracks[i];
let tps = track.getTrackPointsBeforeTime(time); let tps = track.getTrackPointsBeforeTime(time);
if (tps && tps.length) this._draw.drawTrack(tps); if (tps && tps.length) this._draw.drawTrack(tps);
} }
// add scores to counter
for (let i = 0; i < this._scores.length; i++) { for (let i = 0; i < this._scores.length; i++) {
let newScore = 0; let newScore = 0;
let scores = this._scores[i]; let scores = this._scores[i];
...@@ -60,6 +64,16 @@ export const TrackController = L.Class.extend({ ...@@ -60,6 +64,16 @@ export const TrackController = L.Class.extend({
} }
this._activeScores[i] = newScore; this._activeScores[i] = newScore;
} }
// draw mapdrawings to map
for (let i = 0; i < this._drawings.length; i++) {
let drawing;
for (let j = 0; j < this._drawings[i].length; j++) {
if (this._drawings[i][j].timestamp < time) {
drawing = this._drawings[i][j];
}
}
if (drawing) this._activeDrawings[i] = drawing;
}
}, },
_updateTime: function() { _updateTime: function() {
......
...@@ -27,9 +27,12 @@ export const TrackPlayBack = L.Class.extend({ ...@@ -27,9 +27,12 @@ export const TrackPlayBack = L.Class.extend({
this.tracks = this._initTracks(data.players); this.tracks = this._initTracks(data.players);
this.draw = new Draw(map, drawOptions); this.draw = new Draw(map, drawOptions);
this.trackController = new TrackController( this.trackController = new TrackController(
this.tracks, {
this.draw, tracks: this.tracks,
data.scores scores: data.scores,
drawings: data.drawings
},
this.draw
); );
this.clock = new Clock(this.trackController, options.clockOptions); this.clock = new Clock(this.trackController, options.clockOptions);
...@@ -122,9 +125,14 @@ export const TrackPlayBack = L.Class.extend({ ...@@ -122,9 +125,14 @@ export const TrackPlayBack = L.Class.extend({
passFactions: function() { passFactions: function() {
return this.draw.filterOptions.factions; return this.draw.filterOptions.factions;
}, },
// pass current scores to control panel
passScores: function(i) { passScores: function(i) {
return this.trackController._activeScores[i]; return this.trackController._activeScores[i];
}, },
// pass current drawings to control panel
passDrawings: function() {
return this.trackController._activeDrawings;
},
dispose: function() { dispose: function() {
this.clock.off("tick", this._tick); this.clock.off("tick", this._tick);
this.draw.remove(); this.draw.remove();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment