Let me first explain what i am trying to do: Every 30 seconds i get array of gps points(lat, lng). These points represent a route along which i must move a maker, i'm trying to do it simply by moving a marker from point1 to point2 , then from point2 to point3 and so on. And then when i receive a new array of points i start doing this again. It is guaranteed that the last point of previous array and the first point of current array are the same. This means that routes are connected and each route is a part of one Big Route, which is divided into smaller routes and these smaller routes are sent to me in an order. (If last sentence was too difficult to understand please ignore it, it's not necessary to understand it).
How i implement it
Here as a code: (it's not full, i wrote it as close to my code and as brief as it is possible)
var api = // setting api here..
var marker = L.Marker.movingMarker(
[[0,0],[0,0]],
[0],
{ icon: icons.chosen });
var myPlugin = function(api, marker) {
this._api = api;
this._marker = api;
var that = this.
this._api.on('receive', function(points) { // receiving points here
that.moveMarker(points, 2000);
});
}
myPlugin.prototype.moveMarker = function(points, interval) {
this._marker.initialize(points, interval);
this._marker.start();
}
MyPlugin = new myPlugin(api,marker);
And finally my problem
What happens each time we receive points:
Marker moves as it is supposed to move(from point1 to point2, from point2 to point3 and so on to the last point. Then we wait to receive new points)
We recieved new points.(Cool!). Marker moves correctly, in a correct order, but when it reaches the last point it for some (unclear to me) reasons moves to the first point again and starts moving from point1 to point2, from point2 to point3 and so on. It does a laps. But only twice!
Okay, we received points again and our marker again does laps, 3 laps this time.
We received points again, and our marker does 4 laps...
...And when we receive points for twentieth time our marker does 20 laps. ## Why?
Even though loop option of marker if set to false by default, i tried setting loop option of marker to false manually, this didn't help.
Thanks for spending your valuable time on reading this and helping me!
Let me first explain what i am trying to do: Every 30 seconds i get array of gps points(lat, lng). These points represent a route along which i must move a maker, i'm trying to do it simply by moving a marker from point1 to point2 , then from point2 to point3 and so on. And then when i receive a new array of points i start doing this again. It is guaranteed that the last point of previous array and the first point of current array are the same. This means that routes are connected and each route is a part of one Big Route, which is divided into smaller routes and these smaller routes are sent to me in an order. (If last sentence was too difficult to understand please ignore it, it's not necessary to understand it). How i implement it Here as a code: (it's not full, i wrote it as close to my code and as brief as it is possible)
And finally my problem What happens each time we receive points:
...And when we receive points for twentieth time our marker does 20 laps. ## Why? Even though loop option of marker if set to false by default, i tried setting loop option of marker to false manually, this didn't help.
Thanks for spending your valuable time on reading this and helping me!