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

barely working drawing replay

parent 25279041
No related branches found
No related tags found
2 merge requests!46Development to testing,!45Mapdrawing replay
...@@ -17,11 +17,16 @@ export const TrackPlayBackControl = L.Control.extend({ ...@@ -17,11 +17,16 @@ export const TrackPlayBackControl = L.Control.extend({
this.leafletDrawings = []; this.leafletDrawings = [];
}, },
// absolutely disgusting, never use geojson
// init object to pass drawing data to right function // init object to pass drawing data to right function
_drawFunction: function(data) { _drawFunction: function(data) {
// create leaflet objects // create leaflet objects
var createMarker = data => { var createMarker = data => {
return L.polyline(data.geometry.coordinates).addTo(this.map); data.geometry.coordinates = [
data.geometry.coordinates[1],
data.geometry.coordinates[0]
];
return L.marker(data.geometry.coordinates).addTo(this.map);
}; };
var createPolyline = data => { var createPolyline = data => {
data.geometry.coordinates = data.geometry.coordinates.map(cords => { data.geometry.coordinates = data.geometry.coordinates.map(cords => {
...@@ -46,21 +51,27 @@ export const TrackPlayBackControl = L.Control.extend({ ...@@ -46,21 +51,27 @@ export const TrackPlayBackControl = L.Control.extend({
}).addTo(this.map); }).addTo(this.map);
}; };
var createCircle = data => { var createCircle = data => {
data.geometry.coordinates = [
data.geometry.coordinates[1],
data.geometry.coordinates[0]
];
return L.circle(data.geometry.coordinates, { return L.circle(data.geometry.coordinates, {
radius: data.properties.radius radius: data.properties.radius
}).addTo(this.map); }).addTo(this.map);
}; };
// handle faulty cords // handle faulty cords
if (!data.geometry.coordinates[0][0]) { if (!data.geometry.coordinates[0][0] && !data.geometry.type === "Point") {
return null; return null;
} }
if (data.geometry.type === "Point" && !data.properties.radius) {
data.geometry.type = "Marker";
}
var obj = { var obj = {
Marker: createMarker, Marker: createMarker,
LineString: createPolyline, LineString: createPolyline,
Polygon: createPolygon, Polygon: createPolygon,
Rectangle: createRectangle, Rectangle: createRectangle,
Circle: createCircle Point: createCircle
}; };
return obj[data.geometry.type](data); return obj[data.geometry.type](data);
}, },
...@@ -429,6 +440,14 @@ export const TrackPlayBackControl = L.Control.extend({ ...@@ -429,6 +440,14 @@ export const TrackPlayBackControl = L.Control.extend({
// 更新时间 // 更新时间
let time = this.getTimeStrFromUnix(e.time); let time = this.getTimeStrFromUnix(e.time);
this._infoCurTime.innerHTML = time; this._infoCurTime.innerHTML = time;
this._slider.value = e.time;
// 播放结束后改变播放按钮样式
if (e.time >= this.trackPlayBack.getEndTime()) {
L.DomUtil.removeClass(this._playBtn, "btn-start");
L.DomUtil.addClass(this._playBtn, "btn-stop");
this._playBtn.setAttribute("title", "play");
this.trackPlayBack.stop();
}
// tick scores // tick scores
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);
...@@ -437,6 +456,11 @@ export const TrackPlayBackControl = L.Control.extend({ ...@@ -437,6 +456,11 @@ export const TrackPlayBackControl = L.Control.extend({
let drawings = this.trackPlayBack.passDrawings(); let drawings = this.trackPlayBack.passDrawings();
for (let i = 0; i < drawings.length; i++) { for (let i = 0; i < drawings.length; i++) {
// skip if undefined // skip if undefined
if (!drawings[i] && this.leafletDrawings[i]) {
this.map.removeLayer(this.leafletDrawings[i]);
this.leafletDrawings[i] = null;
return;
}
if (!drawings[i]) return; if (!drawings[i]) return;
// remove if it's not active // remove if it's not active
if (!drawings[i].drawingIsActive && this.leafletDrawings[i]) { if (!drawings[i].drawingIsActive && this.leafletDrawings[i]) {
...@@ -445,20 +469,13 @@ export const TrackPlayBackControl = L.Control.extend({ ...@@ -445,20 +469,13 @@ export const TrackPlayBackControl = L.Control.extend({
return; return;
} }
// else draw the marker if it's not drawn // else draw the marker if it's not drawn
if (!this.leafletDrawings[i]) { if (drawings[i].drawingIsActive && !this.leafletDrawings[i]) {
this.leafletDrawings[i] = this._drawFunction(drawings[i].data); this.leafletDrawings[i] = this._drawFunction(drawings[i].data);
console.log(this.leafletDrawings[i]);
} }
} }
// //
// 更新时间轴 // 更新时间轴
this._slider.value = e.time;
// 播放结束后改变播放按钮样式
if (e.time >= this.trackPlayBack.getEndTime()) {
L.DomUtil.removeClass(this._playBtn, "btn-start");
L.DomUtil.addClass(this._playBtn, "btn-stop");
this._playBtn.setAttribute("title", "play");
this.trackPlayBack.stop();
}
} }
}); });
......
...@@ -66,13 +66,13 @@ export const TrackController = L.Class.extend({ ...@@ -66,13 +66,13 @@ export const TrackController = L.Class.extend({
} }
// draw mapdrawings to map // draw mapdrawings to map
for (let i = 0; i < this._drawings.length; i++) { for (let i = 0; i < this._drawings.length; i++) {
let drawing; let drawing = null;
for (let j = 0; j < this._drawings[i].length; j++) { for (let j = 0; j < this._drawings[i].length; j++) {
if (this._drawings[i][j].timestamp < time) { if (this._drawings[i][j].timestamp < time) {
drawing = this._drawings[i][j]; drawing = this._drawings[i][j];
} }
} }
if (drawing) this._activeDrawings[i] = drawing; this._activeDrawings[i] = drawing;
} }
}, },
......
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