Bing Maps v7: The OnScriptLoad parameter

One positive thing that seems to have come out of the confusion regarding the recent Bing Maps v7 AJAX update has just been mentioned in a forum post by Chris Pendleton, in which he suggests a possible resolution to the lazy-loading errors (“xxx is undefined” / “yyy is not a Constructor function” etc.) is to make use of the OnScriptLoad parameter.

This parameter, which had been present throughout the v6.x versions of Bing Maps, was conspicuous by its absence in v7 and, despite several comments regarding its whereabouts, did not appear anywhere in the documentation for the v7 API. Based on Chris’ comments, it appears that this parameter has in fact always been present in v7, but accidentally omitted from the documentation. So, until that gets corrected, you can refer to the v6.3 documentation, taken from here: http://msdn.microsoft.com/en-us/library/cc980837.aspx

“onScriptLoad is a string parameter that specifies the name of a JavaScript function to call when the map control script is loaded. The name must contain only alphanumeric characters. The CSS and tiles will not be loaded when this function is called. (This parameter is useful for loading the map control script from an UpdatePanel in ASP.NET Ajax. Users can call Sys.Application.notifyScriptLoaded from their callback to tell ASP.NET Ajax the script has loaded.)”

Not only does this parameter provide an apparent workaround for some of the issues currently being experienced with the v7 control, but it also provides a useful method for any other functions in the future that you want to execute only after you are certain that the library has been loaded (note that this is not the same as when the map has been loaded into the page). To take the example from my last post, you can therefore safely create an instance of the Microsoft.Maps.Location class by calling the tryCreateLocation function from onScriptLoad callback, as follows:

[php]
<!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>
<title>Bing Maps v7 Initialisation Bugs</title>
<script src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0&amp;onscriptload=tryCreateLocation" type="text/javascript"></script>
<script type="text/javascript">
function tryCreateLocation() {
try {
var MyLocation = new Microsoft.Maps.Location(51, -0.15);
alert(MyLocation);
}
catch (e) {
alert(e);
}
}
</script>
</head>
<body></body>
</html>

[/php]

Google I/O winners

It seems like only yesterday that we announced our Last Call for Google I/O contest. We’ve been keeping busy, judging Round 2 submissions for all 10 of our challenges. The winners have been notified via email and will receive a pass to this year’s sold-out Google I/O. Also, all of the Round 1 answers, as well as Round 2 prompts have been posted to the contest site.

We were really impressed with the quality of the submissions–especially with less than 24 hours to turn the code around! Check out screenshots of some of the winning entries below, along with notes from members of each Google Developer Relations group, and stay tuned for more surprises from the I/O team.

Android

Judging was easy for the Android challenge, because our first run through the apps produced a total of exactly 10 places where the reviewer said “Nice!”. Above you see a screenshot of the “Party mode” in Charles Vaughn’s “Bounce Clock”. Read about the details on our Android Developers Blog.

– Tim Bray, Android Developer Advocate

Chrome

(Click a doodle to go to its site and interact.)

We received a lot of nifty doodles and it was tough to pick only ten winners. Some of the particularly fun doodles were interactive or involved a game of some sort (like Pong, or Simon with the Chrome logo). We definitely appreciated being able to view the source code of the web page to see how developers took advantage of the latest HTML, CSS, and JS technologies.

– Jeffrey Chang, Chrome Product Manager

Games

(Click a screen shot to play a game.)

Congratulations to everyone who knew the Konami code and somehow managed to recall that Kuribo’s Shoe is only found on one stage of World Five in Super Mario Bros. 3…and after remembering all that, were still able to write a game in only 24 hours. Apparently playing video games as a kid doesn’t rot your brain as much as our moms said it would.

Almost all of our submissions were fun, technically impressive, or both. The judges were video game industry veterans, so we weren’t wowed by flashy graphics alone. We tried to reward a balance of fun gameplay and technical prowess. Some of the games were actually pretty addictive!

– Ian Lewis, Games Developer Advocate

YouTube

We saw some great submissions that put the new iframe Player API through its paces! The winning submissions offered a mix of cross-browser compatibility, stylish user interface, and the ability to reuse the player for arbitrary sequences anywhere on the web.

