Example #1
0
    private void LoadPointFeatures()
    {
        cdbDatabase = fpsCDB.GetCDBDatabase();
#if UNITY_ANDROID
        string filepath = UnityEngine.Application.persistentDataPath;
#else
        string filepath = cdbDatabase.Path;
#endif
        cdbDatabase = fpsCDB.GetCDBDatabase();
        string databaseName = cdbDatabase.name;
        databaseName = databaseName.Replace('.', '_');

        var feats = Cognitics.CDB.Shapefile.ReadFeatures(filepath + "/" + databaseName + "point.shp");
        foreach (Feature f in feats)
        {
            GeoAPI.Geometries.Coordinate[] coords = f.Geometry.Coordinates;
            var geoCoords = new Cognitics.CoordinateSystems.GeographicCoordinates();
            geoCoords.Longitude = coords[0].X;
            geoCoords.Latitude  = coords[0].Y;
            var         cartCoords = geoCoords.TransformedWith(cdbDatabase.Projection);
            Vector3     loc        = new Vector3((float)cartCoords.X, (float)coords[0].Z, (float)cartCoords.Y);
            LocationPin lp         = locationPin.GetComponent <LocationPin>();
            lp.title.GetComponent <TMP_InputField>().text       = f.Attributes["Title"].ToString();
            lp.description.GetComponent <TMP_InputField>().text = f.Attributes["Description"].ToString();
            lp.location.GetComponent <TextMeshProUGUI>().text   = f.Geometry.ToString();
            lp.SetPinText();
            locationPin.SetActive(true);
            Instantiate(locationPin, loc, Quaternion.identity);
            locationPin.SetActive(false);
            lp.ClearFields();
        }
    }
Example #2
0
 /// <summary>
 /// Launches the Maps app and displays the route from the current location
 /// to the specified location.
 /// </summary>
 /// <param name="location">The location to display the route to.</param>
 public static async Task ShowRouteToLocationInMapsAppAsync(LocationPin location, LocationPin currentLocation)
 {
     var mapUri = new Uri("bingmaps:?trfc=1&rtp=" +
                          $"pos.{currentLocation.Position.Latitude}_{currentLocation.Position.Longitude}~" +
                          $"pos.{location.Position.Latitude}_{location.Position.Longitude}");
     await Windows.System.Launcher.LaunchUriAsync(mapUri);
 }
Example #3
0
        /// <summary>
        /// Updates the UI to account for the user's current position, if available,
        /// resetting the MapControl bounds and refreshing the travel info.
        /// </summary>
        /// <param name="isGeolocatorReady">false if the Geolocator is known to be unavailable; otherwise, true.</param>
        /// <returns></returns>
        private async Task ResetViewAsync(bool isGeolocatorReady = true)
        {
            LocationPin currentLocation = null;

            if (isGeolocatorReady)
            {
                currentLocation = await this.GetCurrentLocationAsync();
            }
            if (currentLocation != null)
            {
                if (this.ViewModel.CheckedLocations.Count > 0)
                {
                    var currentLoc = this.ViewModel.CheckedLocations.FirstOrDefault(loc => loc.IsCurrentLocation == true);
                    if (currentLoc != null && currentLoc.IsCurrentLocation)
                    {
                        this.ViewModel.CheckedLocations.Remove(currentLoc);
                    }
                }
                this.ViewModel.CheckedLocations.Add(new LocationPin {
                    Position = currentLocation.Position, IsCurrentLocation = true
                });

                this.ViewModel.PinDisplayInformation = new LocationPin {
                    Position = currentLocation.Position, IsCurrentLocation = true
                };
                this.InputMap.Center    = new Geopoint(currentLocation.Position);
                this.InputMap.ZoomLevel = 20;
                await LocationHelper.TryUpdateMissingLocationInfoAsync(this.ViewModel.PinDisplayInformation, null);
            }
        }
 public LocationPinForPosting(LocationPin location)
 {
     Name        = location.Name;
     Latitude    = location.Latitude;
     Longitude   = location.Longitude;
     Description = location.Description;
 }
        private async void PostButton_Click(object sender, RoutedEventArgs e)
        {
            var position = App.currentLocation.Position;

            if (isRandomPhotoLocation)
            {
                position = LocationHelper.getRandomLocation(App.currentLocation.Position);
            }

            var item = new LocationPin
            {
                Position = position,
                Photo    = new SharedPhoto
                {
                    ShareWith   = contactPickerTb.Text,
                    ImageName   = imageName,
                    Description = DescriptionTb.Text,
                },
                IsCheckPoint = true,
                DateCreated  = App.currentLocation.DateCreated
            };
            await localData.InsertLocationDataAsync(item);

            App.PageName = "TripTrak";
            this.Frame.GoBack();
        }
        /// <summary>
        /// Loads the saved location data on first navigation, and
        /// attaches a Geolocator.StatusChanged event handler.
        /// </summary>
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            if (App.PageName.Equals("Start Trip"))
            {
                bool getPins = await GetPinsForGivenDate();

                if (this.ViewModel.CheckedLocations.Count > 0)
                {
                    oldPin               = this.ViewModel.CheckedLocations[0];
                    oldPin.IsSelected    = true;
                    selectedImage.Source = await PhotoHelper.getImageSource(this.ViewModel.CheckedLocations[0].Photo.ImageName);
                }
                else if (this.ViewModel.PinnedLocations.Count > 0)
                {
                    oldPin = this.ViewModel.PinnedLocations[0];
                }
                else
                {
                    oldPin = new LocationPin
                    {
                        DateCreated = HistoryDatePicker.Date,
                    };
                }
            }
            else if (App.PageName.Equals("End Trip"))
            {
                tripItem             = e.Parameter as Trip;
                NameTb.Text          = tripItem.Name;
                shareTb.Text         = tripItem.ShareWith;
                DescTb.Text          = tripItem.Description;
                startDateTb.Text     = "End Date";
                startPointTb.Text    = "End Point";
                submitButton.Content = "End Trip";
                bool getPins = await GetPinsForGivenDate();

                if (this.ViewModel.CheckedLocations.Count > 0)
                {
                    oldPin               = this.ViewModel.CheckedLocations[this.ViewModel.CheckedLocations.Count - 1];
                    oldPin.IsSelected    = true;
                    selectedImage.Source = await PhotoHelper.getImageSource(this.ViewModel.CheckedLocations[this.ViewModel.CheckedLocations.Count - 1].Photo.ImageName);
                }
                else if (this.ViewModel.PinnedLocations.Count > 0)
                {
                    oldPin = this.ViewModel.PinnedLocations[this.ViewModel.PinnedLocations.Count - 1];
                }
                else
                {
                    oldPin = new LocationPin {
                        DateCreated = HistoryDatePicker.Date,
                    };
                }
            }

            if (e.NavigationMode == NavigationMode.New)
            {
            }
        }
