Esempio n. 1
0
        private async Task <bool> SetUpForecastAsync(SimpleLocation location, bool showLoading = true)
        {
            if (showLoading)
            {
                ShowLoadingPanel(Common.GetLocalizedText("LoadingWeatherInfoText"));
            }

            try
            {
                CurrentLocation = location.Name;

                // Set the map center
                MapCenter = new Geopoint(location.Position);

                // Add pin
                MapLayers.Clear();
                AddPinToMap(new SimpleLocation(Common.GetLocalizedText("WeatherMapPinLabel"), location.Position.Latitude, location.Position.Longitude));

                // Retrieve weather information about location
                var weather = await WeatherProvider.Instance.GetGenericWeatherAsync(location.Position.Latitude, location.Position.Longitude);

                // Update the UI if weather is available
                if (weather != null)
                {
                    // Only set weather if it's not null
                    _weather = weather;

                    // Update weather-related UI
                    RefreshWeatherUI(_weather);

                    // Try to get sensor data
                    try
                    {
                        SensorTemperatureAndHumidity = await GetSensorTemperatureAndHumidityString();
                    }
                    catch (Exception ex)
                    {
                        LogService.WriteException(ex);
                    }

                    // Show proper weather panel
                    WeatherErrorPageVisibility = false;
                    WeatherControlVisibility   = true;
                    return(true);
                }
                else
                {
                    // Something went wrong so show the error panel
                    WeatherErrorPageVisibility = true;
                    WeatherControlVisibility   = false;
                }
            }
            finally
            {
                HideLoadingPanel();
            }
            return(false);
        }
Esempio n. 2
0
        private void ClearMapLayers()
        {
            foreach (var item in MapLayers)
            {
                CTRL_Map_Main.Layers.Remove(item);
            }

            MapLayers.Clear();
        }
Esempio n. 3
0
        private void Stops_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            // If we are running a switch command, don't do anything
            if (isSwitchCommandRunning)
            {
                // Perform re-routing mechanism here since we swapped
                // the indexes of our stops
                PerformReroutingOfPoints();
                return;
            }

            // If we have no more stops, clear our map layers and reset our
            // center to our default position
            if (Stops.Count == 0)
            {
                // Remove any pushpins
                MapLayers.Clear();

                // Set Center to default position
                Center = new Geopoint(defaultPosition);
                return;
            }

            // For old items, remove the map elements, for new items, add them
            if (e.OldItems != null)
            {
                foreach (var old in e.OldItems)
                {
                    StopModel stop = old as StopModel;

                    // Remove our removed stop from the map elements of its corresponding
                    // pushpin
                    if (mapElements.Any(x => ((MapIcon)x).Title == stop.Name))
                    {
                        mapElements.Remove(mapElements.Where(x => ((MapIcon)x).Title == stop.Name).First());
                    }
                }
            }

            if (e.NewItems != null)
            {
                foreach (var newItem in e.NewItems)
                {
                    StopModel stop         = newItem as StopModel;
                    var       stopGeopoint = new Geopoint(
                        new BasicGeoposition()
                    {
                        Latitude  = decimal.ToDouble(stop.Latitude),
                        Longitude = decimal.ToDouble(stop.Longitude)
                    });

                    var poi = new MapIcon
                    {
                        Location = stopGeopoint,
                        NormalizedAnchorPoint = new Point(0.5, 1.0),
                        Title  = stop.Name,
                        ZIndex = 0
                    };

                    // Add newly created pushpin to our map elements
                    mapElements.Add(poi);
                }
            }

            // Recreate the layer
            var layer = new MapElementsLayer
            {
                ZIndex      = 1,
                MapElements = mapElements
            };

            MapLayers.Clear();
            MapLayers.Add(layer);

            // Perform re-routing mechanism
            PerformReroutingOfPoints();
        }