– Jeffrey Posnick, YouTube Developer Advocate

Apps

Our Google Apps challenge was built around Google Apps Script, a JavaScript cloud scripting language that allows developers to automate tasks across Google products and interact with 3rd-party APIs. In round 1, we asked contestants to find the median stock price of stock symbols. Round 2 was a fairly open challenge, and the winning submissions performed tasks such as predicting future traffic accidents on Google Maps, producing a daily meeting agenda using Google Calendar and LinkedIn, and sharing Flickr pictures via e-mail to friends and family.

– Ryan Boyd, Google Apps Developer Advocate

Accessibility

We enjoyed seeing how much the ten top entries were able to achieve in such a short time in developing a caption rating app for YouTube (at least one dedicated tweeter pulled an all-nighter). Our top picks really impressed us with the accessibility and polish of their UI. All of them have TalkBack speech support through the Android Accessibility API. Most of the winners have already published and open sourced their work. If these apps inspire you, take a look at the source and contribute!

– Naomi Black, Accessibility Technical Program Manager

Commerce

They say that great minds think alike, and in the case of Google Commerce, our developers created similar mashups. A simple store based on Google Product Search and Google Checkout could be a powerful tool for mom and pop shops. We hope our developers had fun learning about the commerce products that Google offers.

– Ossama Alami, Commerce/Geo Developer Relations

Geo

We asked developers to create a mobile web application to discover interesting walks around San Francisco. We had some really impressive entries, especially given they were developed in a very short timeframe.

– Ossama Alami, Commerce/Geo Developer Relations

Google Web Toolkit (GWT)

We were very impressed with the creativity and performance of the I/O countdown entries. All of the submissions were great examples of what is possible with GWT and HTML5/CSS3. It was an extremely tight competition that came down to tough decisions based on originality, visual appeal, and the size of the resulting JavaScript.

– Chris Ramsdale, GWT/Developer Tools Program Engineer

App Engine

Developers submitted a simple Fibonacci web app in Round 1, where the key was to demonstrate that you correctly handled bad input. We were amazed at the apps that were submitted for Round 2, where we asked developers to create an interesting app using one or more of several App Engine APIs. From making book recommendations to visualizing author impact on PubMed (a favorite of mine, my wife being an academic in medicine), we found many apps useful, well designed, and often quite elaborate.

– Patrick Chanezon, App Engine Developer Relations

Congratulations from the entire Google I/O team to the winners of all the challenges. The bar was quite high and even if you didn’t win, we hope you learned something while building your applications. We encourage you to hone your skills for challenges to come!

The World… She Be a Changing…

The speed at which technology flows these days still impresses me. It seems like just yesterday I was watching TV on a TV, reading books on paper and listening to music on something called a walkman. My son asked me what a modem was and how it worked with my iPhone. Clearly we are all in trouble.

  • Brian Flood is correctly impressed with the World Resources Institute Reefs Map rendering 63,000 polygons with Google Fusion Tables faster than you can scream AXL.
  • Take a look at the Atlas of New South Wales.  I love how it is organized for actual people and not technologists.  I suspect it will be used quite a bit by the good folks upside-down on the other side of the world.  Take note, organize information by how people understand it to be, not by how you think it should be.  I’m not as smart as I think I am and neither are you.
  • The OpenLayers community has been sprinting in some neutral country in Europe.  The main goal, only something where they get OpenLayers to support mobile devices better.  Sounds like they have made some great progress.
  • When you see an article with “Gov 2.0″ in the title you can but not help but cringe.  That said the awesome that is TileMill is only to apparent to everyone.  CSS is the future, stop using SLD everyone.
  • Speaking of freaking amazing, how about this?  Noncontiguous cartograms in OpenLayers and Polymaps 1.  OpenLayers + Polymaps 2 is a winning combination.  God bless Ian Turton for pushing a SLD/GeoServer example 3 in the comments.
  • Do you use ArcGIS Server with OpenLayers?  Thank the Azavea guys for making that happen.
  • Lastly, lets all start putting the fork in the IT department and just name them “the help desk”.  Why we hold on to such nonsense is beyond me.  We are all IT staff tonight! 4

Have a great weekend folks, baseball is back in session!