示例#1
0
        private async void cmdRoute_Click(object sender, RoutedEventArgs e)
        {
            checkBoxMapSource.IsChecked = false;
            checkBoxMapTarget.IsChecked = false;

            SetHighwayFilter();

            List <int> nodeList = new List <int>();

            if (nodeSourceId != 0)
            {
                nodeList.Add(nodeSourceId);
            }
            for (int i = 0; i < dtGridRoute.Items.Count; i++)
            {
                OsmRouteData DetailData = ((List <OsmRouteData>)dtGridRoute.ItemsSource)[i];
                if (DetailData.NodeId != 0)
                {
                    nodeList.Add(DetailData.NodeId);
                }
            }
            if (nodeTargetId != 0)
            {
                nodeList.Add(nodeTargetId);
            }



            //            typRoute RoadRoute = UserSession.ClientSideObject.m_GameManagerProxy.GetRoadsRoute(pntSource.X, pntSource.Y, pntTarget.X, pntTarget.Y);
            enOSMhighwayFilter[] arrHighwayFilter = new enOSMhighwayFilter[1];
            arrHighwayFilter[0] = highwayFilter;


            shPath Path = await clsRoadRoutingWebApi.FindShortPathWithArrayNodes("0", nodeList.ToArray(), arrHighwayFilter);

            m_PolygonPnts.Clear();
            if (Path != null && Path.Points != null)
            {
                for (int i = 0; i < Path.Points.Count; i++)
                {
                    DPoint Dpnt = new DPoint();
                    Dpnt.X = Path.Points[i].x;
                    Dpnt.Y = Path.Points[i].y;
                    m_PolygonPnts.Add(Dpnt);
                }
            }



            VMMainViewModel.Instance.InvalidateVisual();
        }
示例#2
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;
            }
        }