예제 #1
0
        private async void MapPinElementMapPinTapped(object sender,
                                                     MapPinTappedEventArgs e)
        {
            MapPin mapPinElement = (MapPin)sender;

            if (mapPinElement.Focused)
            {
                if (e.Marked)
                {
                    await _mapLocationAccess.Add(
                        DataSourceType.Sqlite,
                        new MapLocationModel
                    {
                        ID          = Guid.NewGuid(),
                        Name        = mapPinElement.Name,
                        Description = mapPinElement.Description,
                        Latitude    = mapPinElement.Latitude.ToString(),
                        Longitude   = mapPinElement.Longitude.ToString(),
                        MapId       = _map.ID
                    });

                    MapLocationModel addedLocation = _mapLocations.FirstOrDefault(location =>
                                                                                  location.Latitude == mapPinElement.Latitude.ToString() &&
                                                                                  location.Longitude == location.Longitude);
                    if (addedLocation != null)
                    {
                        mapPinElement.ID = addedLocation.ID;
                    }

                    _mapPins.Add(mapPinElement);
                }
                else
                {
                    MapLocationModel deleteLocation = _mapLocations.FirstOrDefault(location =>
                                                                                   location.ID.Equals(mapPinElement.ID));
                    if (deleteLocation != null)
                    {
                        await _mapLocationAccess.Remove(DataSourceType.Sqlite, deleteLocation);
                    }

                    _mapPins.Remove(mapPinElement);
                }
            }

            _lastFocusedMapPin = _focusedMapPin;
            _focusedMapPin     = mapPinElement;

            if (_lastFocusedMapPin != null)
            {
                _lastFocusedMapPin.UnFocus();
            }

            if (!_focusedMapPin.Focused)
            {
                _focusedMapPin.Focus();
            }
        }
예제 #2
0
        private async void MapPinElementMapPinTapped(object sender,
            MapPinTappedEventArgs e)
        {
            MapPin mapPinElement = (MapPin)sender;

            if (mapPinElement.Focused)
            {
                if (e.Marked)
                {
                    await _mapLocationAccess.Add(
                        DataSourceType.Sqlite,
                        new MapLocationModel
                    {
                        ID = Guid.NewGuid(),
                        Name = mapPinElement.Name,
                        Description = mapPinElement.Description,
                        Latitude = mapPinElement.Latitude.ToString(),
                        Longitude = mapPinElement.Longitude.ToString(),
                        MapId = _map.ID
                    });

                    MapLocationModel addedLocation = _mapLocations.FirstOrDefault(location =>
                        location.Latitude == mapPinElement.Latitude.ToString() &&
                        location.Longitude == location.Longitude);
                    if (addedLocation != null)
                        mapPinElement.ID = addedLocation.ID;

                    _mapPins.Add(mapPinElement);
                }
                else
                {
                    MapLocationModel deleteLocation = _mapLocations.FirstOrDefault(location =>
                        location.ID.Equals(mapPinElement.ID));
                    if (deleteLocation != null)
                        await _mapLocationAccess.Remove(DataSourceType.Sqlite, deleteLocation);

                    _mapPins.Remove(mapPinElement);
                }
            }

            _lastFocusedMapPin = _focusedMapPin;
            _focusedMapPin = mapPinElement;

            if (_lastFocusedMapPin != null)
                _lastFocusedMapPin.UnFocus();

            if (!_focusedMapPin.Focused)
                _focusedMapPin.Focus();
        }