Exemple #1
0
 private void OnAreaChanged(LatLonRect oldArea, LatLonRect newArea)
 {
     if ((ZoomLevel < SmallThreshold && lastZoomLevel != -1) || (newArea.Span.Latitude > MAX_LAT_RANGE * 8 || newArea.Span.Longitude > MAX_LON_RANGE * 8))
     {
         ShownStops.Clear();
         PendingRegions.Clear();
     }
     else
     {
         IEnumerable <LatLonRect> newRegion;
         if (lastZoomLevel < SmallThreshold)
         {
             newRegion = new LatLonRect[] { newArea }
         }
         ;
         else
         {
             newRegion = oldArea.GetNewRegion(newArea);
         }
         AppendRegions(newRegion);
         if (!IsBusy)
         {
             RefreshShownStops(TokenSource.Token, !ManuallyDownloadStops);
         }
     }
     lastZoomLevel = ZoomLevel;
 }
Exemple #2
0
        protected async void RefreshShownStops(CancellationToken token, bool download = false)
        {
            IsBusy = true;
            try
            {
                if (ZoomLevel < SmallThreshold)
                {
                    ShownStops.Clear();
                }
                else
                {
                    //var toRemove = ShownStops.Where(stop => !Area.ContainsLatLon(stop.Position)).ToArray();
                    //ShownStops.RemoveRange(toRemove);
                    var area = Area;
                    for (int i = 0; i < ShownStops.Count; i++)
                    {
                        if (!area.ApplySubset(OuterStopCacheMargin).ContainsLatLon(ShownStops[i].Position))
                        {
                            ShownStops.RemoveAt(i);
                            i--;
                        }
                    }
                    var fwtc = MemoryCache.GetStop("FWTC");
                    if (fwtc.HasValue && area.ContainsLatLon(fwtc.Value.Position))
                    {
                        ShownStops.Add(fwtc.Value);
                    }
                    while (PendingRegions.Count > 0)
                    {
                        var region = PendingRegions.Dequeue();
                        //var fwtc = new string[] { "1_80439", "1_80431", "1_80438", "1_80432", "1_80437", "1_80433", "3_27814", "3_29410" };
                        if (region.Intersects(area))
                        {
                            var sResult = await DataSource.GetTransitStopsForAreaAsync(region, download?DataSourcePreference.All : DataSourcePreference.OfflineSources, token);

                            var stops = sResult.Data.Where(stop => !ShownStops.Contains(stop));
                            //var fwtcStop = new TransitStop() { ID = "FWTC", Position = new LatLon(47.31753, -122.30486), Path = "_vx_HlnniVF??LJ??MF??nIG??MK??LG?", Name = "Federal Way Transit Center" };
                            //TransitStop.SqlProvider.Insert(fwtcStop, DatabaseManager.MemoryDatabase);
                            if (stops == null)
                            {
                                return;
                            }
                            Cache.Add(stops.ToArray());
                            ShownStops.AddRange(stops);
                        }
                        //foreach (var stop in stops)
                        //{
                        //    if (!ShownStops.Any(stp => stp.ID == stop.ID))
                        //        ShownStops.Add(stop);
                        //}
                    }
                }
            }
            catch (HttpRequestException)
            {
                PendingRegions.Clear();
            }
            catch (OperationCanceledException)
            {
            }
            finally
            {
                IsBusy = false;
            }
        }