Skip to content

Commit 704285a

Browse files
committed
callback after nextPoint
1 parent 8096b27 commit 704285a

File tree

7 files changed

+419
-230
lines changed

7 files changed

+419
-230
lines changed
Lines changed: 1 addition & 0 deletions
Loading

lib/components/laeflet-react-track-player/index.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,18 @@
6161
background-image: url("./icon/speed.svg");
6262
}
6363

64+
.tp_button.stream {
65+
background-image: url("./icon/stream.svg");
66+
}
67+
6468
.tp_button:last-child {
6569
margin-right: 0;
6670
}
6771

72+
.tp_button:disabled {
73+
opacity: .3;
74+
}
75+
6876
.tp_track-line {
6977
width: 460px;
7078
height: 50px;

lib/components/laeflet-react-track-player/index.js

Lines changed: 168 additions & 42 deletions
Large diffs are not rendered by default.

lib/components/laeflet-react-track-player/snake.js

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ var _moment = require("moment");
88

99
var _moment2 = _interopRequireDefault(_moment);
1010

11+
var _index = require("./index");
12+
1113
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1214

1315
_leaflet2.default.Polyline.include({
@@ -69,7 +71,7 @@ _leaflet2.default.Polyline.include({
6971
if (!this._snakeLatLngs) this._snakeLatLngs = this._latlngs;
7072
if (this._snakeLatLngs.length === params.points.length) {
7173
this.setLatLngs(this._snakeLatLngs);
72-
this._snaking = false;
74+
if (!params.last) this._snaking = false;
7375
} else {
7476
if (params.points.length !== 1) {
7577
this.setLatLngs(params.points);
@@ -83,8 +85,11 @@ _leaflet2.default.Polyline.include({
8385
// delete LatLngs, but not remove polyline.
8486
removePosition: function removePosition() {
8587
this._play = false;
88+
this._now = 0;
89+
this._forward = 0;
8690
this._snakingTime = 0;
8791
this._snakingDistance = 0;
92+
this._snakingVertices = 0;
8893
this._snaking = false;
8994
this._path.style.display = "none";
9095
this.setLatLngs([this._snakeLatLngs[0], this._snakeLatLngs[0]]);
@@ -327,7 +332,7 @@ _leaflet2.default.LayerGroup.include({
327332
},
328333

329334
// Is is progress for mode progressFormat === "distance"
330-
procentProgress: function procentProgress(e, point, progress) {
335+
_procentProgress: function _procentProgress(e, point, progress) {
331336
var _this4 = this;
332337

333338
if (progress) {
@@ -368,7 +373,7 @@ _leaflet2.default.LayerGroup.include({
368373
var self = this;
369374
this._latLngAnimation = function (point, progress) {
370375
if (self._options.progressFormat === "distance") {
371-
self.procentProgress(events.fly, point, progress);
376+
self._procentProgress(events.fly, point, progress);
372377
} else events.fly(point);
373378
};
374379
}
@@ -383,17 +388,37 @@ _leaflet2.default.LayerGroup.include({
383388
}
384389
this.clearLayers();
385390
this._detailDistance = this._detailData.map(function (polyline) {
386-
return polyline.reduce(function (result, point, index) {
387-
if (polyline[index + 1]) {
388-
result = result + _leaflet2.default.latLng(point).distanceTo(polyline[index + 1]);
389-
}
390-
return result;
391-
}, 0);
391+
return (0, _index.getDistance)(polyline);
392392
});
393-
return this._snakeNext();
393+
if (this._options.startPosition) {
394+
this._initiateStartPosition();
395+
} else {
396+
return this._snakeNext();
397+
}
398+
},
399+
400+
_initiateStartPosition: function _initiateStartPosition() {
401+
if (this._options.startPosition === "full") {
402+
if (this._options.progressFormat === "default") {
403+
this.changePosition(this._originalLatlngs.length - 1);
404+
} else if (this._options.progressFormat === "distance") {
405+
var max = this._detailDistance.reduce(function (result, item) {
406+
result = result + item;
407+
return result;
408+
}, 0);
409+
this.changePosition(max);
410+
} else if (this._options.progressFormat === "time") {
411+
this.changePosition(this._originalLatlngs[this._originalLatlngs.length - 1].t);
412+
}
413+
this._end(true);
414+
} else {
415+
this.changePosition(this._options.startPosition);
416+
this.snakePlay();
417+
}
394418
},
395419

396420
_snakeNext: function _snakeNext() {
421+
console.log(this);
397422
if (this._snakingLayersDone >= this._snakingLayers.length) {
398423
this._end(true);
399424
this._snaking = false;
@@ -405,5 +430,23 @@ _leaflet2.default.LayerGroup.include({
405430
this.addLayer(currentLayer);
406431
currentLayer.snakeIn(this._latLngAnimation);
407432
} else currentLayer.snakePlay();
433+
},
434+
435+
addPolyline: function addPolyline(layers, detail) {
436+
var _this5 = this;
437+
438+
var prevRange = this._snakingLayers.length;
439+
layers.map(function (item, index) {
440+
_this5.addLayer(item);
441+
_this5._detailData.push(detail[index]);
442+
_this5._detailDistance.push((0, _index.getDistance)(detail[index]));
443+
_this5._snakingLayers.push(item);
444+
_this5._snakingLayers[prevRange + index].initDefaultPosition({
445+
animate: _this5._latLngAnimation,
446+
points: item
447+
});
448+
_this5._snakingLayers[prevRange + index].removePosition();
449+
});
450+
this.snakePlay();
408451
}
409452
});

src/App.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,20 @@ import React, { Component } from "react";
22
import "./App.css";
33
import LeafletReactTrackPlayer from "components/laeflet-react-track-player";
44
import demo from "./demo";
5-
import demo2 from "./demo2";
65
import { Map, TileLayer } from "react-leaflet";
76

87
class App extends Component {
98
state = {
109
lat: 47.445745,
1110
lng: 40.272891666666666,
1211
zoom: 14,
13-
type: "time",
12+
type: "distance",
1413
demo: demo
1514
};
1615
render() {
1716
const position = [demo[demo.length - 1].lat, demo[demo.length - 1].lng];
1817
return (
1918
<div className="App">
20-
<button onClick={() => this.setState({demo: demo2})}>add</button>
2119
<Map center={position} zoom={this.state.zoom}>
2220
<LeafletReactTrackPlayer
2321
track={this.state.demo}
@@ -31,9 +29,9 @@ class App extends Component {
3129
{ color: "#D10B41" },
3230
{ color: "#78c800" }
3331
]}
32+
useControl={true}
3433
progressFormat={this.state.type}
3534
customMarker={true}
36-
startPosition={"full"}
3735
streamData={true}
3836
changeCourseCustomMarker={true}
3937
markerIcon={"/img/mech.svg"}

0 commit comments

Comments
 (0)