Bug with Resize() if you remove controls after AddControl()

I've found a bug if we have added a control using AddControl, then you remove it use the non VE API method posted here by me and then make a call to Resize(). The Resize function looks like it loops through the list of controls to do something with them but since they no longer exist it thows an error.
So its not really a VE bug but we do need a DeleteControl() added to the API. That said maybe a try catch to handle this situation would be great.
John

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://dev.virtualearth.net/mapcontrol/v3/mapcontrol.js"></script>
<script type="text/javascript">
function GetMap()
{
map = new VEMap('MapDiv');
map.LoadMap(new VELatLong(-27, 152), 5 ,'r' ,false);
var el = document.createElement("div");
el.setAttribute('id',"VELoading");
el.innerHTML = "Test";
map.AddControl(el);
var el = document.getElementById("VELoading");
el.parentNode.removeChild(el);
map.Resize(800, 600);
}
</script>
</head>
<body onload="GetMap();">
<div id='MapDiv' style="position:relative; width:500px; height:500px;border:solid 1px black;"></div>
</body>
</html>




Answer this question

Bug with Resize() if you remove controls after AddControl()

  • paoloTheCool

    Thanks Caleb,
    I'll put a simple workaround in place for now until it gets fixed. When i find that simple work around i'll post it here.
    John.


  • AustinMyers

    ok instead of using AddControl I switched to:
    document.body.appendChild(newdiv);

    For me I clear all these divs on any mouse movement (onstartcontinuouspan() and onstartzoom()) and refresh all points, lines and these divs onchangeview(). In most people cases this won't be as simple.

    The only extra change was to set the postion of the new divs to absolute:
    newdiv.style.position = "absolute";
    John.


  • Mahyar154572

    Thanks, John. I've filed a bug with the team on this.

    I've asked for a DeleteControl or RemoveControl method for a while now, but have been content with the "removeChild()" approach. I guess we need to revisit that now.


  • Bug with Resize() if you remove controls after AddControl()