Example #7
0
        private void checkedPinBtn_Click(object sender, RoutedEventArgs e)
        {
            Button      btn    = (Button)sender;
            LocationPin btnPin = btn.DataContext as LocationPin;

            //move the slider, photo list along
            ImageGridView.SelectedIndex = this.ViewModel.CheckedLocations.IndexOf(btnPin);
            displayInfoGrid.Visibility  = Visibility.Visible;
        }
        private async void checkedPinBtn_Click(object sender, RoutedEventArgs e)
        {
            LocationPin btnPin = ((Button)sender).DataContext as LocationPin;

            oldPin.IsSelected = false;
            oldPin            = btnPin;
            oldPin.IsSelected = true;
            await LocationHelper.TryUpdateMissingLocationInfoAsync(btnPin, null);

            selectedImage.Source = await PhotoHelper.getImageSource(btnPin.Photo.ImageName);
        }
        private async void HistoryDatePicker_DateChanged(object sender, DatePickerValueChangedEventArgs e)
        {
            HistoryDatePicker.IsHitTestVisible = false;
            HistoryDatePicker.Opacity          = 0.5;

            var hasData = await GetPinsForGivenDate();

            if (App.PageName.Equals("Start Trip"))
            {
                if (this.ViewModel.CheckedLocations.Count > 0)
                {
                    oldPin               = this.ViewModel.CheckedLocations[0];
                    oldPin.IsSelected    = true;
                    selectedImage.Source = await PhotoHelper.getImageSource(this.ViewModel.CheckedLocations[0].Photo.ImageName);
                }
                else if (this.ViewModel.PinnedLocations.Count > 0)
                {
                    oldPin = this.ViewModel.PinnedLocations[0];
                }
                else
                {
                    oldPin = new LocationPin
                    {
                        DateCreated = HistoryDatePicker.Date,
                    };
                }
            }
            else if (App.PageName.Equals("End Trip"))
            {
                if (this.ViewModel.CheckedLocations.Count > 0)
                {
                    oldPin               = this.ViewModel.CheckedLocations[this.ViewModel.CheckedLocations.Count - 1];
                    oldPin.IsSelected    = true;
                    selectedImage.Source = await PhotoHelper.getImageSource(this.ViewModel.CheckedLocations[this.ViewModel.CheckedLocations.Count - 1].Photo.ImageName);
                }
                else if (this.ViewModel.PinnedLocations.Count > 0)
                {
                    oldPin = this.ViewModel.PinnedLocations[this.ViewModel.PinnedLocations.Count - 1];
                }
                else
                {
                    oldPin = new LocationPin
                    {
                        DateCreated = HistoryDatePicker.Date,
                    };
                }
            }

            HistoryDatePicker.IsHitTestVisible = true;
            HistoryDatePicker.Opacity          = 1;
        }
