I have a code that draws an itinerary on an svg element in a function.
I need when i Recall this function, the last element will be removed and a new one will be drawn.
I've used the remove() function of snap but it doesn't work.
Here is my code:
function tracingitinerarysnap(table_shortest_way,table1){
var x1,y1,y2,x2,tempPoint, myLen;
var element;
var k=0;
var trace=0;
var array=[]; //un tableau intermédiaire pour convertir les chaines de caractères en Objets.
for(var i=0;i<table_shortest_way.length;i++){
for ( var j=0;j<table1.length;j++) {
if (table_shortest_way[i]== table1[j][0])
{ array.push(table1[j]);
}
}
}
if(k!=0)
{
s.remove(element);
}
while(trace<array.length-1)
{
x1= array[trace][1];
y1= array[trace][2];
x2= array[trace+1][1];
y2= array[trace+1][2];
var y=y1-2;
var x=x1-2;
var y3=y2-3;
var x3=x2-3;
myLine =s.path( 'M'+x+','+y+'L'+x3+','+y3);
trace+=1;
myLen = myLine.getTotalLength();
for( var a=0; a< myLen-1; a+=10 ) {
tempPoint = myLine.getPointAtLength( a );
dessin=s.text(tempPoint.x, tempPoint.y+8, '<').transform( 'r' + tempPoint.alpha ).attr({ strokeWidth: 1, stroke: "#FF0000"});
}
}
k++;
}
so when we execute this function next time k will be equal to 1 and then it is different from zero. So it will delete the previous one and will draw a new itinerary with a new value of table_shortest_way.
Can anyone help me with that?
Thank you.