MapTileBitmapRequest MapTileBitmapRequest MapTileBitmapRequest MapTileBitmapRequest Class

Definition

Represents a bitmap request for a tile for a CustomMapTileDataSource.

public : sealed class MapTileBitmapRequest : IMapTileBitmapRequestpublic sealed class MapTileBitmapRequest : IMapTileBitmapRequestPublic NotInheritable Class MapTileBitmapRequest Implements IMapTileBitmapRequest// This API is not available in Javascript.
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Remarks

For more info about using the CustomMapTileDataSource, see the PixelData property of the MapTileBitmapRequest.

Constructors

MapTileBitmapRequest() MapTileBitmapRequest() MapTileBitmapRequest() MapTileBitmapRequest()

Initializes a new instance of MapTileBitmapRequest class.

public : MapTileBitmapRequest()public MapTileBitmapRequest()Public Sub New()// This API is not available in Javascript.
See Also

Properties

PixelData PixelData PixelData PixelData

Gets the bitmap data for the CustomMapTileDataSource.

public : IRandomAccessStreamReference PixelData { get; set; }public IRandomAccessStreamReference PixelData { get; set; }Public ReadWrite Property PixelData As IRandomAccessStreamReference// This API is not available in Javascript.

Remarks

CustomMapTileDataSource supports drawing tiles in memory and returning them as a stream of pixels. The following code sample demonstrates one approach for drawing tiles in memory.

        // Create new custom tile source
        CustomMapTileDataSource customDataSource = new CustomMapTileDataSource();
        customDataSource.BitmapRequested += customDataSource_BitmapRequestedAsync;
        customTileSource = new MapTileSource(customDataSource);



        /// <summary>
        /// BitmapRequested event handler for CustomMapTileDataSource.BitmapRequested event
        /// </summary>
        /// <param name="sender">sender</param>
        /// <param name="args">args for ZoomLevel, X, Y and the PixelData</param>
        private async void customDataSource_BitmapRequestedAsync(CustomMapTileDataSource sender, MapTileBitmapRequestedEventArgs args)
        {
            var deferral = args.Request.GetDeferral();
            args.Request.PixelData = await CreateBitmapAsStreamAsync();
            deferral.Complete();
        }

        /// <summary>
        /// Create memory buffer with length of 256 * 256 * 4.  
        /// This memory buffer is holding 256 * 256 pixels
        /// </summary>
        /// <returns>memory buffer that fills with red opaque pixels.</returns>
        private async Task<Windows.Storage.Streams.RandomAccessStreamReference> CreateBitmapAsStreamAsync()
        {
            int pixelHeight = 256;
            int pixelWidth = 256;
            int bpp = 4;

            byte[] bytes = new byte[pixelHeight * pixelWidth * bpp];

            for (int y = 0; y < pixelHeight; y++)
            {
                for (int x = 0; x < pixelWidth; x++)
                {
                    int pixelIndex = y * pixelWidth + x;
                    int byteIndex = pixelIndex * bpp;

                    bytes[byteIndex] = 0xff;        // Red
                    bytes[byteIndex + 1] = 0x00;    // Green
                    bytes[byteIndex + 2] = 0x00;    // Blue
                    bytes[byteIndex + 3] = 0x80;    // Alpha (0xff = fully opaque)
                }
            }

            // Create RandomAccessStream from byte array
            InMemoryRandomAccessStream randomAccessStream = new InMemoryRandomAccessStream();
            IOutputStream outputStream = randomAccessStream.GetOutputStreamAt(0);
            DataWriter writer = new DataWriter(outputStream);
            writer.WriteBytes(bytes);
            await writer.StoreAsync();
            await writer.FlushAsync();
            return RandomAccessStreamReference.CreateFromStream(randomAccessStream);
        }
InMemoryRandomAccessStream^ TileSources::CustomRandomAccessSteram::get()
{
       int pixelHeight = 256;
       int pixelWidth = 256;
       int bpp = 4;

       Array<byte>^ bytes = ref new Array<byte>(pixelHeight * pixelWidth * bpp);

       for (int y = 0; y < pixelHeight; y++)
       {
              for (int x = 0; x < pixelWidth; x++)
              {
                     int pixelIndex = y * pixelWidth + x;
                     int byteIndex = pixelIndex * bpp;

                     // Set current pixel bytes
                     bytes[byteIndex] = (byte)(std::rand() % 256);        // Red
                     bytes[byteIndex + 1] = (byte)(std::rand() % 256);    // Green
                     bytes[byteIndex + 2] = (byte)(std::rand() % 256);    // Blue
                     bytes[byteIndex + 3] = (byte)((std::rand() % 56) + 200);    // Alpha (0xff = fully opaque)
              }
       }

       // Create RandomAccessStream from byte array
       InMemoryRandomAccessStream^ randomAccessStream = ref new InMemoryRandomAccessStream();
       IOutputStream^ outputStream = randomAccessStream->GetOutputStreamAt(0);
       DataWriter^ writer = ref new DataWriter(outputStream);
       writer->WriteBytes(bytes);

       create_task(writer->StoreAsync()).then([writer](unsigned int)
       {
              create_task(writer->FlushAsync());
       });

       return randomAccessStream;
}
See Also

Methods

GetDeferral() GetDeferral() GetDeferral() GetDeferral()

Gets a MapTileBitmapRequestDeferral that the app can use to respond asynchronously to the bitmap request.

public : MapTileBitmapRequestDeferral GetDeferral()public MapTileBitmapRequestDeferral GetDeferral()Public Function GetDeferral() As MapTileBitmapRequestDeferral// This API is not available in Javascript.
Returns

The deferral object that the app uses to indicate that it has finished responding to a BitmapRequested event and that the request is complete.

See Also

See Also