none
Uncaught TypeError: Cannot read property 'targetViewChanged' of null RRS feed

  • Question

  • Hi, 

    I am getting below error from Bing map API in JavaScript console. 

    4d1324b4.js?bu=rms+answers+MapsSDKRelease+AnonymousBegin*SDKPluginStart*SDKInfoboxOverlay*Infobox*S…:1 Uncaught TypeError: Cannot read property 'targetViewChanged' of null
        at 4d1324b4.js?bu=rms+answers+MapsSDKRelease+AnonymousBegin*SDKPluginStart*SDKInfoboxOverlay*Infobox*S…:1
    (anonymous) @ 4d1324b4.js?bu=rms+answers+MapsSDKRelease+AnonymousBegin*SDKPluginStart*SDKInfoboxOverlay*Infobox*S…:1

    It started recently. earlier this error was not there. 

    Thanks

    Ramesh Chandra

    Wednesday, August 9, 2017 7:46 PM

Answers

  • Internally there is a property with that name, just wanted to make sure you weren't using the old V7 events that were in the API with the same name as those are no longer supported. 

    Is the map hidden when you are trying to load it? If so this may be the cause of the issue. 

    Are you calling the loadMap function via the callback URL parameter in the Bing Maps script URL? If not, you may want to give this a try as this will ensure the map source code is loaded before your code starts trying to load it. For example: 

    <script type='text/javascript' src='http://www.bing.com/api/maps/mapcontrol?callback=loadMap' async defer></script>

    Are you using any JavaScript frameworks? If so, which ones, so we can test to ensure there is no compatibility issues.


    [Blog] [twitter] [LinkedIn]

    Thursday, August 10, 2017 9:13 PM
  • Is the map div hidden when loading the map? The error you are seeing typically only occurs when loading the map when it is hidden or when the map script hasn't finished downloading which I suspect may be the issue. How/when do you call the loadMap function?

    [Blog] [twitter] [LinkedIn]

    Thursday, August 10, 2017 11:53 PM

All replies

  • Can you provide a code sample that reproduces this issue? There is no targetViewChanged event in V8 like there was in V7.

    [Blog] [twitter] [LinkedIn]

    Thursday, August 10, 2017 4:49 PM
  • here is the code

    function loadMap() {
            var mapDiv = document.getElementById('myTripsMap');
            if (mapDiv) {
                try {
                    $scope.bingMap = new Microsoft.Maps.Map(mapDiv, {
                        credentials: commonSharedService.BingMapKey || globalDefaultValues.BingMapKey,
                        showMapTypeSelector: false
                    });
                }
                catch (e) {
                    console.log('Error in loading map: ' + e);
                    return;
    			}
    			....  code removed intensionally
    		}
    	}

    I can clearly see a targetViewChanged in V8 code:

    



    Thursday, August 10, 2017 8:16 PM
  • Internally there is a property with that name, just wanted to make sure you weren't using the old V7 events that were in the API with the same name as those are no longer supported. 

    Is the map hidden when you are trying to load it? If so this may be the cause of the issue. 

    Are you calling the loadMap function via the callback URL parameter in the Bing Maps script URL? If not, you may want to give this a try as this will ensure the map source code is loaded before your code starts trying to load it. For example: 

    <script type='text/javascript' src='http://www.bing.com/api/maps/mapcontrol?callback=loadMap' async defer></script>

    Are you using any JavaScript frameworks? If so, which ones, so we can test to ensure there is no compatibility issues.


    [Blog] [twitter] [LinkedIn]

    Thursday, August 10, 2017 9:13 PM
  • I am not using any callback function. I didn't try callback as it was working fine earlier. I am using AngularJS 1.5 in my application. I am using the map API with default options. So, visibility of map is control by bing API. I am not hiding/showing it explicitly.

    Ramesh Chandra

     
    Thursday, August 10, 2017 10:28 PM
  • Is the map div hidden when loading the map? The error you are seeing typically only occurs when loading the map when it is hidden or when the map script hasn't finished downloading which I suspect may be the issue. How/when do you call the loadMap function?

    [Blog] [twitter] [LinkedIn]

    Thursday, August 10, 2017 11:53 PM