private void mapItemButton_Click(object sender, RoutedEventArgs e) { var mapItemButton = sender as Button; PointOfCustomRoute currMapItem = mapItemButton?.DataContext as PointOfCustomRoute; if (currMapItem != null) { int ind = MyMapVM.PointList.IndexOf(currMapItem); MyMapVM.PointList.RemoveAt(ind); if (ind == 0) { myMap.MapElements.Remove(_lastPolyline); MyMapVM.PointList.Clear(); MyMapVM.IsRouting = false; return; } DrawPolyline(); if (ind != MyMapVM.PointList.Count) { double delta = MyMapVM.PointList[ind].CurrentLenght - MyMapVM.PointList[ind - 1].CurrentLenght - PointOfCustomRoute.GetDistance(MyMapVM.PointList[ind], MyMapVM.PointList[ind - 1]); for (int i = ind; i < MyMapVM.PointList.Count; i++) { MyMapVM.PointList[i].CurrentLenght -= delta; } } } }
public static double GetDistance(PointOfCustomRoute p1, PointOfCustomRoute p2) { //Y=atan{sqrt(a+(b-c)^2)/(d+e)} double lat1 = p1.Location.Position.Latitude * Math.PI / 180; double long1 = p1.Location.Position.Longitude * Math.PI / 180; double lat2 = p2.Location.Position.Latitude * Math.PI / 180; double long2 = p2.Location.Position.Longitude * Math.PI / 180; double a = Math.Pow(Math.Cos(lat2) * Math.Sin(long2 - long1), 2); double b = Math.Cos(lat1) * Math.Sin(lat2); double c = Math.Sin(lat1) * Math.Cos(lat2) * Math.Cos(long2 - long1); double d = Math.Sin(lat1) * Math.Sin(lat2); double e = Math.Cos(lat1) * Math.Cos(lat2) * Math.Cos(long2 - long1); double Y = Math.Atan(Math.Sqrt(a + Math.Pow(b - c, 2)) / (d + e)); return(RADIUS_EARTH * Y / 1000); }
private void myMap_MapTapped(MapControl sender, MapInputEventArgs args) { if (MyMapVM.IsRouting) { Debug.WriteLine(String.Format(args.Location.Position.Latitude + " " + args.Location.Position.Longitude)); PointOfCustomRoute currPoint = new PointOfCustomRoute() { Location = args.Location, NormalizedAnchorPoint = new Point(0.5, 0.93) }; if (MyMapVM.PointList.Count != 0) { currPoint.CurrentLenght = MyMapVM.PointList.Last().CurrentLenght + PointOfCustomRoute.GetDistance(MyMapVM.PointList.Last(), currPoint); } MyMapVM.PointList.Add(currPoint); DrawPolyline(); } }