none
using map in WindowsForms.WebBrowser control, refresh issue RRS feed

  • Question

  • Hi,

    I have WebBrowser control (windows forms desktop app, c#, .net 4.6.2) with which I display a map. I have prepared necessary html document as string and I load it into WebBrowser.DocumentText property. All is good so far. But when I hide-then-show the form on which control sits on, it causes sort of a refresh in webbrowser - document's body onload event is fired, but previously created javascript map object is ready from original load, but it doesn't show. When i try just to recreate it from scratch - it doesn't load fully - for example street names are missing. So how can I properly refresh map object in this scenario?

    Thursday, March 22, 2018 12:21 PM

Answers

  • Can you try this sample code: https://code.msdn.microsoft.com/bing/Using-the-Bing-Maps-V8-Web-07e21f3a?redir=0

    I am unable to repro your issue. What objects and modules are you loading on the map? If you can share some code it would be helpful. Also are you loading the map synchronously or asynchronously? 

    Thursday, March 22, 2018 2:09 PM
    Moderator

All replies

  • Can you try this sample code: https://code.msdn.microsoft.com/bing/Using-the-Bing-Maps-V8-Web-07e21f3a?redir=0

    I am unable to repro your issue. What objects and modules are you loading on the map? If you can share some code it would be helpful. Also are you loading the map synchronously or asynchronously? 

    Thursday, March 22, 2018 2:09 PM
    Moderator
  • tried both sync and async - no luck.
    Not able to share full code right now, but my scenario is bit different than given sample:
    I have a main form which is MDIparent. Then I create MDI child form which contains webbrowser control with map.
    I have a button on the main MDI parent form which does childForm.Visible = !childForm.Visible;
    Issue seems to be related to changing MDIchild form's .Visible property (or executing it's Hide()/Show() methods) because just making the webbrowser control not visible, then visible, is ok.
    Another thing is i am not using WebBrowser.Navigate(new Uri(htmlPath));
    i have source of html as string hardcoded and i assign it to webbrowser.DocumentText. I don't want users to load random htmls into the control.

    this is my GetMap part:

    var searchManager;
    var layer;
    var infobox;
    var map;

    function myOnLoadMap()
    {
    if (searchManager == null)
    {
    searchManager = new Microsoft.Maps.Search.SearchManager(map);
    }
    }

    function GetMap()
    {
    map = new Microsoft.Maps.Map('#myMap', {
    credentials:'mykey',
    mapTypeId: Microsoft.Maps.MapTypeId.road,
    zoom: 4
    });

    infobox = new Microsoft.Maps.Infobox(new Microsoft.Maps.Location(0.0, 0.0), { visible: false });
    infobox.setMap(map);

    layer = new Microsoft.Maps.Layer();
    map.layers.insert(layer);

    Microsoft.Maps.loadModule('Microsoft.Maps.Search', myOnLoadMap);
    }


    • Edited by mrcnbld Friday, March 23, 2018 11:25 AM
    Thursday, March 22, 2018 5:06 PM