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); }
public void SetHighwayFilter(enOSMhighwayFilter highwayFilter) { highwayFilter = highwayFilter | enOSMhighwayFilter.CarMostImportant; highwayFilter = highwayFilter | enOSMhighwayFilter.CarMediumImportant; highwayFilter = highwayFilter | enOSMhighwayFilter.CarLowImportant; highwayFilter = highwayFilter | enOSMhighwayFilter.Construction; }
public void SetHighwayFilter() { highwayFilter = enOSMhighwayFilter.Undefined; if ((bool)chkCarMostImportant.IsChecked) { highwayFilter = highwayFilter | enOSMhighwayFilter.CarMostImportant; } if (highwayFilter.HasFlag(enOSMhighwayFilter.Undefined) == true) { } // uint b = (uint)highwayFilter; if ((bool)chkCarMediumImportant.IsChecked) { highwayFilter = highwayFilter | enOSMhighwayFilter.CarMediumImportant; } if ((bool)chkCarLowImportant.IsChecked) { highwayFilter = highwayFilter | enOSMhighwayFilter.CarLowImportant; } if ((bool)chkConstruction.IsChecked) { highwayFilter = highwayFilter | enOSMhighwayFilter.Construction; } }
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; }
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; } } }
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(); }
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); }
public static async Task<shPath> FindShortPathWithArrayNodes(string ScenarioId, int[] arrNodeId, enOSMhighwayFilter[] arrHighwayFilter) { using(var client = new HttpClient()) { client.BaseAddress = new Uri(BaseAddress); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); ArrNodes nodes = new ArrNodes(); nodes.ScenarioId = ScenarioId; nodes.arrNodeId = arrNodeId; nodes.arrHighwayFilter = arrHighwayFilter; HttpResponseMessage response = await client.PostAsJsonAsync<ArrNodes>("api/Routing/FindShortPathWithArrayNodes/", nodes); //FindShortPathWithArrayNodes if (response.StatusCode != System.Net.HttpStatusCode.OK) { return null; } HttpContent content = response.Content; string v = await content.ReadAsStringAsync(); shPath tmp = JsonConvert.DeserializeObject<shPath>(v); return tmp; } }
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(); }
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; } } }