public void LatLonRect_Miniaturize() { LatLonRect rect = LatLonRect.FromPointAndSpan(2, 4, -10, 18); var mini = rect.Miniaturize(new LatLon(5, 7)); var miniEnumerator = mini.GetEnumerator(); AssertExpectedException <InvalidOperationException>("Forgetting to MoveNext after creating enumerator", () => miniEnumerator.Current.ToString()); AssertExpectedVsActual("moveNext0", true, miniEnumerator.MoveNext()); AssertExpectedVsActual("enumeration0", LatLonRect.FromPointAndSpan(2, 4, -5, 6), miniEnumerator.Current); AssertExpectedVsActual("moveNext1", true, miniEnumerator.MoveNext()); AssertExpectedVsActual("enumeration1", LatLonRect.FromPointAndSpan(-3, 4, -5, 6), miniEnumerator.Current); AssertExpectedVsActual("moveNext2", true, miniEnumerator.MoveNext()); AssertExpectedVsActual("enumeration2", LatLonRect.FromPointAndSpan(2, 10, -5, 6), miniEnumerator.Current); AssertExpectedVsActual("moveNext3", true, miniEnumerator.MoveNext()); AssertExpectedVsActual("enumeration3", LatLonRect.FromPointAndSpan(-3, 10, -5, 6), miniEnumerator.Current); AssertExpectedVsActual("moveNext4", true, miniEnumerator.MoveNext()); AssertExpectedVsActual("enumeration4", LatLonRect.FromPointAndSpan(2, 16, -5, 6), miniEnumerator.Current); AssertExpectedVsActual("moveNext5", true, miniEnumerator.MoveNext()); AssertExpectedVsActual("enumeration5", LatLonRect.FromPointAndSpan(-3, 16, -5, 6), miniEnumerator.Current); AssertExpectedVsActual("moveNext6", false, miniEnumerator.MoveNext()); AssertExpectedException <InvalidOperationException>("Moving past end of enumerator", () => miniEnumerator.Current.ToString()); miniEnumerator.Reset(); AssertExpectedVsActual("moveNext0b", true, miniEnumerator.MoveNext()); AssertExpectedVsActual("enumeration0b", LatLonRect.FromPointAndSpan(2, 4, -5, 6), miniEnumerator.Current); }
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; }
public void LatLonRect_RectSubsetTests() { //LatLonRect rect = LatLonRect.FromNWSE(new LatLon(12, 4), new LatLon(2, 24)); LatLonRect rect = LatLonRect.FromPointAndSpan(2, 4, 10, 20); LatLonRect result = rect.ApplySubset(new RectSubset() { Left = 1, Right = 2, Top = 3, Bottom = 4 }); LatLonRect expected = LatLonRect.FromPointAndSpan(6, 5, 3, 17); AssertExpectedVsActual("rect1", expected, result); result = rect.ApplySubset(new RectSubset() { Left = 0.25, LeftScale = RectSubsetScale.Relative, Right = 0.5, RightScale = RectSubsetScale.Relative, Top = 0.1, TopScale = RectSubsetScale.Relative, Bottom = 0.2, BottomScale = RectSubsetScale.Relative }); expected = LatLonRect.FromPointAndSpan(4, 9, 7, 5); AssertExpectedVsActual("rect2", expected, result); result = rect.ApplySubset(new RectSubset() { Left = -0.25, LeftScale = RectSubsetScale.Relative, Right = 10, Top = 0.1, TopScale = RectSubsetScale.Relative, Bottom = 0.2, BottomScale = RectSubsetScale.Relative, BottomValueType = RectSubsetValueType.Length }); expected = LatLonRect.FromPointAndSpan(9, 1.5, 2, 12.5); AssertExpectedVsActual("rect3", expected, result); result = rect.ApplySubset(new RectSubset() { Left = 10, LeftValueType = RectSubsetValueType.Length, Top = 5, TopValueType = RectSubsetValueType.Length, RightValueType = RectSubsetValueType.Length, BottomValueType = RectSubsetValueType.Length }); expected = LatLonRect.FromPointAndSpan(4.5, 9, 5, 10); AssertExpectedVsActual("rect4", expected, result); }
public void LatLonRect_Intersects() { LatLonRect rect = new LatLonRect(8, 4, 2, -8); LatLonRect other = new LatLonRect(4, 10, 0, 0); AssertExpectedVsActual("intersects0", true, rect.Intersects(other)); other = new LatLonRect(4, 10, 0, 6); AssertExpectedVsActual("intersects1", false, rect.Intersects(other)); other = new LatLonRect(1, 10, 0, 0); AssertExpectedVsActual("intersects2", false, rect.Intersects(other)); other = new LatLonRect(12, 10, 10, 0); AssertExpectedVsActual("intersects3", false, rect.Intersects(other)); other = new LatLonRect(4, -20, 0, -10); AssertExpectedVsActual("intersects4", false, rect.Intersects(other)); }
public void LatLonRect_InstantiationTests() { LatLonRect rect = new LatLonRect(2, 3, 4, 5); LatLonRect expected = new LatLonRect(new LatLon(2, 3), new LatLon(4, 5)); AssertExpectedVsActual("rect1", expected, rect); rect = LatLonRect.FromPointAndSpan(new LatLon(4, 6), new LatLon(7, 8)); expected = new LatLonRect(11, 14, 4, 6); AssertExpectedVsActual("rect2", expected, rect); rect = LatLonRect.FromNWSE(new LatLon(5, 6), new LatLon(7, 8)); expected = new LatLonRect(5, 8, 7, 6); AssertExpectedVsActual("rect3", expected, rect); rect = LatLonRect.Parse("5, 6, 7, 8"); expected = new LatLonRect(5, 6, 7, 8); AssertExpectedVsActual("rect4", expected, rect); }
private void SetArea() { if (MainMap.ActualWidth > 0 && MainMap.ActualHeight > 0) { try { double width = MainMap.ActualWidth; double height = MainMap.ActualHeight; Geopoint nw; Geopoint se; MainMap.GetLocationFromOffset(new Point(0, 0), out nw); MainMap.GetLocationFromOffset(new Point(width, height), out se); Area = LatLonRect.FromNWSE(nw.ToLatLon(), se.ToLatLon()); } catch (ArgumentException) { Area = LatLonRect.NotAnArea; } } else { Area = LatLonRect.NotAnArea; } }
public static RetrievedData<IEnumerable<TransitStop>> GetTransitStopsForArea(LatLonRect area, DataSourcePreference preference) => RunSync(() => GetTransitStopsForAreaAsync(area, preference, CancellationToken.None));
public static async Task<RetrievedData<IEnumerable<TransitStop>>> GetTransitStopsForAreaAsync(LatLonRect area, DataSourcePreference preference, CancellationToken cancellationToken) { IEnumerable<TransitStop> resultStops = null; List<string> resultErrors = new List<string>(); List<Exception> resultExceptions = new List<Exception>(); foreach (var source in Sources) { if (cancellationToken.IsCancellationRequested) throw new OperationCanceledException(); if (!source.IsQualified(preference)) continue; if (source.CanGetTransitStopsForArea) { var sResult = await source.GetTransitStopsForArea(area, cancellationToken); if (sResult.HasData) { if (resultStops == null) resultStops = sResult.Data; else resultStops = resultStops.Union(sResult.Data); } if (sResult.ErrorMessage != null) resultErrors.Add(sResult.ErrorMessage); if (sResult.CaughtException != null) resultExceptions.Add(sResult.CaughtException); } } if (resultStops == null) resultStops = new TransitStop[] { }; return new RetrievedData<IEnumerable<TransitStop>>(resultStops, resultErrors.Count == 0 ? null : resultErrors.Aggregate("", (acc, err) => (acc == "" ? "" : ", ") + err), resultExceptions.Count == 0 ? null : new AggregateException(resultExceptions)); }
public MapView(LatLonRect area) { Area = area; }
public override Task <RetrievedData <IEnumerable <TransitStop> > > GetTransitStopsForArea(LatLonRect area, CancellationToken cancellationToken) { throw new NotImplementedException(); }
public override Task<RetrievedData<IEnumerable<TransitStop>>> GetTransitStopsForArea(LatLonRect area, CancellationToken cancellationToken) { throw new NotImplementedException(); }
public override Task<RetrievedData<IEnumerable<TransitStop>>> GetTransitStopsForArea(LatLonRect area, CancellationToken cancellationToken) { var result = MemoryCache.QueryStops(stop => area.ContainsLatLon(stop.Position)); return Task.FromResult(new RetrievedData<IEnumerable<TransitStop>>(result)); }
public void LatLonRect_GetNewRegionTests() { LatLonRect rect = new LatLonRect(8, 10, 4, 5); var reg = rect.GetNewRegion(new LatLonRect(7, 12, 4, 4)).ToList(); var expected = new LatLonRect(7, 12, 4, 10); if (!reg.Contains(expected)) { Assert.Fail($"GetNewRegion0: expected to contain {expected}, which it does not."); } reg.Remove(expected); expected = new LatLonRect(7, 5, 4, 4); if (!reg.Contains(expected)) { Assert.Fail($"GetNewRegion0: expected to contain {expected}, which it does not."); } reg.Remove(expected); if (reg.Count > 0) { Assert.Fail($"GetNewRegion0: result contains unexpected entries:{reg.Aggregate("", (acc, rct) => acc + $" ({rct.ToString()})")}."); } reg = rect.GetNewRegion(new LatLonRect(9, 12, 1, 1)).ToList(); expected = new LatLonRect(9, 10, 8, 5); if (!reg.Contains(expected)) { Assert.Fail($"GetNewRegion1: expected to contain {expected}, which it does not."); } reg.Remove(expected); expected = new LatLonRect(9, 12, 8, 10); if (!reg.Contains(expected)) { Assert.Fail($"GetNewRegion1: expected to contain {expected}, which it does not."); } reg.Remove(expected); expected = new LatLonRect(8, 12, 4, 10); if (!reg.Contains(expected)) { Assert.Fail($"GetNewRegion1: expected to contain {expected}, which it does not."); } reg.Remove(expected); expected = new LatLonRect(4, 12, 1, 10); if (!reg.Contains(expected)) { Assert.Fail($"GetNewRegion1: expected to contain {expected}, which it does not."); } reg.Remove(expected); expected = new LatLonRect(4, 10, 1, 5); if (!reg.Contains(expected)) { Assert.Fail($"GetNewRegion1: expected to contain {expected}, which it does not."); } reg.Remove(expected); expected = new LatLonRect(4, 5, 1, 1); if (!reg.Contains(expected)) { Assert.Fail($"GetNewRegion1: expected to contain {expected}, which it does not."); } reg.Remove(expected); expected = new LatLonRect(8, 5, 4, 1); if (!reg.Contains(expected)) { Assert.Fail($"GetNewRegion1: expected to contain {expected}, which it does not."); } reg.Remove(expected); expected = new LatLonRect(9, 5, 8, 1); if (!reg.Contains(expected)) { Assert.Fail($"GetNewRegion1: expected to contain {expected}, which it does not."); } reg.Remove(expected); if (reg.Count > 0) { Assert.Fail($"GetNewRegion1: result contains unexpected entries:{reg.Aggregate("", (acc, rct) => acc + $" ({rct.ToString()})")}."); } }
public abstract Task<RetrievedData<IEnumerable<TransitStop>>> GetTransitStopsForArea(LatLonRect area, CancellationToken cancellationToken);
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; }
public static async Task<TransitStop[]> GetTransitStopsForArea(LatLonRect area, CancellationToken cancellationToken) { if (area.Span.Latitude > 1 || area.Span.Longitude > 1) return null; List<TransitStop> result = new List<TransitStop>(); var responseString = await SendRequest("stops-for-location", new Dictionary<string, string>() { ["lat"] = area.Center.Latitude.ToString(), ["lon"] = area.Center.Longitude.ToString(), ["latSpan"] = area.Span.Latitude.ToString(), ["lonSpan"] = area.Span.Longitude.ToString() }, false, cancellationToken); if (cancellationToken.IsCancellationRequested) return null; StringReader reader = new StringReader(responseString); XDocument xDoc = XDocument.Load(reader); //XElement el = (XElement)xDoc.Nodes().First(d => d.NodeType == XmlNodeType.Element && ((XElement)d).Name.LocalName == "response"); XElement el = xDoc.Element("response").Element("data"); XElement elList = el.Element("list"); foreach (XElement el1 in elList.Elements("stop")) { result.Add(ParseTransitStop(el1)); } return result.ToArray(); }
public override Task<RetrievedData<IEnumerable<TransitStop>>> GetTransitStopsForArea(LatLonRect area, CancellationToken cancellationToken) { return Task.FromResult(new RetrievedData<IEnumerable<TransitStop>>(Stops.Where(stop => area.ContainsLatLon(stop.Position)))); }