Пример #1
0
        private void AddBtn_Click(object sender, RoutedEventArgs e)
        {
            if (edit == true)
            {
                waypointsTxt.Items.Clear();
                edit = false;
            }
            if (routeTypeCmb.Text == waypoint[0] && counter > 0)
            {
                MessageBox.Show("Start waypoint already selected");
                waypoint[counter] = "";
            }
            else
            {
                //creates a request to bing maps api for a geo code
                RestClient client = new RestClient();
                client.endPoint   = "http://localhost:8080/AppServer_war_exploded/logic/geo/" + addTxt.Text;
                waypoint[counter] = routeTypeCmb.Text;
                string response = client.makeRequest();

                try
                {
                    // creates JGeoCode from response
                    JGeoCode code1 = JsonConvert.DeserializeObject <JGeoCode>(response.ToString());

                    //creates expander objects added to listbox on button click
                    Expander expander = new Expander
                    {
                        Header  = waypoint[counter],
                        Name    = "expander" + counter.ToString(),
                        Content = "Address: " + "\n" + code1.resourceSets[0].resources[0].address.formattedAddress
                    };

                    RegisterName("expander" + counter.ToString(), expander);
                    waypointsTxt.Items.Add(expander);
                    //keeps geo cords to forward to bing api
                    GeoCords.Enqueue(code1.resourceSets[0].resources[0].point.coordinates[0] + "," + code1.resourceSets[0].resources[0].point.coordinates[1]);
                    ////keeps response
                    cordsAddress.Add(code1);

                    //ui formatting
                    waypoint[counter]          = routeTypeCmb.Text;
                    routeTypeCmb.SelectedIndex = 2;
                    addTxt.Clear();
                    counter++;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Whoops something happened, please try again");
                }
            }
        }
Пример #2
0
        private void RouteTxt_TextChanged(object sender, TextChangedEventArgs e)
        {
            //shows route information
            try
            {
                //converts units for km's to mile's
                double kDistance = mjRoute.resourceSets[0].resources[0].travelDistance / 1.609344;
                double mDistance = Math.Round(kDistance, 2);
                time  = TimeSpan.FromSeconds(mjRoute.resourceSets[0].resources[0].travelDuration);
                start = cordsAddress[0];
                end   = cordsAddress[cordsAddress.Count - 1];

                string startResult = start.resourceSets[0].resources[0].address.formattedAddress;
                string endResult   = end.resourceSets[0].resources[0].address.formattedAddress;

                string[] startWords            = startResult.Split(',');
                string[] endWords              = endResult.Split(',');
                var      formattedStartAddress = new System.Text.StringBuilder();
                var      formattedEndAddress   = new System.Text.StringBuilder();
                //converts start formatted address into atomic elements
                for (int i = 1; i < startWords.Length; i++)
                {
                    formattedStartAddress.AppendLine(startWords[i]);
                }
                formattedStartAddress.AppendLine(startWords[0]);

                //converts end formatted address into atomic elements
                for (int i = 1; i < endWords.Length; i++)
                {
                    formattedEndAddress.AppendLine(endWords[i]);
                }
                formattedEndAddress.AppendLine(endWords[0]);

                startTxtBlk.Text = "\n\n\n\n\n\n" + formattedStartAddress.ToString();

                endTxtBlk.Text = "\n\n\n\n\n\n" + formattedEndAddress.ToString();

                summaryTxtBlk.Text = "\n\n\n\nDistance: " + mDistance + "miles " + "                Estimated Duration: " + time;
            }
            catch (Exception ex)
            {
                ex.ToString();
            }
        }
