Exemple #1
0
        private static async Task <Osm> GetElementsInBoundingBox(Bounds bounds, NonAuthClient client, int depth = 0, int maxDepth = 3)
        {
            try
            {
                return(await client.GetMap(bounds));
            }
            catch (OsmApiException e)
            {
                if (!e.Message.Contains("limit is 50000") || depth > maxDepth)
                {
                    throw;
                }

                Log.LogInformation("Fetch area was too big. Splitting it into smaller pieces and re-trying.");
                var tasks = bounds.Quarter().Select(async quarter => await GetElementsInBoundingBox(quarter, client, depth + 1)).ToArray();
                Task.WaitAll(tasks);
                return(tasks.Select(t => t.Result).Merge());
            }
        }