none
HttpMapTileDataSource.AdditionalRequestHeaders does not add to the request header RRS feed

  • Question

  • I'm adding request headers with the following code example, and I'm expecting to see the information I've added in the request header.
    When I follow and review the request header (Telerik Fiddler 4) I can not see the information I added.
    I don't know what's wrong with the code. Can you help me?
    Thank you in advance.


    private HttpMapTileDataSource _dataSource;
    public GmHttpTileDataSourceFactory()
    {
    _dataSource = new HttpMapTileDataSource("https://tile.openstreetmap.org/{zoomlevel}/{x}/{y}.png");           
    _dataSource.AdditionalRequestHeaders.Add("Accept-Language", "en");
    _dataSource.AdditionalRequestHeaders.Add("Key", "Value");
    _dataSource.AdditionalRequestHeaders.Add("blabla", "blabla");
    }


    HttpMapTileDataSource.AdditionalRequestHeaders does not add to the request header
    HttpMapTileDataSource.AdditionalRequestHeaders does not add to the request header
    I'm adding request headers with the following code example
    I'm adding request headers with the following code example
    I'm adding request headers with the following code example
    Thursday, August 8, 2019 5:37 PM

Answers

  • Hi Mustafa,

    Members of the Bing maps dev team have taken a look at your post and believe it should work but would need more details to dig further. Without that detail, they have the following suggestion "An easy workaround would be to use the CustomMapTileDataSource and make the request directly from user code where they can add any headers they want."

    Sincerely,

    IoTGirl 

    Monday, August 12, 2019 5:18 PM
    Owner

All replies

  • Hi Mustafa,

    Members of the Bing maps dev team have taken a look at your post and believe it should work but would need more details to dig further. Without that detail, they have the following suggestion "An easy workaround would be to use the CustomMapTileDataSource and make the request directly from user code where they can add any headers they want."

    Sincerely,

    IoTGirl 

    Monday, August 12, 2019 5:18 PM
    Owner
  • Thank you for your suggestion.
    I have already tried 'CustomMapTileDataSource'. 
    But I want to use 'HttpMapTileDataSource' cache capability, and I need to manage the request headers.
    I briefly summarize the problem.
    I can't see the request headers that I added to the HttpMapTileDataSource object with the AdditionalRequestHeaders method when I follow the request.
    How do I give more information about the problem? 
    What should I do ?
    Thank you very much for your interest.
    Tuesday, August 13, 2019 10:49 AM
  • It does not work for me either. Can you ask them to have another look? 
    Monday, August 17, 2020 7:36 PM
  • Hi T. Partl,

    Did you use the work around suggested?

    Sincerely,

    IoTGirl

    Monday, August 17, 2020 9:33 PM
    Owner
  • Yes I did but either the map didn't load at all (the BitmapRequested event was only called one single time) or the loaded images didn't look right (had a black bar of variable size on the bottom). Also, the loading times were unusable slow compared to when using HttpMapTileDataSource. Maybe you can share some code that I should try?
    Monday, August 17, 2020 9:40 PM
  • There is sample code in the docs...https://docs.microsoft.com/en-us/windows/uwp/maps-and-location/overlay-tiled-images.  The performance will be dependent on the availability and speed of your tile source.  My suspicion as the "black bar" is of variable size, your contents is getting served very slowly to your map application or the tile definition is off somehow?

    Monday, August 17, 2020 9:54 PM
    Owner
  • When using a CustomMapTileDatasource, the speed of requesting tiles is entirely up to the application developer. You need to make sure to not block the callback making a synchronous network request for example to get the best throughput. Decoding the image is also up to the application so I would check to make sure you're using a fast image decoder and creating the right size tile and image buffer.
    Monday, August 17, 2020 10:05 PM
    Moderator
  • So these are the options I tried:

    var url = $"https://maps.wikimedia.org/osm-intl/{args.ZoomLevel}/{args.X}/{args.Y}.png";
    var bytes = await new HttpClient().GetByteArrayAsync(url);
    
    IRandomAccessStream randomAccessStream;
    if (false) // OPTION 1
    {
        randomAccessStream = bytes.AsBuffer().AsStream().AsRandomAccessStream();
    }
    else if (false) // OPTION 2
    {
        randomAccessStream = new MemoryStream(bytes).AsRandomAccessStream();
    }
    else if (false) // OPTION 3
    {
        var memStream = new MemoryStream(bytes);
        randomAccessStream = new InMemoryRandomAccessStream();
        await randomAccessStream.WriteAsync(bytes.AsBuffer());
        randomAccessStream.Seek(0); // Just to be sure.
    }
    else if (false) // OPTION 4
    {
        randomAccessStream = new InMemoryRandomAccessStream();
        IOutputStream outputStream = randomAccessStream.GetOutputStreamAt(0);
        DataWriter writer = new DataWriter(outputStream);
        writer.WriteBytes(bytes);
        await writer.StoreAsync();
        await writer.FlushAsync();
    }
    else if (true) // OPTION 5
    {
        var decoder = await BitmapDecoder.CreateAsync(new MemoryStream(bytes).AsRandomAccessStream());
        var pixelProvider = await decoder.GetPixelDataAsync(BitmapPixelFormat.Rgba8, BitmapAlphaMode.Straight,
            new BitmapTransform(), ExifOrientationMode.RespectExifOrientation, ColorManagementMode.ColorManageToSRgb)
            .AsTask().ConfigureAwait(false);
        var pixels = pixelProvider.DetachPixelData();
    
        randomAccessStream = new InMemoryRandomAccessStream();
        var outputStream = randomAccessStream.GetOutputStreamAt(0);
        var writer = new DataWriter(outputStream);
        writer.WriteBytes(pixels);
        await writer.StoreAsync();
        await writer.FlushAsync();
    }
    
    args.Request.PixelData = RandomAccessStreamReference.CreateFromStream(randomAccessStream);
    

    Option 1 & 2 got my whole app stuck and no single tile appeared

    Option 3 & 4 lead to the unwanted behavior that can be seen in the screenshot below

    Only option 5 worked, but was awfully slow. When I scrolled fast for just 5 seconds, you could visually see the app trying to catch up with all the requests for another 10 seconds or so (and I have a fast internet + PC). There's also no CancellationToken that I could use to cancel requests that are not needed any more. I can't see how this could be a viable option for any app that allows users to browse the map. Or am I missing something? Is there a optimization that could marginally improve the performance?

    And, what I would be most interested in: Is this bug regarding HttpMapTileDataSourceactually known by the developer team and expected to be fixed at some point?

    Tuesday, August 18, 2020 7:43 AM
  • The code shown doesn't show the full callback, but if you're awaiting in a callback you need to request a deferral as shown here:

    https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.controls.maps.maptilebitmaprequest.pixeldata?view=winrt-19041

    In the first 4 options you show, you're not decoding the response stream at all. You need to decode the response stream (JPG, PNG, etc.) to RGB pixels otherwise you're just getting garbage.

    Tuesday, August 18, 2020 6:42 PM
    Moderator
  • Doesn't seem that I was getting complete garbage without the decode step as you can see on my screenshot, some decoding must have taken place.

    I didn't post the full callback, I was getting the referral and calling Complete on it.

    Well, guess there's no usable way for me to use the http tiles with Headers then...

    Tuesday, August 18, 2020 8:06 PM