Пример #3
0
        private void  CalcRouteBtn_Click(object sender, RoutedEventArgs e)
        {
            //takes each geo location taken from array and querys HERE API for route
            foreach (var cord in GeoCords)
            {
                hTemp += "&waypoint." + hcounter + "=" + cord;
                hcounter++;
            }

            RestClient client = new RestClient();

            if (window.editTxt.Text == "Save")
            {
                mapTest.Children.Clear();
                client.endPoint = "http://localhost:8080/AppServer_war_exploded/logic/route/" + hTemp + "?" + "height=" + shift.busT.bus_height + "&width=" + shift.busT.bus_width + "&weight=" + shift.busT.bus_weight;
                response        = client.makeRequest();

                window.route = response;
            }
            else
            {
                client.endPoint = "http://localhost:8080/AppServer_war_exploded/logic/route/" + hTemp + "?" + "height=" + shift.bus.bus_height + "&width=" + shift.bus.bus_width + "&weight=" + shift.bus.bus_weight;
                response        = client.makeRequest();
            }

            try
            {
                code = JsonConvert.DeserializeObject <JRoute>(response.ToString());
                //turns api response into JRoute object plots the path and draws to map the lines to map control
                int via = 0;
                shift.jRoute       = code;
                shift.jRouteString = response.ToString();

                //creates Bing Map API Request and add start and end push pins
                for (int i = 0; i < code.resourceSets[0].resources[0].routeLegs[0].itineraryItems.Length; i++)
                {
                    if (i == 0 || i == code.resourceSets[0].resources[0].routeLegs[0].itineraryItems.Length - 1)
                    {
                        double lat = code.resourceSets[0].resources[0].routeLegs[0].itineraryItems[i].maneuverPoint.coordinates[0];
                        double lng = code.resourceSets[0].resources[0].routeLegs[0].itineraryItems[i].maneuverPoint.coordinates[1];
                        mTemp += "&wp." + i + "=" + lat + "," + lng;
                        Pushpin pin = new Pushpin();
                        pin.Location = new Location(lat, lng);
                        mapTest.Children.Add(pin);
                    }
                    else if (code.resourceSets[0].resources[0].routeLegs[0].itineraryItems.Length >= 25 && via < 9)
                    {
                        double lat = code.resourceSets[0].resources[0].routeLegs[0].itineraryItems[i].maneuverPoint.coordinates[0];
                        double lng = code.resourceSets[0].resources[0].routeLegs[0].itineraryItems[i].maneuverPoint.coordinates[1];
                        mTemp += "&vwp." + i + "=" + lat + "," + lng;
                        via++;
                    }
                    else
                    {
                        double lat = code.resourceSets[0].resources[0].routeLegs[0].itineraryItems[i].maneuverPoint.coordinates[0];
                        double lng = code.resourceSets[0].resources[0].routeLegs[0].itineraryItems[i].maneuverPoint.coordinates[1];
                        mTemp += "&wp." + i + "=" + lat + "," + lng;
                    }
                    I = i;
                }

                mapTest.Center    = new Location(code.resourceSets[0].resources[0].routeLegs[0].itineraryItems[0].maneuverPoint.coordinates[0], code.resourceSets[0].resources[0].routeLegs[0].itineraryItems[0].maneuverPoint.coordinates[1]);
                mapTest.ZoomLevel = 13;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Couldn't find location, try again");
            }



            try
            {
                MJRoute code2 = JsonConvert.DeserializeObject <MJRoute>(response.ToString());
                shift.mjRoute       = code2;
                shift.mjRouteString = response.ToString();

                MapPolyline polyline = new MapPolyline();
                polyline.Stroke          = new SolidColorBrush(Colors.Blue);
                polyline.StrokeThickness = 3;
                polyline.Opacity         = 0.7;

                coll = new LocationCollection();

                ////full path
                foreach (var item in code2.resourceSets[0].resources[0].routePath.line.coordinates)
                {
                    coll.Add(new Location(item[0], item[1]));
                }
                //non matched
                //foreach (var item in code2.resourceSets[0].resources[0].routeLegs[0].itineraryItems)
                //{
                //    coll.Add(new Location(item.maneuverPoint.coordinates[0], item.maneuverPoint.coordinates[1]));
                //}

                polyline.Locations = coll;
                mapTest.Children.Add(polyline);
                calc = true;

                //creates summary expander
                if (counter >= 2)
                {
                    JGeoCode sCode = cordsAddress[0];
                    JGeoCode eCode = cordsAddress[cordsAddress.Count - 1];
                    time      = TimeSpan.FromSeconds(code2.resourceSets[0].resources[0].travelDuration);
                    kDistance = code2.resourceSets[0].resources[0].travelDistance;
                    mDistance = Math.Round(kDistance, 2);
                    Expander eExpander = new Expander
                    {
                        Header  = "Summary",
                        Content = "Start: " + "\nTravel Time: " + time
                                  + "\nDistance: " + mDistance + "miles"
                    };
                    waypointsTxt.Items.Add(eExpander);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString() + "what what");
                calc = false;
            }
        }