none
Error adding polylines in IE8 RRS feed

  • Question

  • Hi. The map we are developing is working ok in Firefox, Chrome and Opera. But when we test in IE we're getting the following error when we try to add a polyline to the map:

    Message: 'undefined' is null or not an object
    Line: 1
    Char: 109174
    Code: 0
    URI: http://ecn.dev.virtualearth.net/mapcontrol/v7.0/js/bin/7.0.20110224212311.97/en-gb/veapicore.js

    The error occurs at the point we try to add the polyline we have created to an Entity Collection and does not occur every time. We haven't been able to trace the error and can't spot any pattern as to what might be causing it. Has anyone else seen anything like this or have any ideas on what might fix it?

    • Moved by Ricky_Brundritt Friday, March 9, 2012 4:12 PM (From:Bing Maps: Map Control and Web services Development)
    Thursday, March 10, 2011 3:19 PM

Answers

  • Hello,

    Weird way to write your thing but anyway, if it works:

    function (points, collection, opacity, r, g, b) {
    
      var pointArray = [];
      for (var i = 0; i < points.length; i++)
        <strong> pointArray.push</strong>(new Microsoft.Maps.Location(points[i][0], points[i][1]));
      
      var shape = new Microsoft.Maps.Polyline(pointArray, { strokeColor: new Microsoft.Maps.Color(opacity, r, g, b) });
      map.entities.push(shape); 
    }
    

    Hope this will help.


    MVP - Bing Maps - My blog (FR): http://blogs.developpeur.org/nicoboo/ Twitter: http://twitter.com/nicolasboonaert/
    Monday, March 14, 2011 10:30 AM
    Moderator
  • The error you are seeing is a generic error. Verify that the points you are using to create your location objects are numbers and not strings. If they are strings you will be able to create the polyline object but it will error out when you add it to the map. Try wrapping points[i][0] and points[i][1] with parseFloat.
    Windows Live Developer MVP - http://rbrundritt.spaces.live.com | http://inknowledge.co.uk
    Thursday, March 10, 2011 9:13 PM

All replies

  • As the error message states, you're trying to reference an object or property that isn't defined (at least, not at the point you're trying to access it). The fact that this is an intermittent error suggests that it's a timing issue that you're not waiting for some part of the map to be instantiated before you try to access it. This often occurred in v6.x when people tried to call and of the VEMap methods before waiting for the onload callback to fire, but I've not experienced it in v7.

    Hard to say anything else without seeing exactly what you're trying to do - if you want more help please paste a code sample of URL link to your map.


    twitter: @alastaira blog: http://alastaira.wordpress.com/
    Thursday, March 10, 2011 3:39 PM
    Moderator
  • Thanks for the reply. Unfortunatley I'm limited in what I can share but here is the function where the error is occuring:

    line : function (points, collection, opacity, r, g, b) {

            var pointArray = []; // Create array to hold points
            for (var i = 0, j = points.length; i < j; i++) {
                pointArray[i] = new Microsoft.Maps.Location(points[i][0], points[i][1]); // Create location point and add to array
            }
            var shape = new Microsoft.Maps.Polyline(pointArray, {strokeColor: new Microsoft.Maps.Color(opacity, r, g, b)}); // Create line
            collection.push(shape); // Add line to map
        }

    It gets as far as creating the Polyline ok, but when we try to add the line to the Entity collection on the last line of this function then it will error. The map is loaded on document ready, this then makes an ajax request for a data set and then the callback function from that request calls this function when it needs to draw a line and so everything should be instantiated correctly.

    Thursday, March 10, 2011 3:58 PM
  • The error you are seeing is a generic error. Verify that the points you are using to create your location objects are numbers and not strings. If they are strings you will be able to create the polyline object but it will error out when you add it to the map. Try wrapping points[i][0] and points[i][1] with parseFloat.
    Windows Live Developer MVP - http://rbrundritt.spaces.live.com | http://inknowledge.co.uk
    Thursday, March 10, 2011 9:13 PM
  • Hello,

    Weird way to write your thing but anyway, if it works:

    function (points, collection, opacity, r, g, b) {
    
      var pointArray = [];
      for (var i = 0; i < points.length; i++)
        <strong> pointArray.push</strong>(new Microsoft.Maps.Location(points[i][0], points[i][1]));
      
      var shape = new Microsoft.Maps.Polyline(pointArray, { strokeColor: new Microsoft.Maps.Color(opacity, r, g, b) });
      map.entities.push(shape); 
    }
    

    Hope this will help.


    MVP - Bing Maps - My blog (FR): http://blogs.developpeur.org/nicoboo/ Twitter: http://twitter.com/nicolasboonaert/
    Monday, March 14, 2011 10:30 AM
    Moderator