public async Task <WalkerResponse> MakeRequest(string body)
        {
            var request = new HttpRequestMessage
            {
                Method     = HttpMethod.Get,
                RequestUri = new Uri(SERVER_URL),
                Content    = new StringContent(body, Encoding.UTF8)
            };

            var response = await client.SendAsync(request).ConfigureAwait(false);

            response.EnsureSuccessStatusCode();

            var responseBody = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

            return(WalkerResponse.FromJson(responseBody));
        }
示例#2
0
 private void ProcessTileResponse(WalkerResponse walkerResponse)
 {
     foreach (Element element in walkerResponse.elements)
     {
         if (element.type == "node")
         {
             if (!nodes.ContainsKey(element.id))
             {
                 nodes.Add(element.id, new Node(element));
             }
         }
         else if (element.type == "way")
         {
             if (!ways.ContainsKey(element.id))
             {
                 ways.Add(element.id, new Way(element));
             }
         }
     }
 }
示例#3
0
        public async Task LoadTile(Tile tile)
        {
            Console.WriteLine("Loading tile {0}", tile);

            string bodyFormat =
                "[out:json];" +
                "node({0}, {1}, {2}, {3});" +
                "way(bn);" +
                "(._; node(w););" +
                "out;";
            string         body           = string.Format(bodyFormat, tile.Lat1, tile.Lon1, tile.Lat2, tile.Lon2);
            WalkerResponse walkerResponse = await networkingManager.MakeRequest(body).ConfigureAwait(false);

            Console.WriteLine("Processing tile {0}", tile);

            ProcessTileResponse(walkerResponse);

            Console.WriteLine("Done loading tile {0}", tile);
            loadedTiles.Add(tile);
        }