internal void NotifyMouseRightClickOnMapEvent(MapMouseEventArgsWPF args) { if (dlgMouseRightClickOnMapEvent == null) { return; } dlgMouseRightClickOnMapEvent(this, args); }
protected override void OnMouseDown(System.Windows.Input.MouseButtonEventArgs e) { base.OnMouseDown(e); Point pnt = e.GetPosition(this); int XDown = (int)pnt.X; int YDown = (int)pnt.Y; GMap.NET.PointLatLng Position = FromLocalToLatLng(XDown, YDown); if (e.LeftButton == System.Windows.Input.MouseButtonState.Pressed) { MapMouseEventArgsWPF me = new MapMouseEventArgsWPF(); me.MapXLongLatWGS84 = Position.Lng; me.MapYLongLatWGS84 = Position.Lat; me.X = pnt.X; me.Y = pnt.Y; try { VMMainViewModel.Instance.NotifyMouseLeftClickOnMapEvent(me); } catch (Exception ex) { } } else if (e.RightButton == System.Windows.Input.MouseButtonState.Pressed) { MapMouseEventArgsWPF me = new MapMouseEventArgsWPF(); me.MapXLongLatWGS84 = Position.Lng; me.MapYLongLatWGS84 = Position.Lat; me.X = pnt.X; me.Y = pnt.Y; try { VMMainViewModel.Instance.NotifyMouseRightClickOnMapEvent(me); } catch (Exception ex) { } } }
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; // } // } // } }
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; } } } }
internal void NotifyMouseRightClickOnMapEvent(MapMouseEventArgsWPF args) { if (dlgMouseRightClickOnMapEvent == null) return; dlgMouseRightClickOnMapEvent(this, args); }
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; } } }
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) { } }
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; } } }