Example #10
0
        void SaveButton_Click(object sender, EventArgs e)
        {
            var location = new LocationPin
            {
                Name        = title.Text,
                Description = description.Text,
                Latitude    = gps.Latitude,
                Longitude   = gps.Longitude
            };

            ViewModel.AddLocationsCommand.Execute(location);

            Finish();
        }
Example #11
0
        private void ImageGridView_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                //get selected ImageGrid item and convert to LocationPin
                LocationPin loc = (ImageGridView.SelectedItem) as LocationPin;

                //move the slider along
                CheckPointSlider.Value = this.ViewModel.MileStoneLocations.IndexOf(loc);

                ImageGridView.ScrollIntoView(loc, ScrollIntoViewAlignment.Leading);
            }
            catch (Exception ex)
            {
            }
        }
Example #12
0
        private void PutEntries(string path, Regex rgx, string text)
        {
            path = path.Substring(_rootPath.Length).Trim('/', '\\');
            MatchCollection matches = rgx.Matches(text);

            foreach (Match m in matches)
            {
                string ns   = m.Groups[1].Value;
                string cn   = m.Groups[2].Value;
                string full = ns.Trim() + "." + cn.Trim();


                var pin = new LocationPin(path, full);

                _entityToLocation[full] = pin;
            }
        }
