Open klederson opened 8 years ago
By the way i know i can preserve the sequence by changing my code, the purpose of this bug is to explict that exists and it's wrong
By the way if anyone is interested the fix ( in my case ) to keep the sequence but keep the objects separated by type in my directive is the following.
getPolygons: function(mapName) {
var objects = service._getDriverObjectsData(mapName);
var response = [];
var allowed = ["circles" , "lines", "polygons"];
for(var i in objects) {
if(allowed.indexOf(i) > -1) {
response = response.concat(objects[i]);
}
}
//@see https://github.com/tombatossals/angular-leaflet-directive/issues/1047
var sorter = function(a,b) {
if (a._timestamp < b._timestamp)
return -1;
else if (a._timestamp > b._timestamp)
return 1;
else
return 0;
};
response.sort(sorter);
return response;
},
Note that the same approach can be used inside the directive to avoid this kind of workarround...
My suggestion is to put a timestamp in each object ( in the angular-leaflet-directive core ) so the user does not have to handle this order.
I had to create a system that refresh the objects from a map (will not explain the reason and I know that reload all paths can be heavy)...
Anyway this adapter separate everything like this:
Then in the time to generate a unique paths object i do something similar to this:
So in the end what happen is if i keep adding elements in the order:
BUT if i follow that sequence and than try to add any line or circle i get:
Same happens if i start adding a polygon and try to add a line or circle and also the same happens if i add a circle and try to add a line ( in that sequence ) so this is the scenario:
ONE of my theories is that happens because in the parse algorithm it changes the sequence from the directive ( example: in a case that in the array of paths index 1 was a circle ... now it became a line and the parse get the error when i "refresh" the paths object ).
Following attached a small video from what I just said:
https://www.dropbox.com/s/3fj93xni6hz0d2l/leaflet-directive-bug.mov?dl=0