VE 3, MS Ajax beta 2 and IE7 weirdness

I just updating a site to use MS Ajax beta 2, from beta 1. Everything was fine under beta 1, but code that used to work under beta 1, is throwing an error under beta 2. Oddly enough it all works great under IE6, but not 7.

I have just spent some considerable time examining the data, and everything looks fine. The problem seems to be with drawing a poly line, i.e. simply commenting out the line which adds the polyline to the map stops the problem happening:

map.AddPolyline(poly);

The array of lat/long looks fine, there are no nulls or anything odd, and doing 'map.SetMapView' on the array of points is fine too.

To make the problem even more maddening, the problem is intermittant, and only on IE7, so for the moment I'm giving up on this.

An example URL can be found here:

http://www.mtb-routes.co.uk/northyorkmoors/routes/Pickering-Newtondale-Forest-Loop/route2.aspx

The error is thrown in the VE code, and is 'Unexpected call to method or property access'. Checking it in the script debugger doesn't show anything obviously wrong, as all the points look correct.

The script which calls the MS Ajax web service is here:

http://www.mtb-routes.co.uk/northyorkmoors/routes/webservice.js

The web service method that gets called simply returns a series of lat/longs, like this (bits of code snipped for brevity). There is a class in my webservice which stores points as lat/longs and that's what my code parses. There's other similar code which does the same thing for a list of points of interest, which get rendered into pushpins and that all fine. 'Addpin' is some code which I use to construct a pushpin.

function OnGetPointsRequestComplete(result)

{

//build the map at the first point

var objItem = result[0];

var myPoint =new VELatLong(objItem.lat, objItem.lon);

for(i = 0; i < result.length-1; i=i+increment)

{

var objItem = resultIdea;

var myPoint =new VELatLong(objItem.lat, objItem.lon);

myPoints.push(myPoint);

}

//draw the pretty poly

poly =new VEPolyline('1', myPoints);

poly.SetWidth(6);

poly.SetColor(new VEColor(255,153,0,0.57));

map.AddPolyline(poly);

//start of route

var objItem = result[0] ;

AddPin(objItem.lat, objItem.lon,"Start","Start of the Route","","","start16x16.png");

map.SetMapStyle(VEMapStyle.Hybrid);

map.SetMapView(myPoints);

My question is: does anybody else have a similar problem? If you try the URL in IE7 does it work?

I would revert back to MS Ajax beta 1, but I can't find a link to a download, so for the moment by site is not working right ;-(

It's possible that it might be a problem in the VE stuff which may be sorted, or my IE7 install has become hosed in some way.

[4586 byte] By [dylanh] at [2007-12-27]
# 1

I have made a work around for the problem. Basically, I now generate string with the javascript to write all the points on the server, and then draw this array as a polyline. It's more simple to code, but means all the points are loaded in the initial page load, rather than after the map loads.

However, if anybody wants to have a look, the old broken code lives here:

http://www.mtb-routes.co.uk/northyorkmoors/routes/Castle-Howard/route_example.aspx

Oddly enough, I can't make it fail now ;-) Not sure if it is some weird issue with the the web service scripts getting cached, as I have previously noticed that when you change a web service which is used by MS Ajax, the changes don't always seem to take effect right away.

If anybody tries the above link in IE7 could they mention if it works, ie the map, pushpins and route is rendered, or if it blows up with javascript errors.

dylanh at 2007-9-4 > top of Msdn Tech,Windows Live Developer Forums,Virtual Earth: Map Control Development...
# 2

I think I figured it out. What I wasn't doing is waiting for the map to load before scripting against it. Why this worked in some cases and not with IE7/MS ajax B2, I don't know.

If anybody else is trying to use MS Ajax in conjunction with VE, you might want to read this example!

What you should be doing is something like this (in psuedo code):

//this fires when MS Ajax is loaded and happy

function PageLoad()

{

map = new VEMap('myMap');

//set a callback when the map loads

map = new VEMap('myMap');

//callback when it loads - if we don't do this we script stuff before the map loads and it is not happy

map.onLoadMap = OnMapLoad();

map.LoadMap(new VELatLong(54.40, -0.85), 9 ,'r', false);

map.LoadMap(new VELatLong(54.0, -0.0), 9 ,'r', false);

}

function OnMapLoad()

{

//call the webservice to draw stuff

rtn = mytest.webservice.mapData.GetSomeData(args, OnDoSomethingRequestComplete, OnTimeout, OnError);

}

function OnDoSomethingRequestComplete(result)

{

//our script which plots points on the map

}

It's a wee bit convoluted, as we have to do several cycles of loading something and waiting for it to come back, but it seems to work. Unless you care greatly about loading time, or you load a lot of data, I'd be inclined to dyanmically generate the javascript which renders the map on the server, and just make sure that script gets run as the map.onLoadMap code.

Hope this helps somebody!

dylanh at 2007-9-4 > top of Msdn Tech,Windows Live Developer Forums,Virtual Earth: Map Control Development...
# 3

Please notice the date of this entry, 6 months after OP's last entry.

1. i have IE7.

2. i have exactly the same behaviour. old link does not load, new link works great. security is set at normal.

3. I have scripts activated at a reasonable security level.

4. i am having a puddle-filling contest right now with oreilly - safaribooksonline. couple of the books i am 'trying' to read have ajax. Works intermittedly, if i go back a page nothing works. and I have all the security set to 'off'. they could do anything with the security level I am giving oreilly and still only works intermittedly. i clear my cache each time i start IE7. Actually, I clear, and then restart IE7.

5. dylanh thank you for posting this here! I am trying to get the oreilly folks to read your post.

dbzTHEdinosaur at 2007-9-4 > top of Msdn Tech,Windows Live Developer Forums,Virtual Earth: Map Control Development...

Windows Live Developer Forums

Site Classified