0

How I can delete the polyline line between 2 specific marker. I have many polyline connected with many marker . But i want to delete any sspecific line on double click .

How Can I do that ?

I am using leaflet to draw the polyline. enter image description here

here suppose I want to delete the polyline between marker 3 and 4 on double click. what will be procedure to do that.

Thank you.

I tried something like this but its not working , Can anybody please help me where is the mistakes ?

//polyline delete on double click 

    for (var i = 0; i < $scope.polycoords.length; i++) {
        var polyline = $scope.polycoords[i];
        $scope.polycoords[i].on('click', function (e) {
        console.log("sdd",polyline._leaflet_id);
         for (var j = 0; j < $scope.polycoords.length; j++) {
            if($scope.polycoords[i]._leaflet_id = $scope.polycoords[j]._leaflet_id){
                  console.log($scope.polycoords[j])
                  var polyline = $scope.polycoords[j];
                      map.removeLayer(polyline);
               }


           }


     });
    }
upendra
  • 339
  • 4
  • 20

1 Answers1

1
polyline.on('dblclick', function (e) {
    map.removeLayer(this);
});

Edit
This is going to work because based on your other question here on SO, I know that you create a different polyline for each line. But for anyone else that creates a single polyline with all the coordinates together, this solution will delete the whole polyline, not just a part of it.

Roberto Soares
  • 244
  • 1
  • 11
  • It deleting only the last line. – upendra Aug 23 '17 at 08:41
  • You should put this solution after the creation of each polyline (if I remember correctly, inside that double loop that you have). You should post your sample code here too so others can understand. – Roberto Soares Aug 23 '17 at 08:43
  • [Sample code](https://stackoverflow.com/questions/45810267/marker-with-polyline-while-dragging-the-marker-using-leaflet) Here the sample code which I used to drag polyline with marker – upendra Aug 23 '17 at 08:53
  • Where are you attaching the event handler? It should be right after the creation of the polyline. Please provide the updated code with what you're trying to do. – Roberto Soares Aug 23 '17 at 09:57
  • thank you so much . It's working now. Thank you for your time. – upendra Aug 23 '17 at 10:11