Example #13
0
        /// <summary>
        /// Attempts to update either the address or the coordinates of the specified location
        /// if the other value is missing, using the specified current location to provide
        /// context for prioritizing multiple locations returned for an address.
        /// </summary>
        /// <param name="location">The location to update.</param>
        /// <param name="currentLocation">The current location.</param>
        public static async Task <bool> TryUpdateMissingLocationInfoAsync(LocationPin location, LocationPin currentLocation)
        {
            bool hasNoAddress = String.IsNullOrEmpty(location.Address);

            if (location.Photo == null)
            {
                location.Photo = new SharedPhoto();
            }
            if (!hasNoAddress)
            {
                return(true);
            }
            else if (location.Position.Latitude == 0 && location.Position.Longitude == 0)
            {
                return(false);
            }

            var results = await MapLocationFinder.FindLocationsAtAsync(location.Geopoint);


            if (results.Status == MapLocationFinderStatus.Success && results.Locations.Count > 0)
            {
                var result = results.Locations.First();

                //This will re-allocate the Position to that particular address.
                //   location.Position = result.Point.Position;
                location.Address = result.Address.FormattedAddress;
                if (String.IsNullOrEmpty(location.Name))
                {
                    location.Name = result.Address.Town;
                }

                // Sometimes the returned address is poorly formatted. This fixes one of the issues.
                if (location.Address.Trim().StartsWith(","))
                {
                    location.Address = location.Address.Trim().Substring(1).Trim();
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #14
0
        /// <summary>
        /// Save the BasicGeoposition list to roaming storage.
        /// </summary>
        /// <param name="locations">The BasicGeoposition list  to save.</param>
        public async Task InsertLocationDataAsync(LocationPin location)
        {
            string      fileName   = GenerateFileName(dataFileName, location.DateCreated.Date);
            StorageFile sampleFile = await ApplicationData.Current.RoamingFolder.CreateFileAsync(
                fileName, CreationCollisionOption.OpenIfExists);

            using (MemoryStream stream = new MemoryStream())
            {
                var serializer = new DataContractJsonSerializer(typeof(LocationPin));
                serializer.WriteObject(stream, location);
                stream.Position = 0;
                using (StreamReader reader = new StreamReader(stream))
                {
                    string locationString = reader.ReadToEnd();
                    locationString = locationString + ",";
                    await FileIO.AppendTextAsync(sampleFile, locationString);
                }
            }
        }
Example #15
0
 private void Geolocator_PositionChanged(Geolocator sender, PositionChangedEventArgs args)
 {
     var _ = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
     {
         if (args.Position.Coordinate.Accuracy < 55)
         {
             var item = new LocationPin
             {
                 Position = args.Position.Coordinate.Point.Position,
                 Speed    = args.Position.Coordinate.Speed
             };
             if (DateTime.Now.Date == HistoryDatePicker.Date.Date)
             {
                 if (this.ViewModel.CheckedLocations.Count > 0)
                 {
                     var currentLoc = this.ViewModel.CheckedLocations.FirstOrDefault(loc => loc.IsCurrentLocation == true);
                     if (currentLoc != null && currentLoc.IsCurrentLocation)
                     {
                         this.ViewModel.CheckedLocations.Remove(currentLoc);
                     }
                 }
                 this.ViewModel.PinnedLocations.Add(item);
                 this.ViewModel.CheckedLocations.Add(new LocationPin {
                     Position = item.Position, IsCurrentLocation = true
                 });
                 bool isInView = false;
                 this.InputMap.IsLocationInView(new Geopoint(item.Position), out isInView);
                 if (isInView)
                 {
                     this.InputMap.Center = new Geopoint(item.Position);
                 }
             }
             await localData.InsertLocationDataAsync(item);
         }
     });
 }
Example #16
0
        public static async Task <MapRoute> getRoute(LocationPin destinationPin)
        {
            if (string.IsNullOrEmpty(destinationPin.Address))
            {
                return(null);
            }
            var currenLoc = await GetCurrentLocationAsync();

            var routeResultTask = MapRouteFinder.GetDrivingRouteAsync(
                currenLoc.Geopoint, destinationPin.Geopoint,
                MapRouteOptimization.TimeWithTraffic, MapRouteRestrictions.None);
            MapRouteFinderResult routeResult = await routeResultTask;

            if (routeResult.Status == MapRouteFinderStatus.Success)
            {
                destinationPin.CurrentTravelDistance = Math.Round(routeResult.Route.LengthInMeters * 0.00062137, 1); // convert to miles
                destinationPin.CurrentTravelTime     = (int)routeResult.Route.EstimatedDuration.TotalMinutes;
                if (routeResult.Status == MapRouteFinderStatus.Success)
                {
                    return(routeResult.Route);
                }
            }
            return(null);
        }
Example #17
0
        public int drawPolylines(LocationPin breakColorPin, bool isAddMilestone, MapControl map)
        {
            int ret = 0;

            //remove all current polylines on map
            map.MapElements.Clear();

            //Order points by DateCreated
            var    simpleGeoInDateOrder = this.PinnedLocations.OrderBy(x => x.DateCreated).ToList();
            var    color      = Colors.Blue;
            double thickness  = 3;
            var    Coords     = new List <BasicGeoposition>();
            bool   breakColor = false;

            //Query Points list to draw Polylines
            for (int i = 0; i < simpleGeoInDateOrder.Count; i++)
            {
                if (simpleGeoInDateOrder[i].IsCheckPoint == true && isAddMilestone)
                {
                    this.MileStoneLocations.Add(simpleGeoInDateOrder[i]);
                }
                if (Coords.Count == 0)
                {
                    Coords.Add(simpleGeoInDateOrder[i].Position);
                }
                else if (!breakColor && simpleGeoInDateOrder[i].DateCreated > breakColorPin.DateCreated)
                {
                    //define polyline
                    MapPolyline mapPolyline = new MapPolyline();
                    mapPolyline.StrokeColor     = color;
                    mapPolyline.StrokeThickness = thickness;
                    mapPolyline.StrokeDashed    = true;
                    mapPolyline.Path            = new Geopath(Coords);

                    //draw polyline on map
                    map.MapElements.Add(mapPolyline);
                    ret++;
                    //Clear Coords.
                    Coords.Clear();
                    if (simpleGeoInDateOrder[i].IsCheckPoint == false && isAddMilestone)
                    {
                        this.MileStoneLocations.Add(simpleGeoInDateOrder[i]);
                    }
                    breakColor = !breakColor;
                    color      = Colors.CornflowerBlue;
                    thickness  = 2;
                }
                else if (simpleGeoInDateOrder[i].DateCreated - simpleGeoInDateOrder[i - 1].DateCreated < TimeSpan.FromMinutes(5) && Coords.Count < 200)
                {
                    Coords.Add(simpleGeoInDateOrder[i].Position);
                }
                else
                {
                    //define polyline
                    MapPolyline mapPolyline = new MapPolyline();
                    mapPolyline.StrokeColor     = color;
                    mapPolyline.StrokeThickness = thickness;
                    mapPolyline.StrokeDashed    = true;
                    mapPolyline.Path            = new Geopath(Coords);

                    //draw polyline on map
                    map.MapElements.Add(mapPolyline);
                    ret++;
                    //Clear Coords.
                    Coords.Clear();
                    if (simpleGeoInDateOrder[i].IsCheckPoint == false && isAddMilestone)
                    {
                        this.MileStoneLocations.Add(simpleGeoInDateOrder[i]);
                    }
                }
            }
            //draw last Polyline on map
            if (Coords.Count > 1)
            {
                MapPolyline lastPolyline = new MapPolyline();
                lastPolyline.StrokeColor     = color;
                lastPolyline.StrokeThickness = thickness;
                lastPolyline.StrokeDashed    = true;
                lastPolyline.Path            = new Geopath(Coords);

                //draw polyline on map
                map.MapElements.Add(lastPolyline);
                ret++;
            }
            return(ret);
        }