How to know the available map Types (China) RRS feed

  • Question

  • Hi, I have an issue when accessing the map from china.

    I would like to know if a specific type of map is available when the script is loaded, so I can show/hide map layer switching functions depending on if the mapType is really accessible.

    When I call setMapType(MapTypeId.aerial) while the site is accessed in china, I get an error because the Aerial map type is not available.

    Solutions to this according to this forum seemed to call map.getOptions().supportedMapTypes, however these are not dynamically updated (If I set them to have road and aerial when creating the map, then asking for map.getOptions().supportedMapTypes returns aerial and road, even if aerial is not available, because I'm served for china).

    The other thing I tried was to use the MapTypeId.isValid(MapTypeId.aerial (tried with "a" too) ) but this returns true because it is validated statically, (so it is a valid "enum" value, not valid in the current context, so this doesnt help)

    When digging into the code, when calling setMapType on the map, some object are checked and eventually a getMapTypes() is called on one of those object, and tries to call the "a" map type on it, and this fails as THIS object knows what was really loaded, so there is a way to know it, but these objects seems private, I did not find in documentation a public access to that getMapTypes method.

    The only thing I see to detect this automatically would be to try to set the map type after loadign the map the first time in a try, and handle the error to disable my layer switching capabilities, but if it works (which is probably everywhere than china) then the map switching will likely work and cause useless traffic while it is in aerial, even though the user want road. So this is a no go.


    Raphael Lemieux

    Thursday, May 31, 2018 12:43 PM

All replies

  • Only road maps are available for China when in China. 

    [Blog] [twitter] [LinkedIn]

    Thursday, May 31, 2018 4:50 PM
  • Yes, I figured that out, but the code itself will not let me know, other than failing when it is asked to display another map type. (And we don't have different deployments for Chinese customers or not chinese, so I would have liked to know that this was not available from the code)
    Thursday, May 31, 2018 5:16 PM
  • Hi Raphael,

    There is a nice table here https://msdn.microsoft.com/en-us/library/dd435699.aspx but it doesn't really address your question of how you tell from within your code.

    Worst case you could test each type in the background for the region you are loading but I suspect that might add a bit of overhead.  My assumption is that https://www.bing.com/api/maps/sdk/mapcontrol/isdk/compactnavigationbar would only offer items that work.  Can you use that in your solution?



    Thursday, May 31, 2018 7:17 PM
  • Since I don't have control over the control itself, it is not where or as I would need it to be consistent with my UI. I could probably hack something together via CSS to make it look correct, but it would only hold as long as nothing changes, which is not good.

    I could also analyse the HTML code generated for a Navigation Bar and determine what classes are available, but again that would be forging my way through private code which is not meant to be tinkered with, and could change anytime, so it is neither a good option.

    Note that your suggestion gave me an idea, and if I use this "minified" navigation bar code while in China, the map control does appear, but clicking on it gives the same error than I get when basically replicating this tool (I mitigated by using a try catch around the setMapType, but what I'd like would be not to display the button if its not available):

    function loadMapScenario() {
      var navigationBarMode = Microsoft.Maps.NavigationBarMode;
      var map = new Microsoft.Maps.Map(document.getElementById('myMap'), {
          navigationBarMode: navigationBarMode.minified

    Clicking on the "switch layer" button causes a script error "Invalid map type ida".



    Thursday, May 31, 2018 8:04 PM
  • Hi Raphael,

    That is odd. When I tried it using the interactive SDK the options that were not available were grey, displayed but not available, so I guess my assumption was wrong!



    Thursday, May 31, 2018 8:19 PM
  • This is what I got using compact, minified, and default navigation bar, with the code I used. (default everything else)

    Note that the minified layer icon is not disabled, it just fails with a console error when clicked on.

    Thursday, May 31, 2018 8:51 PM
  • It looks like the only option is road. How are you selecting the failing options?
    Friday, June 1, 2018 1:24 AM
  • As I mentioned in the previous post, the layer icon in the minified view is not disabled, and tries to switch to Aerial Layer when clicked on.

    My workflow is really similar to that "minified" version of the UI, where we are simply allowing to toggle from Road to Aerial.

    Monday, June 11, 2018 2:26 PM