RickLH


Starting from the most simple map code imaginable, I can successfully display a map but an attempt to click and drag on the map results in

---------------------------
Error
---------------------------
A Runtime Error has occurred.
Do you wish to Debug

Line: 1
Error: 'null' is null or not an object
---------------------------
Yes No
---------------------------

Here's the web code:

Code Block

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

<html>

<head>

<title>Virtual Earth</title>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

<script type="text/javascript" src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx v=6"></script>

<script type="text/javascript">

var map = null;

function startVE()

{

map = new VEMap('myMap');

map.LoadMap();

}

</script>

</head>

<body onload="startVE()" style="margin: 0px">

<div style="overflow: hidden" id="myMap"></div>

</body>

</html>

I had this once before but it went away after I fixed a mispelling. Now I can't get rid of the problem despite having reduced the code down to the smallest possible amount. What am I doing wrong





Re: Error: 'null' is null or not an object on pan

Richard_Brundritt


Try setting the position in the div tag for the map

i.e. <div style="position:relative; overflow: hidden" id="myMap"></div>





Re: Error: 'null' is null or not an object on pan

SoulSolutions

Richard is spot on you must set a width, height and position. This can be in line as a style or new for V6 you can do this in your CSS stylesheet or at the top of the page:

Code Block
<style>
#myMap {width:400px;height:400px;position:relative}
</style>

John.







Re: Error: 'null' is null or not an object on pan

RickLH

I hesitate to contradict anyone who obviously is so well versed in these matters, but setting a size did nothing for problem. I'm beginning to suspect that the problem is not the HTML code at all but rather some interaction with how I'm calling the javascript functions themselves.

Here's what made the problem go away:

By my WinForm code and the HTML body's onload event were invoking the startVE function. If startVE is only called from the HTML body's onload event then the program works as desired. However, if startVE is only called from the WinForm in response to notification that the HTML document has completed then the problem still manifests. I suspect that either I'm calling startVE incorrectly from the WinForm or calling startVE at that time is causing a problem.

Do you see something wrong with this The documents say that InvokeScript comes in two flavors, one that has just a function name and one that has function name plus object array of arguments. To keep things simple, I'm using the 'just a function name with no arguments' version of the call.

Code Block

private void Form1_Load( object sender, EventArgs e )
{
// Find the Location of VirtualEarth.html
string BrowserURL = Application.ExecutablePath;
BrowserURL = BrowserURL.Substring( 0, BrowserURL.LastIndexOf( "\\" ) );
BrowserURL = Path.Combine( BrowserURL, @"VirtualEarth.htm" );

// Start the load of VirtualEarth.html into the WebBrowser.
// When done, the callback below (DocumentedCompleted) gets called.
virtualEarthMapBrowser.Url = new Uri( BrowserURL );
virtualEarthMapBrowser.ObjectForScripting = this;
}

private void virtualEarthMapBrowser_DocumentCompleted( object sender, WebBrowserDocumentCompletedEventArgs e )
{
virtualEarthMapBrowser.Document.InvokeScript( "startVE" );
}






Re: Error: 'null' is null or not an object on pan

RobertoRaimondo

Hello Richard,

I already had a similar problem like this. For some reason that I don't know the DocumentCompleted may get called twice, thus creating some problem in your map. I was able to reproduce your same problem, and to fix it in this easy way.
- Declare a private bool variable in your form, or wherever is convenient for you. Let's call it _isFullyLoaded.
- Modify your callback to have this body:

Code Block

private void virtualEarthMapBrowser_DocumentCompleted( object sender, WebBrowserDocumentCompletedEventArgs e )
{

if (!_isFullyLoaded)
{
_isFullyLoaded = true;
virtualEarthMapBrowser.Document.InvokeScript("startVE");
}
}



In this way your script function will be called only once, and everything should work as you expect.

Roberto.





Re: Error: 'null' is null or not an object on pan

RickLH

That's a good idea and I will add that to the code. For what it's worth, I'd already put a check in the HTML javascript to see if the map object had been created so it should not have been possible to create the map twice. It didn't fix the problem so I got around the problem by taking a leaf from the Henny Youngman School of Programming ("Doctor, Doctor! It hurts when I do this" "Well, don't do that then.") Since the map was perfectly happy when being initialized from the HTML body, that's what I let it do. I do have some other initial state values that need to be asserted but they don't care if they are doubly set.