none
How to delete each polyline

    Question

  • Hi everyone, I have multiple polylines on Bing Map. Now I want to delete the chosen one by using QR code, but it didn't work. It only deletes from the 1st to the last in the order of creation. Do you know how I can resolve this? Thanks a lot.

    Here is my code:

    private void MapWithPushpins_TouchDown(object sender, TouchEventArgs e)
            {
    if (e.TouchDevice.GetTagData().Value == 7)
                { 
                    foreach (MapPolyline polyline in FindVisualChildren<MapPolyline>(MainMap))
                    {
                        for (int i = 0; i < polyline.Locations.Count; i++)
                        {
                            var point = polyline.Locations.ElementAt(i);
                            if (Math.Abs(pinLocation.Latitude - point.Latitude) < 0.5 && Math.Abs(pinLocation.Longitude - point.Longitude) < 0.5)
                            {
                                MainMap.Children.Remove(polyline);
    return;
                            }
                        }
    
                       }
                            
                        
                        
                    }
    
    

    Friday, October 25, 2013 4:49 PM

Answers

  • If you simply want to delete a polyline if it is tapped/clicked then there is no need to go through all the data points. The sender object to the event handler should be the polyline. Simply use that with the remove method. You may need to cast the sender object to a polyline. Do something like this:

    private void MapWithPushpins_TouchDown(object sender, TouchEventArgs e)
    {
    	if(sender is MapPolyline)
    	{
    		var line = sender as MapPolyline;
    		MainMap.Children.Remove(line);
    	}
    }

    http://rbrundritt.wordpress.com

    Monday, October 28, 2013 8:57 AM
    Owner

All replies

  • Can you provide more details. It's not clear what you are trying to do. Do you want to delete a polyline or just points from a polyline? How are using a QR code with your app?

    http://rbrundritt.wordpress.com

    Friday, October 25, 2013 5:33 PM
    Owner
  • For example, I drew 3 polylines on the map. Now I want to delete the 2nd polyline, but the 1st polyline is deleted rather than the second one. The same thing will happen if I want to delete the 3rd polyline. I want to delete the whole polyline, not just points from a polyline. The way to use a QR code is just using this line "e.TouchDevice.GetTagData().Value == 7". Do you know how I can delete the polyline I want? Thanks.
    Saturday, October 26, 2013 6:15 AM
  • If you have an index for the polyline, then use the RemoveAt method on the Children property of the map.

    If you need to see if a polyline matches another one, loop through all the coordinates in it and check if they are the same. If they are then remove that one polyline from the map. The way your code is it looks like you are only looking at each coordinate and if any one match your deleting the polyline. If two of your lines have the same coordinate then this would remove the first line.


    http://rbrundritt.wordpress.com

    Sunday, October 27, 2013 1:15 PM
    Owner
  • I think you misunderstand my way. I want to delete the polyline when I touch that polyline. That's why I need to get the touch position and compare it with each coordinate of each polyline, and if any coordinate in a polyline matches with the touch position, that polyline will be deleted. And I'm stuck at this point. Do you know why my code doesn't work?
    Monday, October 28, 2013 3:36 AM
  • If you simply want to delete a polyline if it is tapped/clicked then there is no need to go through all the data points. The sender object to the event handler should be the polyline. Simply use that with the remove method. You may need to cast the sender object to a polyline. Do something like this:

    private void MapWithPushpins_TouchDown(object sender, TouchEventArgs e)
    {
    	if(sender is MapPolyline)
    	{
    		var line = sender as MapPolyline;
    		MainMap.Children.Remove(line);
    	}
    }

    http://rbrundritt.wordpress.com

    Monday, October 28, 2013 8:57 AM
    Owner
  • Thank you so much. It works!
    Monday, October 28, 2013 3:58 PM