Example #1
0
 async void miAddBarier_Click(object sender, RoutedEventArgs e)
 {
     // add a police barrier in the closest route
     DPoint             coordinates   = (DPoint)((System.Windows.Controls.MenuItem)sender).Tag;
     enOSMhighwayFilter highwayFilter = enOSMhighwayFilter.Undefined;
     shPointId          PointId       = await clsRoadRoutingWebApi.GetNearestPointIdOnRoad("0", highwayFilter, coordinates.X, coordinates.Y);
 }
Example #2
0
        public static async Task <shPointId> GetNearestPointIdOnRoad(string ScenarioId, enOSMhighwayFilter highwayFilter, double x, double y)
        {
            try
            {
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(BaseAddress);
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                    string strUri = "api/Routing/GetNearestPointIdOnRoad?ScenarioId=" + ScenarioId + "&highwayFilter=" + (int)highwayFilter + "&x=" + x + "&y=" + y;
                    HttpResponseMessage response = await client.GetAsync(strUri);

                    if (response.StatusCode != System.Net.HttpStatusCode.OK)
                    {
                        return(null);
                    }

                    HttpContent content = response.Content;
                    string      v       = await content.ReadAsStringAsync();

                    shPointId tmp = JsonConvert.DeserializeObject <shPointId>(v);
                    return(tmp);
                }
            }
            catch (Exception ex)
            {
            }
            return(null);
        }
Example #3
0
        protected async override void OnDrop(System.Windows.DragEventArgs e)
        {
            double currMapX = 0;
            double currMapY = 0;

            System.Windows.DataObject d = (System.Windows.DataObject)e.Data;

            string[] dataFormats = d.GetFormats();
            string   dataText    = d.GetText();

            Point position = e.GetPosition(this);

            GMap.NET.PointLatLng curPosition = FromLocalToLatLng((int)position.X, (int)position.Y);
            currMapX = curPosition.Lng;
            currMapY = curPosition.Lat;

            for (int i = 0; i < dataFormats.Length; i++)
            {
                string dragFormat = dataFormats[i];

                if (dragFormat.Contains("FormationTree") && dataText == "Actor")
                {
                    object dragObject = d.GetData(dragFormat);

                    FormationTree formation = dragObject as FormationTree;
                    if (formation == null)
                    {
                        continue;
                    }

                    enOSMhighwayFilter highwayFilter = enOSMhighwayFilter.Undefined;
                    SetHighwayFilter(highwayFilter);
                    shPointId PointId = await clsRoadRoutingWebApi.GetNearestPointIdOnRoad("0", highwayFilter, currMapX, currMapY);

                    if (PointId != null)
                    {
                        shPoint           pnt             = PointId.point;
                        DeployedFormation deployFormation = new DeployedFormation();
                        deployFormation.x         = pnt.x;
                        deployFormation.y         = pnt.y;
                        deployFormation.formation = formation;

                        AtomData atom = await TDSClient.SAGInterface.SAGSignalR.DeployFormationFromTree(VMMainViewModel.Instance.SimulationHubProxy, deployFormation);

                        if (atom != null)
                        {
                            AtomDeployedEventArgs args = new AtomDeployedEventArgs();
                            args.atom = atom;
                            if (AtomDeployedEvent != null)
                            {
                                AtomDeployedEvent(this, args);
                            }
                        }
                    }

                    return;
                }
            }
        }
Example #4
0
        internal async void NotifyMouseLeftClickOnMapEvent(MapMouseEventArgsWPF args)
        {
            double currMapX = args.MapXLongLatWGS84;
            double currMapY = args.MapYLongLatWGS84;


            switch (CurrMapTool)
            {
            case enMapTool.MoveObjectTool:
                CurrMapTool = enMapTool.DefautMapTool;

                enOSMhighwayFilter highwayFilter = enOSMhighwayFilter.Undefined;
                highwayFilter = highwayFilter | enOSMhighwayFilter.CarMostImportant;
                highwayFilter = highwayFilter | enOSMhighwayFilter.CarMediumImportant;
                highwayFilter = highwayFilter | enOSMhighwayFilter.CarLowImportant;
                highwayFilter = highwayFilter | enOSMhighwayFilter.Construction;

                shPointId PointId = await clsRoadRoutingWebApi.GetNearestPointIdOnRoad("0", highwayFilter, currMapX, currMapY);

                if (PointId != null)
                {
                    shPoint           pnt             = PointId.point;
                    DeployedFormation deployFormation = new DeployedFormation();
                    deployFormation.x = pnt.x;
                    deployFormation.y = pnt.y;

                    deployFormation.formation = new FormationTree();
                    deployFormation.formation.Identification = MoveObjectCommonProperty.AtomName;
                    deployFormation.formation.GUID           = MoveObjectCommonProperty.GUID;


                    // deployFormation.formation = formation;

                    await TDSClient.SAGInterface.SAGSignalR.MoveGroundObject(VMMainViewModel.Instance.SimulationHubProxy, deployFormation);
                }


                break;
            }



            if (dlgMouseLeftClickOnMapEvent == null)
            {
                return;
            }

            System.Delegate[] invklist = dlgMouseLeftClickOnMapEvent.GetInvocationList();
            IEnumerator       ie       = invklist.GetEnumerator();

            while (ie.MoveNext())
            {
                MouseLeftClickOnMapEventWPF handler = (MouseLeftClickOnMapEventWPF)ie.Current;
                try
                {
                    {
                        // IAsyncResult ar = handler.BeginInvoke(this,args, null, null);
                        // handler.EndInvoke(ar);

                        handler.Invoke(this, args);
                    }
                }
                catch (System.Exception e)
                //catch
                {
                    dlgMouseLeftClickOnMapEvent -= handler;
                }
            }
        }