none
Error loading Microsoft.Maps.SpatialDataService for first time IE11 RRS feed

  • Question

  • I have code that is throwing an error on the first load in IE 11.

    When the map is rendered, I create a new layer, pass an array of country names to the getBoundary method and set the polygons on the layer which is then added to the map.

    On the initial load, the below code runs

    Microsoft.Maps.loadModule('Microsoft.Maps.SpatialDataService', function () {
                Microsoft.Maps.SpatialDataService.GeoDataAPIManager.getBoundary(
                    countries,
                    { entityType: 'CountryRegion' },
                    map,
                    setInitStatus.bind(layer));
                map.layers.insert(layer);
            });

    I have stepped through the code and found that the error is being thrown from the very first line, the loadModule method resulting in the callback not being fired. The error thrown is as follows.

    mapcontrol (339,17) - Unable to get property 'prototype' of undefined or null reference 

    However, I also use this module to create further layers with country boundaries which uses the same loadModule method and that works fine, which is the same code that is failing in the first initial load.

    Any ideas or workarounds?

    Above code works fine in Chrome.

    Friday, July 1, 2016 3:52 PM

Answers

  • I'm unable to reproduce this. Do you define the layer earlier in your code i.e. var layer = new Microsoft.Maps.Layer(); ?

    I'm assuming that "setInitStatus.bind(layer)", generates a callback function. Verify that this callback function handles the case where the length of the returned result array is 0. If an error occurs or a boundary can't be found for a query, the callback function is still triggered as the response includes the query so you can figure out what didn't process. The results property of the response will be an array with 0 length.

    Also try running your code against the experimental branch to see if that makes a difference. To do this, add "&branch=experimental" to the map script URL.


    [Blog] [twitter] [LinkedIn]


    Friday, July 1, 2016 7:36 PM
  • Try only loading the spatial data service module once. Since the getboundary call is async the second module is likely being loaded and overriding the first bit before the boundaries were returned. You only need to load a module once and then it is available for as long as the page is open.

    Also verify your countries array is an array of string and that there are values in it.

    also


    [Blog] [twitter] [LinkedIn]

    Monday, July 4, 2016 3:45 AM

All replies

  • I'm unable to reproduce this. Do you define the layer earlier in your code i.e. var layer = new Microsoft.Maps.Layer(); ?

    I'm assuming that "setInitStatus.bind(layer)", generates a callback function. Verify that this callback function handles the case where the length of the returned result array is 0. If an error occurs or a boundary can't be found for a query, the callback function is still triggered as the response includes the query so you can figure out what didn't process. The results property of the response will be an array with 0 length.

    Also try running your code against the experimental branch to see if that makes a difference. To do this, add "&branch=experimental" to the map script URL.


    [Blog] [twitter] [LinkedIn]


    Friday, July 1, 2016 7:36 PM
  • Thanks for the reply, for completeness here are the methods in full.

    LayerId = 'init' and the countries array is filled.

    As I mentioned before, the execution doesn't get to the method below.

    Microsoft.Maps.SpatialDataService.GeoDataAPIManager.getBoundary()
    function addCountriesToInitLayer(mapdata, layerid) {
            var countries = [],
                admindivisions = [],
                layer = new Microsoft.Maps.Layer(layerid);
    
            countries = getUniqueValuesFromCollection(mapdata, 'GFCCountry');
            admindivisions = getAdminDivisionsFromCountries(countries);
            countries = removeItemsFromArray(countries, constants.AdminDivisions);
    
            Microsoft.Maps.loadModule('Microsoft.Maps.SpatialDataService', function () {
                Microsoft.Maps.SpatialDataService.GeoDataAPIManager.getBoundary(
                    countries,
                    { entityType: 'CountryRegion' },
                    map,
                    setInitStatus.bind(layer));
                map.layers.insert(layer);
            });
    
            if (admindivisions.length > 0) {
                Microsoft.Maps.loadModule('Microsoft.Maps.SpatialDataService', function () {
                    Microsoft.Maps.SpatialDataService.GeoDataAPIManager.getBoundary(
                        admindivisions,
                        { entityType: 'AdminDivision1' },
                        map,
                        setInitStatus.bind(layer));
                    map.layers.insert(layer);
                });
            }
        }
    function setInitStatus(data) {
            if (data.results && data.results.length > 0) {
                for (var i = 0; i < data.results[0].Polygons.length; i++) {
                    var polygon = data.results[0].Polygons[i],
                        location = data.location,
                        options = constants.PolygonOptions.Purple;
    
                    Microsoft.Maps.Events.addHandler(polygon, 'click', onMapCountryClick.bind(location));
                    polygon.setOptions(options);
                    this.add(polygon);
                }
            }
        }
    I'll try the experimental branch and let you know if that helps.


    Sunday, July 3, 2016 9:25 AM
  • Try only loading the spatial data service module once. Since the getboundary call is async the second module is likely being loaded and overriding the first bit before the boundaries were returned. You only need to load a module once and then it is available for as long as the page is open.

    Also verify your countries array is an array of string and that there are values in it.

    also


    [Blog] [twitter] [LinkedIn]

    Monday, July 4, 2016 3:45 AM