예제 #1
0
        /* Add new marker event */
        private async void MapWithPushpins_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            try
            {
                e.Handled = true;

                Point    mousePosition = e.GetPosition(MainMap);
                Location pinLocation   = MainMap.ViewportPointToLocation(mousePosition);

                LocationMarker newMarker = new LocationMarker();
                newMarker.markerID = markerCount;

                newMarker.location  = new Location(pinLocation.Latitude, pinLocation.Longitude);
                newMarker.latitude  = pinLocation.Latitude;
                newMarker.longitude = pinLocation.Longitude;

                await getAltitude(pinLocation.Latitude, pinLocation.Longitude, newMarker);

                Pushpin pin = new Pushpin();
                pin.Location = pinLocation;
                MainMap.Children.Add(pin);

                ListBoxItem newItem = new ListBoxItem();
                newItem.Content     = "Marker #" + markerCount;
                newItem.DataContext = newMarker.latitude + "," + newMarker.longitude;
                markerListBox.Items.Add(newItem);

                if (newPlan.locationMarkers.Count > 1)
                {
                    MapPolyline polygon = new MapPolyline();
                    polygon.Stroke          = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Black);
                    polygon.StrokeThickness = 3;
                    polygon.Opacity         = 0.7;
                    polygon.Locations       = new LocationCollection()
                    {
                        newMarker.location, newPlan.locationMarkers[markerCount - 1].location
                    };

                    MainMap.Children.Add(polygon);
                }

                markerCount++;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #2
0
        /* Get altitude for a given marker */
        private async Task getAltitude(double lat, double lng, LocationMarker marker)
        {
            using (var httpClient = new HttpClient())
            {
                using (var request = new HttpRequestMessage(new HttpMethod("GET"), "https://api.airmap.com/elevation/v1/ele/?points=" + lat + "," + lng))
                {
                    var response = await httpClient.SendAsync(request);

                    var     s    = response.Content.ReadAsStringAsync().Result;
                    JObject json = JObject.Parse(s);

                    string altitudeNum   = new string(json["data"].ToString().Where(c => char.IsDigit(c)).ToArray());
                    double altitudeFinal = double.Parse(altitudeNum);

                    marker.altitude = altitudeFinal;
                    newPlan.locationMarkers.Add(marker);

                    altitudeSeries.Values.Add(altitudeFinal);
                    altChart.Series = chartSeries;
                }
            }
        }
예제 #3
0
        /* Parse flightplan file into object */
        private FlightPlan parseFlightplan(string fileName)
        {
            string schemaCode = File.ReadAllText(baseDirectory + "\\flightplans\\" + fileName);
            string parsedCode = schemaCode.Remove(schemaCode.Length - 2).Replace("\n", "");

            FlightPlan loadedPlan = new FlightPlan();

            loadedPlan.locationMarkers = new List <LocationMarker>();

            foreach (string line in parsedCode.Split('!'))
            {
                string[]       dataPoints = line.Split(',');
                LocationMarker newMarker  = new LocationMarker();
                newMarker.markerID  = Convert.ToInt32(dataPoints[0]);
                newMarker.latitude  = double.Parse(dataPoints[1]);
                newMarker.longitude = double.Parse(dataPoints[2]);
                newMarker.altitude  = double.Parse(dataPoints[3]);
                newMarker.location  = new Location(newMarker.latitude, newMarker.longitude);

                loadedPlan.locationMarkers.Add(newMarker);
            }

            return(loadedPlan);
        }