Esempio n. 1
0
        public async void MapOnClick(object sender, MapMouseEventArgsWPF e)
        {
            if (checkBoxMapReferencePoint.IsChecked == true && string.IsNullOrEmpty(txtRoute.Text) == false)
            {
                txtReferenceX.Tag = null;
                referencePoint    = new DPoint();


                DPoint Dpnt = new DPoint();
                Dpnt.X = e.MapXLongLatWGS84;
                Dpnt.Y = e.MapYLongLatWGS84;

                Route route = await SAGSignalR.GetRouteByName(VMMainViewModel.Instance.SimulationHubProxy, txtRoute.Text);

                ActivityRoute = route;
                if (route != null)
                {
                    double minDist   = double.MaxValue;
                    DPoint minDpoint = new DPoint();
                    int    leg       = 0;
                    int    i         = -1;
                    foreach (DPoint dpoint in route.Points)
                    {
                        i++;
                        double dist = Utilites.GreatCircleDistance(Dpnt.X, Dpnt.Y, dpoint.X, dpoint.Y);
                        if (dist < minDist)
                        {
                            minDist   = dist;
                            minDpoint = dpoint;
                            leg       = i;
                        }
                    }



                    float NearestIndex = 0;
                    // shPoint[] shPoints = Utilites.Convert2shPoint(route.Points);

                    shPoint pnt = new shPoint(minDpoint.X, minDpoint.Y);


                    //shPoint pnt = TerrainService.MathEngine.ReturnNearestPointOnPolygonBorder(Dpnt.X, Dpnt.Y, shPoints, out  NearestIndex);
                    if (pnt.x != 0.0 && pnt.y != 0.0)
                    {
                        referencePoint = new DPoint(pnt.x, pnt.y);
                    }


                    double aXOut = 0;
                    double aYOut = 0;

                    aXOut = Math.Round(pnt.x, 3);
                    aYOut = Math.Round(pnt.y, 3);

                    txtReferenceX.Content = aXOut.ToString();
                    txtReferenceY.Content = aYOut.ToString();

                    txtReferenceX.Tag = pnt.x;
                    txtReferenceY.Tag = pnt.y;


                    shPath Path = await clsRoadRoutingWebApi.FindShortPath("0", AtomCommonProperty.X, AtomCommonProperty.Y, pnt.x, pnt.y, false);


                    {
                        ReferenceRoute        = new Route();
                        ReferenceRoute.Points = Utilites.Convert2DPoint(Path.Points);

                        VMMainViewModel.Instance.InvalidateVisual();
                    }
                }



                checkBoxMapReferencePoint.IsChecked = false;
            }
        }