private void gMapControl_MainMap_MainMapForm_MouseClick(object sender, MouseEventArgs e) { if (e.Button == System.Windows.Forms.MouseButtons.Left) { double lat = gMapControl_MainMap_MainMapForm.FromLocalToLatLng(e.X, e.Y).Lat; double lng = gMapControl_MainMap_MainMapForm.FromLocalToLatLng(e.X, e.Y).Lng; List<Placemark> plc = null; PointLatLng clickPoint = (gMapControl_MainMap_MainMapForm.FromLocalToLatLng(e.X, e.Y)); if (mWhatToDoOnClick == mCommandAddDriver) { AddDriverMarker(clickPoint, Color.Green); mActiveDrivers++; } else if(mWhatToDoOnClick == mCommandAddItemPickupPoint) { if (mTempOrder.OrderName == mNoOrderString) { mTempOrder = new Order(); mTempOrder.OrderName = "ORDER"; mTempOrder.PickupPoint = clickPoint; mWhatToDoOnClick = mCommandAddItemDropOffPoint; } } else if(mWhatToDoOnClick == mCommandAddItemDropOffPoint) { mTempOrder.DropoOffPoint = clickPoint; int count = 0; KnownColor[] values = (KnownColor[])Enum.GetValues(typeof(KnownColor)); foreach (KnownColor kc in values) { Color realColor = Color.FromKnownColor(kc); if(count == mColourToPick) { mTempOrder.OrderColour = realColor; GMapRoute wasRouteCreated = AddRoute(mTempOrder.PickupPoint, mTempOrder.DropoOffPoint); if (wasRouteCreated == null) break; mTempOrder.OrderID = mTotalItems; mTempOrder.PickupMarker = AddDeliveryMarker(mTempOrder.PickupPoint, realColor, mColourToPick); mTempOrder.DropOffMarker = AddDeliveryMarker(mTempOrder.DropoOffPoint, realColor, mColourToPick); mTempOrder.TimeOrderWasCreated = DateTime.Now; mTempOrder.TimeOrderWasAccepted = mTempOrder.TimeOrderWasCreated; mColourToPick++; mWhatToDoOnClick = mCommandAddItemPickupPoint; mItems.Add(mTempOrder); mTempOrder.OrderName = mNoOrderString; mTotalItems++; break; } count++; } } //Debug Stuff /*var st = GMap.NET.MapProviders.GoogleMapProvider.Instance.GetPlacemarks(clickPoint, out plc); if (st == GeoCoderStatusCode.G_GEO_SUCCESS && plc != null) { foreach (var pl in plc) { if (!string.IsNullOrEmpty(pl.PostalCodeNumber)) { textBox_DebugBox_MainMapForm.Text = "Accuracy: " + pl.Accuracy + ", " + pl.Address + ", PostalCodeNumber: " + pl.PostalCodeNumber; } } }*/ } }
private void AddDriverMarker(PointLatLng aPointToPlaceDriverMarker, Color aMarkerColour) { Driver driver = new Driver(); Order order = new Order(); driver.DriverID = mTotalDrivers; driver.KMDriven = 0; driver.MoneyMade = 0; driver.TimeWorked = 0; driver.OrdersWorkedOn = new List<short>(); order.OrderName = mCommandNoOrder; driver.OrderWorkingOn = order; driver.DriverReliability = mRandom.Next(mDriverMinReliability, mDriverMaxReliability); driver.Marker = new GMap.NET.WindowsForms.Markers.GMarkerGoogle(aPointToPlaceDriverMarker, GMap.NET.WindowsForms.Markers.GMarkerGoogleType.blue_dot); mDrivers.Add(driver); gMapControl_MainMap_MainMapForm.Overlays.Add(mDriverMarkers); mDriverMarkers.Markers.Add(driver.Marker); mActiveDrivers++; mTotalDrivers++; }
private void button_AddDeliveryComplete_MainMapForm_Click(object sender, EventArgs e) { if (textBox_OriginAddress_MainMapForm.Text != string.Empty && textBox_DestinationAddress_MainMapForm.Text != string.Empty) { Order order = new Order(); order.OrderName = "ORDER"; int count = 0; string originAddress = textBox_OriginAddress_MainMapForm.Text; string destinationAddress = textBox_DestinationAddress_MainMapForm.Text; //textBox_OriginAddress_MainMapForm.Text = string.Empty; //textBox_DestinationAddress_MainMapForm.Text = string.Empty; GeoCoderStatusCode status; PointLatLng? originPoint = GMap.NET.MapProviders.GoogleMapProvider.Instance.GetPoint(originAddress, out status); if (status == GeoCoderStatusCode.G_GEO_SUCCESS && originPoint != null) { order.PickupPoint = (PointLatLng)originPoint; } PointLatLng? destinationPoint = GMap.NET.MapProviders.GoogleMapProvider.Instance.GetPoint(destinationAddress, out status); if (status == GeoCoderStatusCode.G_GEO_SUCCESS && originPoint != null) { order.DropoOffPoint = (PointLatLng)destinationPoint; } KnownColor[] values = (KnownColor[])Enum.GetValues(typeof(KnownColor)); foreach (KnownColor kc in values) { Color realColor = Color.FromKnownColor(kc); if (count == mColourToPick) { order.OrderColour = realColor; GMapRoute wasRouteCreated = AddRoute(order.PickupPoint, order.DropoOffPoint); if (wasRouteCreated == null) break; order.OrderID = mTotalItems; order.PickupMarker = AddDeliveryMarker(order.PickupPoint, realColor, mColourToPick); order.DropOffMarker = AddDeliveryMarker(order.DropoOffPoint, realColor, mColourToPick); order.TimeOrderWasCreated = DateTime.Now; order.TimeOrderWasAccepted = order.TimeOrderWasCreated; order.TimeOrderWasPickedUp = order.TimeOrderWasCreated; mColourToPick++; mWhatToDoOnClick = mCommandAddItemPickupPoint; mItems.Add(order); mTotalItems++; break; } count++; } } }
//TODO: Find a list of Ottawa addresses. Use them for deliveries. Pull an address, use it as origin. Pull a second, make sure it's different, use it as destination. Or pull several destinations per origin. public MainMapForm() { InitializeComponent(); mDriverMarkers = new GMapOverlay("Drivers"); mDeliveryMarkers = new GMapOverlay("Deliveries"); mRoutes = new GMapOverlay("Routes"); mAllRoutes = new GMapOverlay("All Routes"); mDrivers = new List<Driver>(); mActiveDrivers = 0; mTotalDrivers = 0; mTotalItems = 0; mItems = new List<Order>(); mDealtWithItems = new List<Order>(); mRandom = new Random(); mTempOrder = new Order(); mTempOrder.OrderName = mNoOrderString; mColourToPick = 0; mSimSpeed = 1; mRefreshRate = TimeSpan.FromMilliseconds(1000); mDriverFee = 3; mDeliveryFee = 0; mDollarPerKM = 0.3f; mAverageKMPerHour = 40; mMaximumKMPerHour = 60; mMaxPickupDistance = 60; mDriverMinReliability = 80; mDriverMaxReliability = 95; mWhatToDoOnClick = mCommandDoNothing; LoadMap(); StartThreads(); }