Exemple #1
0
        void MapOnRightClickWPF(object sender, MapMouseEventArgsWPF e)
        {
            double SearchRadius = 2000;
            double SearchNeiborRadiuse = 200;

            double minDistance = double.MaxValue;
            structTransportCommonProperty minDistAtom = null;
            List<structTransportCommonProperty> NeighborList = new List<structTransportCommonProperty>();



            double resolution = 0;
            double zoom = VMMainViewModel.Instance.MyMainMap.Zoom;
            //* Math.Cos(TerrainService.MathEngine.DegreesToRadians(e.MapYLongLatWGS84))
            resolution = (156543) / Math.Pow(2, zoom);

            SearchNeiborRadiuse = resolution * 10;



            System.Windows.Application.Current.MainWindow.ContextMenu = null;

         //  System.Windows.Controls.ContextMenu contextmenu = new System.Windows.Controls.ContextMenu();

          //  if (VMMainViewModel.Instance.currSelectionType == enSelection.Ground)
            {
                minDistance = double.MaxValue;
                if (VMMainViewModel.Instance.colGroundAtoms != null)
                {
                    foreach (structTransportCommonProperty Tr in VMMainViewModel.Instance.colGroundAtoms.Values)
                    {


                       double Distance = Utilites.GreatCircleDistance(Tr.X, Tr.Y, e.MapXLongLatWGS84, e.MapYLongLatWGS84);

                       if (Distance < minDistance && Distance > 0)
                        {
                            minDistance = Distance;
                            minDistAtom = Tr;
                        }
                    }


                }

            }

            SelectMenu = new System.Windows.Controls.ContextMenu();

            SelectMenu.Style = null;

            DPoint coordinates = new DPoint(e.MapXLongLatWGS84, e.MapYLongLatWGS84);

            // add menu item for adding barriers
            System.Windows.Controls.MenuItem mBarrier = new System.Windows.Controls.MenuItem();
            mBarrier.Header = "Add Barrier";
            mBarrier.Tag = coordinates;
            mBarrier.Click += miAddBarier_Click;
            SelectMenu.Items.Add(mBarrier);

            System.Windows.Controls.MenuItem mCoordinates = new System.Windows.Controls.MenuItem();
            mCoordinates.Header = e.MapXLongLatWGS84.ToString() + " " + e.MapYLongLatWGS84.ToString();
            mCoordinates.Tag = coordinates;
            mCoordinates.Click += miCoordinates_Click;
            SelectMenu.Items.Add(mCoordinates);
            System.Windows.Application.Current.MainWindow.ContextMenu = SelectMenu;

            //if (minDistAtom != null && minDistance < SearchRadius)
            // {
            //    //Create PopUP menu
            //     if (minDistAtom.AtomClass == "TDSServer.GroundTask.clsGroundAtom")
            //     {

            //         foreach (structTransportCommonProperty Tr in VMMainViewModel.Instance.colGroundAtoms.Values)
            //         {
            //             double  Distance = TerrainService.MathEngine.CalcDistanceForPerformance(Tr.X, Tr.Y, minDistAtom.X, minDistAtom.Y);
            //             if (Distance <= SearchNeiborRadiuse)
            //             {
            //                 NeighborList.Add(Tr);

            //             }
            //         }

            //         if (NeighborList.Count==1)
            //         {
            //             ShowGroundSelectAtomMenu(null, minDistAtom);
            //         }
            //         else
            //         {
            //           // System.Windows.Controls.ContextMenu SelectMenu = new System.Windows.Controls.ContextMenu();
            //             SelectMenu = new System.Windows.Controls.ContextMenu();

            //            SelectMenu.Style = null;
                       
            //             for (int i = 0; i < NeighborList.Count; i++)
            //             {
            //                // System.Windows.Controls.MenuItem mSelectGroundAtom = new System.Windows.Controls.MenuItem();
            //                // mSelectGroundAtom.Style = null;

            //                 System.Windows.Controls.MenuItem mSelectGroundAtom = new System.Windows.Controls.MenuItem();
            //                 mSelectGroundAtom.Header =  NeighborList[i].AtomName;
            //                 mSelectGroundAtom.Tag = NeighborList[i];
            //                 mSelectGroundAtom.Focusable = false;
            //                 mSelectGroundAtom.Click += miName_Click;
            //                 SelectMenu.Items.Add(mSelectGroundAtom);
            //             }

            //             System.Windows.Application.Current.MainWindow.ContextMenu = SelectMenu;
            //             return;
            //         }





            //     }
            // }
           
        }
        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);
                 }
             }



             //typRoute RoadRoute = UserSession.ClientSideObject.m_GameManagerProxy.GetRoadsRouteWithArrayNodes(nodeList.ToArray(), arrHighwayFilter);          
                       
             //m_PolygonPnts.Clear();
             //if (RoadRoute != null && RoadRoute.arr_legs.Length>0)
             //{

             //    m_PolygonPnts.Clear();

             //    typLegSector leg0 = RoadRoute.arr_legs[0];
             //    DPoint Dpnt0 = new DPoint();
             //    Dpnt0.X = leg0.FromLongn;
             //    Dpnt0.Y = leg0.FromLatn;
             //    m_PolygonPnts.Add(Dpnt0);


             //    for (int i = 0; i < RoadRoute.arr_legs.Length; i++)
             //    {
             //        typLegSector leg = RoadRoute.arr_legs[i];
             //        DPoint Dpnt = new DPoint();
             //        Dpnt.X = leg.ToLongn;
             //        Dpnt.Y = leg.ToLatn;
             //        m_PolygonPnts.Add(Dpnt);
             //    }

             //  //  UserSession.ClientSideObject.InvalidateVisual();
             //}

             VMMainViewModel.Instance.InvalidateVisual();
        }
