/// <summary> /// Makes a click on the display. /// Returns true when a mapicon is placed. /// </summary> public bool OnClick(object o, MouseMapDragEventArgs mmdea) { bool placedIcon = false; if (ClientRectangle.Contains(mmdea.Location) && graph != null && !isCalculatingRoute) { if (mmdea.Button == MouseButtons.Left) { Point corner = CoordToPoint(bounds.XMin, bounds.YMax); Coordinate c = PointToCoord(corner.X + mmdea.X, corner.Y - mmdea.Y); Node location = null; switch (buttonMode) { case ButtonMode.From: location = graph.GetNodeByPos(c.Longitude, c.Latitude, Vehicle.Foot); if (location != null) { SetMapIcon(IconType.Start, location, mmdea.MapButton); placedIcon = true; } break; case ButtonMode.To: location = graph.GetNodeByPos(c.Longitude, c.Latitude, Vehicle.Foot); if (location != null && mmdea.MapButton != null) { SetMapIcon(IconType.End, location, mmdea.MapButton); placedIcon = true; } break; case ButtonMode.Via: //location = graph.GetNodeByPos(lon, lat, Vehicle.All); // Not used Vehicle.All because then are situations where you can't go to // the location, and the RouteFinder doesn't support this. location = graph.GetNodeByPos(c.Longitude, c.Latitude, Vehicle.Foot); if (location != null && mmdea.MapButton != null) { SetMapIcon(IconType.Via, location, mmdea.MapButton); placedIcon = true; } break; case ButtonMode.NewBike: // You can place a Bycicle at a location where you can walk. location = graph.GetNodeByPos(c.Longitude, c.Latitude, new Vehicle[] { Vehicle.Bicycle, Vehicle.Foot }); if (location != null && mmdea.MapButton != null) { AddVehicle(new MyVehicle(Vehicle.Bicycle, location)); placedIcon = true; } break; case ButtonMode.NewCar: location = graph.GetNodeByPos(c.Longitude, c.Latitude, Vehicle.Car); if (location != null && mmdea.MapButton != null) { AddVehicle(new MyVehicle(Vehicle.Car, location)); placedIcon = true; } break; } buttonMode = ButtonMode.None; } else if (mmdea.Button == MouseButtons.Right) { foreach (MapIcon icon in icons) { if (icon.IntersectWith(mmdea.Location)) { mouseDown = false; lockZoom = true; icons.Remove(icon); myVehicles.Remove(icon.Vehicle); MapIconRemoved(this, new MapDragEventArgs(icon.Button)); CalcRoute(); break; } } } // TODO: lelijke code ((MainForm)Parent).Save(); this.Invalidate(); } return(placedIcon); }
/// <summary> /// Makes a click on the display. /// Returns true when a mapicon is placed. /// </summary> public bool OnClick(object o, MouseMapDragEventArgs mmdea) { bool placedIcon = false; if (ClientRectangle.Contains(mmdea.Location) && graph != null && !isCalculatingRoute) { if (mmdea.Button == MouseButtons.Left) { Point corner = CoordToPoint(bounds.XMin, bounds.YMax); Coordinate c = PointToCoord(corner.X + mmdea.X, corner.Y - mmdea.Y); Node location = null; switch (buttonMode) { case ButtonMode.From: location = graph.GetNodeByPos(c.Longitude, c.Latitude, Vehicle.Foot); if (location != null) { SetMapIcon(IconType.Start, location, mmdea.MapButton); placedIcon = true; } break; case ButtonMode.To: location = graph.GetNodeByPos(c.Longitude, c.Latitude, Vehicle.Foot); if (location != null && mmdea.MapButton != null) { SetMapIcon(IconType.End, location, mmdea.MapButton); placedIcon = true; } break; case ButtonMode.Via: //location = graph.GetNodeByPos(lon, lat, Vehicle.All); // Not used Vehicle.All because then are situations where you can't go to // the location, and the RouteFinder doesn't support this. location = graph.GetNodeByPos(c.Longitude, c.Latitude, Vehicle.Foot); if (location != null && mmdea.MapButton != null) { SetMapIcon(IconType.Via, location, mmdea.MapButton); placedIcon = true; } break; case ButtonMode.NewBike: // You can place a Bycicle at a location where you can walk. location = graph.GetNodeByPos(c.Longitude, c.Latitude, new Vehicle[] { Vehicle.Bicycle, Vehicle.Foot }); if (location != null && mmdea.MapButton != null) { AddVehicle(new MyVehicle(Vehicle.Bicycle, location)); placedIcon = true; } break; case ButtonMode.NewCar: location = graph.GetNodeByPos(c.Longitude, c.Latitude, Vehicle.Car); if (location != null && mmdea.MapButton != null) { AddVehicle(new MyVehicle(Vehicle.Car, location)); placedIcon = true; } break; } buttonMode = ButtonMode.None; } else if (mmdea.Button == MouseButtons.Right) { foreach (MapIcon icon in icons) { if (icon.IntersectWith(mmdea.Location)) { mouseDown = false; lockZoom = true; icons.Remove(icon); myVehicles.Remove(icon.Vehicle); MapIconRemoved(this, new MapDragEventArgs(icon.Button)); CalcRoute(); break; } } } // TODO: lelijke code ((MainForm)Parent).Save(); this.Invalidate(); } return placedIcon; }