예제 #1
0
        private async System.Threading.Tasks.Task UpdateImageries()
        {
            Collection  dataEntity     = lstCollections.SelectedValue as Collection;
            ImageryType dataSeriesType = (ImageryType)lstImageryTypes.SelectedValue;

            if (dataEntity != null && dataSeriesType != null)
            {
                showProgress.Visible = true;
                Client.ImageryQueryParameters query = new Client.ImageryQueryParameters {
                    collectionId = dataEntity.Id, imageryTypeId = dataSeriesType.Id
                };
                Result <List <Imagery> > result = await connection.SearchForImagery(query, cancelToken);

                showProgress.Visible = false;
                if (result.Code != ResultCode.ok || result.Value.Count == 0)
                {
                    MessageBox.Show("The specified collection does not have any imageries.");
                    return;
                }
                lstImageries.DataSource = result.Value;
            }
            else
            {
                lstImageries.DataSource = null;
            }
        }
예제 #2
0
        private async Task <IList <GameImageryItemViewModel> > GetImagesAsync(ImageryType imageType)
        {
            WebClient client      = new WebClient();
            string    downloadUrl = string.Format(balloonImageUrlFormat, Enum.GetName(typeof(ImageryType), imageType));
            var       dataString  = await client.DownloadStringTaskAsync(downloadUrl);

            var images = JsonConvert.DeserializeObject <IEnumerable <ImageProduct> > (dataString);

            return(images.Select(image => {
                return new GameImageryItemViewModel(image);
            }).ToList());
        }
예제 #3
0
    ///////////////////////////////////////////

    public static async Task RequestColor(string apiKey, ImageryType imageryType, BoundingBox regionBounds, Action <Tex, Vec3, Vec2> OnReceivedColor)
    {
        // Request an image from the maps API! This is the request package
        // that gets sent to the server, details about the arguments can be
        // found here:
        // https://github.com/microsoft/BingMapsRESTToolkit/blob/master/Docs/API%20Reference.md#ImageryRequest
        ImageryRequest request = new ImageryRequest()
        {
            MapArea     = regionBounds,
            MapWidth    = 1024,
            MapHeight   = 1024,
            ImagerySet  = imageryType,
            BingMapsKey = apiKey
        };
        // We need the meta response as well as the image response, since the
        // image API doesn't care too much about what we actually request!
        // The results it sends back can differ in size, bounds, image format,
        // so we need to know what we got!
        Task <Response> metaTask  = ServiceManager.GetResponseAsync(request);
        Task <Stream>   colorTask = ServiceManager.GetImageAsync(request);
        await Task.WhenAll(metaTask, colorTask);

        Response meta   = await metaTask;
        Stream   stream = await colorTask;

        // StatusCode is a web response status code, where 200-299 means
        // success. Details here:
        // https://developer.mozilla.org/en-US/docs/Web/HTTP/Status
        if (meta.StatusCode < 200 || meta.StatusCode >= 300)
        {
            Log.Warn("Bing Maps API error:\n" + string.Join('\n', meta.ErrorDetails));
            return;
        }

        // We need the result as a MemoryStream so we can grab the result as
        // an array of bytes.
        MemoryStream memStream = null;

        if (stream is MemoryStream)
        {
            memStream = (MemoryStream)stream;
        }
        else
        {
            stream.CopyTo(memStream);
        }

        // Send the image over to StereoKit, and turn it into a texture!
        Tex texture = Tex.FromMemory(memStream.ToArray());

        texture.AddressMode = TexAddress.Mirror;

        // Convert the image's bounds from lat/lon information into our
        // world's meters.
        BoundingBox bounds = new BoundingBox(meta.ResourceSets[0].Resources[0].BoundingBox);

        Geo.BoundsToWorld(regionBounds, bounds, out Vec3 size, out Vec2 center);

        // Done! Pass the results back.
        OnReceivedColor(texture, size, center);
    }