Exemple #3
0
        void MapOnRightClickWPF(object sender, MapMouseEventArgsWPF e)
        {
            double SearchRadius        = 2000;
            double SearchNeiborRadiuse = 200;

            double minDistance = double.MaxValue;
            structTransportCommonProperty        minDistAtom  = null;
            List <structTransportCommonProperty> NeighborList = new List <structTransportCommonProperty>();



            double resolution = 0;
            double zoom       = VMMainViewModel.Instance.MyMainMap.Zoom;

            //* Math.Cos(TerrainService.MathEngine.DegreesToRadians(e.MapYLongLatWGS84))
            resolution = (156543) / Math.Pow(2, zoom);

            SearchNeiborRadiuse = resolution * 10;



            System.Windows.Application.Current.MainWindow.ContextMenu = null;

            //  System.Windows.Controls.ContextMenu contextmenu = new System.Windows.Controls.ContextMenu();

            //  if (VMMainViewModel.Instance.currSelectionType == enSelection.Ground)
            {
                minDistance = double.MaxValue;
                if (VMMainViewModel.Instance.colGroundAtoms != null)
                {
                    foreach (structTransportCommonProperty Tr in VMMainViewModel.Instance.colGroundAtoms.Values)
                    {
                        double Distance = Utilites.GreatCircleDistance(Tr.X, Tr.Y, e.MapXLongLatWGS84, e.MapYLongLatWGS84);

                        if (Distance < minDistance && Distance > 0)
                        {
                            minDistance = Distance;
                            minDistAtom = Tr;
                        }
                    }
                }
            }

            SelectMenu = new System.Windows.Controls.ContextMenu();

            SelectMenu.Style = null;

            DPoint coordinates = new DPoint(e.MapXLongLatWGS84, e.MapYLongLatWGS84);

            // add menu item for adding barriers
            System.Windows.Controls.MenuItem mBarrier = new System.Windows.Controls.MenuItem();
            mBarrier.Header = "Add Barrier";
            mBarrier.Tag    = coordinates;
            mBarrier.Click += miAddBarier_Click;
            SelectMenu.Items.Add(mBarrier);

            System.Windows.Controls.MenuItem mCoordinates = new System.Windows.Controls.MenuItem();
            mCoordinates.Header = e.MapXLongLatWGS84.ToString() + " " + e.MapYLongLatWGS84.ToString();
            mCoordinates.Tag    = coordinates;
            mCoordinates.Click += miCoordinates_Click;
            SelectMenu.Items.Add(mCoordinates);
            System.Windows.Application.Current.MainWindow.ContextMenu = SelectMenu;

            if (minDistAtom != null && minDistance < SearchRadius)
            {
                //Create PopUP menu
                if (minDistAtom.AtomClass == "TDSServer.GroundTask.clsGroundAtom")
                {
                    foreach (structTransportCommonProperty Tr in VMMainViewModel.Instance.colGroundAtoms.Values)
                    {
                        double Distance = TerrainService.MathEngine.CalcDistanceForPerformance(Tr.X, Tr.Y, minDistAtom.X, minDistAtom.Y);
                        if (Distance <= SearchNeiborRadiuse)
                        {
                            NeighborList.Add(Tr);
                        }
                    }

                    if (NeighborList.Count == 1)
                    {
                        ShowGroundSelectAtomMenu(null, minDistAtom);
                    }
                    else
                    {
                        // System.Windows.Controls.ContextMenu SelectMenu = new System.Windows.Controls.ContextMenu();
                        SelectMenu = new System.Windows.Controls.ContextMenu();

                        SelectMenu.Style = null;

                        for (int i = 0; i < NeighborList.Count; i++)
                        {
                            // System.Windows.Controls.MenuItem mSelectGroundAtom = new System.Windows.Controls.MenuItem();
                            // mSelectGroundAtom.Style = null;

                            System.Windows.Controls.MenuItem mSelectGroundAtom = new System.Windows.Controls.MenuItem();
                            mSelectGroundAtom.Header    = NeighborList[i].AtomName;
                            mSelectGroundAtom.Tag       = NeighborList[i];
                            mSelectGroundAtom.Focusable = false;
                            mSelectGroundAtom.Click    += miName_Click;
                            SelectMenu.Items.Add(mSelectGroundAtom);
                        }

                        System.Windows.Application.Current.MainWindow.ContextMenu = SelectMenu;
                        return;
                    }
                }
            }
        }
        public async void MapOnClick(object sender, MapMouseEventArgsWPF e)
        {
             try
             {
                 SetHighwayFilter();

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

                 if (checkBoxMapSource.IsChecked == true)
                 {

                     checkBoxMapSource.IsChecked = false;

                     shPoint pnt = new shPoint();
                     int nodeid = 0;

                     shPointId PointId = await clsRoadRoutingWebApi.GetNearestPointIdOnRoad("0", highwayFilter, Dpnt.X, Dpnt.Y);

                     if (PointId!=null)
                     {
                         pnt = PointId.point;
                         nodeid = PointId.nodeId;

                         if (pnt.x != 0 || pnt.y != 0)
                         {
                             pntSource.X = pnt.x;
                             pntSource.Y = pnt.y;
                             nodeSourceId = nodeid;
                             txtSourceX.Text = Math.Round(pntSource.X, 4).ToString();
                             txtSourceY.Text = Math.Round(pntSource.Y, 4).ToString();

                         }
                     }


                   

                     
                     //////string err = UserSession.ClientSideObject.m_GameManagerProxy.GetNearestPointIdOnRoad(out pnt,out nodeid,highwayFilter, Dpnt.X, Dpnt.Y);
                     //////if (string.IsNullOrEmpty(err) == false)
                     //////{
                     //////    err = KingsGameClientModel.Properties.Resources.strSpatialServicenotActive;
                     //////    ComponentsUtility.KGMsgBox.ShowCustomMsgOk(UserSession.GetParentWindow(this), err);
                     //////    return;
                     //////}
                     //////else
                     //////{                         
                     //////    if (pnt.x != 0 || pnt.y != 0)
                     //////    {
                     //////        pntSource.X = pnt.x;
                     //////        pntSource.Y = pnt.y;
                     //////        nodeSourceId = nodeid;
                     //////        txtSourceX.Text = Math.Round(pntSource.X, 4).ToString();
                     //////        txtSourceY.Text = Math.Round(pntSource.Y, 4).ToString();
                           
                     //////    }
                     //////    else
                     //////    {

                     //////    }
                     //////}
                    VMMainViewModel.Instance.InvalidateVisual();


                    
                 }
                 else if (checkBoxMapTarget.IsChecked == true)
                 {

                     checkBoxMapTarget.IsChecked = false;

                     shPoint pnt = new shPoint();                   
                     int nodeid = 0;

                     shPointId PointId = await clsRoadRoutingWebApi.GetNearestRoadNodeWithCondition("0", highwayFilter, Dpnt.X, Dpnt.Y, nodeSourceId, true);
                     if (PointId!=null)
                     {
                         pnt = PointId.point;
                         nodeid = PointId.nodeId;


                         //UserSession.ClientSideObject.m_GameManagerProxy.GetNearestPointOnRoadWithCondition(out pnt, out nodeid,highwayFilter, Dpnt.X, Dpnt.Y, nodeSourceId, true);


                         if (pnt.x != 0 || pnt.y != 0)
                         {
                             pntTarget.X = pnt.x;
                             pntTarget.Y = pnt.y;

                             txtTargetX.Text = Math.Round(pntTarget.X, 4).ToString();
                             txtTargetY.Text = Math.Round(pntTarget.Y, 4).ToString();
                             nodeTargetId = nodeid;
                         }
                         else
                         {

                         }

                     }


                         VMMainViewModel.Instance.InvalidateVisual();
                 }
                 else
                 {
                     for (int i = 0; i < dtGridRoute.Items.Count; i++)
                     {
                         OsmRouteData DetailData = ((List<OsmRouteData>)dtGridRoute.ItemsSource)[i];
                         if(DetailData.IsMapClick)
                         {
                             DetailData.IsMapClick = false;

                             shPoint pnt = new shPoint();
                           //  string err = UserSession.ClientSideObject.m_GameManagerProxy.GetNearestPointOnRoad(out pnt, Dpnt.X, Dpnt.Y);
                             int nSourceId = 0;
                             if(i==0)
                             {
                                 nSourceId = nodeSourceId;
                             }
                             else
                             {
                                 OsmRouteData prevDetailData = ((List<OsmRouteData>)dtGridRoute.ItemsSource)[i-1];
                                 nSourceId = prevDetailData.NodeId;
                             }

                             int nodeid = 0;


                             shPointId PointId = await clsRoadRoutingWebApi.GetNearestRoadNodeWithCondition("0", highwayFilter, Dpnt.X, Dpnt.Y, nSourceId, true);
                             if (PointId!=null)
                             {
                                 pnt = PointId.point;
                                 nodeid = PointId.nodeId;


                                 //  UserSession.ClientSideObject.m_GameManagerProxy.GetNearestPointOnRoadWithCondition(out pnt, out nodeid, highwayFilter, Dpnt.X, Dpnt.Y, nSourceId, true);


                                 if (pnt.x != 0 || pnt.y != 0)
                                 {
                                     DetailData.X = pnt.x;
                                     DetailData.Y = pnt.y;
                                     DetailData.NodeId = nodeid;

                                 }
                                 else
                                 {

                                 }
                             }

                            


                            VMMainViewModel.Instance.InvalidateVisual();
                         }
                     }
                 }
             }
            catch(Exception ex)
             {

             }
        }