Tag Archives: ASP.NET

UPDATED WORKAROUND: Intellisense for page level map variables using the Virtual Earth JavaScript Intellisense Helper

UPDATE: AH FOOEY!  I feel like a goof:).  Turns out my workaround DOESN’T WORK!!!  If you look at the logic from the original post, it makes sense that it wouldn’t work because “var map = new VEMap();” is before “var map = null;” and therefore you get Intellisense for null.  I swear it worked (giving me Intellisense for page level map variable in multiple functions) the first time I tested it.  I think I may have been a victim of the JavaScript Intellisense cache not having updated :(.  Nonetheless, I was so excited about it working, I jumped the gun with my original post.  Yes, I realize the last picture in the original post didn’t actually convey what I was trying to accomplish.  I showed the wrong scenario in my haste to get a blog post up.  Maybe if I would have shown the right scenario, I would have recognized the err of my ways:).  This entire post has been rewritten with my "plan B" workaround.

So I have been playing around with other approaches to the workaround described here.  The first thing I tried was:

image 

On the surface, this seemed like a reasonable workaround.  However, there were still some scenarios where JavaScript errors would pop up.  For example, switching to 3D mode would cause the map control to raise an error:

image 

A similar error would happen when you close the browser.  One could argue this annoyance is a small price to pay for JavaScript Intellisense for the map control:).  However, it is still very annoying.  Good news!  There’s a better workaround.  After fiddling with a bunch of ideas, I stumbled upon the following approach:

image

Everything JUST WORKS!  You get JavaScript Intellisense at design time and the map is null at run time until it is actually instantiated in pageLoad().  This makes for a nicer experience since you don’t have to put up with the annoying error messages or constantly comment/uncomment code to get Intellisense where you need it.  Of course, in production, you should replace the conditional logic with var map = null for your page level variable.

Interestingly enough, this approach works well in another scenario:

image

In this scenario you won’t get Intellisense for x above the if statement because Visual Studio does not perform return type analysis.  However, using the same trick, you can see that you get Intellisense after the if statement.  This makes life better in a number of scenarios.  However, it does litter your code a bit.  Use it at your discretion:).  One could write a little utility that scans .js files and removes these entries based on a regular expression.  Maybe we’ll look at writing something such a utility for our next release.

None of this is in the current release of the Virtual Earth JavaScript Intellisense Helper, nor is it in the updated code I recently blogged about at Updated Virtual Earth Map Control demo code.  However, I will get both updated in the coming days.  For the sample code, I will update the original blog post when I publish the updated code.  I will make sure we release a new version of the Intellisense helper with these changes soon.

ASP.NET MVC “step by step”

Rob Conery  is "creating an ongoing series of webcasts and blog posts, documenting the building of an eCommerce storefront using ASP.NET MVC."  As of yesterday, there are 7 installments in the series.  I haven’t gotten around to reading/watching them yet, but they are definitely on my TODO list.  The latest post, MVC Storefront, Part 7: Helpers and Routing, has links to the previous posts as well.

Technorati Tags: ,

Updated Virtual Earth Map Control demo code

UPDATE: I’ve updated the code to use the workaround described here.  If you downloaded this code before May 2nd, 2008 @ 7:30 PM EST, then you might download it again.  The URL is the same.

I’ve update my primary Virtual Earth (VE) map control demos. If you aren’t familiar with my VE demos, they are essentially all the samples from the Virtual Earth Interactive SDK redone in a Visual Studio solution. My directory structure maps almost identically to the steps treeview in the Interactive SDK:

 image image

Then, I sprinkle in a little ASP.NET AJAX and Windows Communication Foundation (WCF) where these technologies can make building VE solutions easier. All you have to do is download the zip and you basically have the Interactive SDK code++.

Here’s what’s new in the updated code:

  • All pages use the 6.1 map control.
  • Cleaned up some AJAX code that still used really old previews from ASP.NET AJAX (Specifically Microsoft.Web.Preview.dll & Sys.Preview.UI scripts from the Microsoft AJAX Library).
  • Additional code cleanup.
  • All JavaScript files use the Virtual Earth JavaScript Intellisense Helper.
  • All JavaScript files have a reference to their corresponding .aspx page so we get full Intellisense for the Microsoft AJAX Library and any other additional .js files referenced in the ScriptManager.
  • 05 – Customize Shapes/CustomizeShapes.aspx.js has an example of how to restyle the VE InfoBox using Cascading Style Sheets (CSS).
  • 07 – Import Data/GeoRSS_Collections_KML.aspx.js shows how to import KML.
  • 08 – Custom Tile Layers/CustomTileLayers.aspx.js correctly shows the custom tiles. The web site is now configured to use a fixed port for the ASP.NET Development Server.
  • 10 – Route and directions/RouteDirections.aspx.js uses map.GetDirections() instead of map.GetRoute() since map.GetRoute() is deprecated. I also added a multipoint routing example.

You can grab the code here:

http://cid-1f72da7294089597.skydrive.live.com/self.aspx/Public/Virtual%20Earth/VEMapControlDemo_v6.1_VS2008.zip 

WEBCAST FOLLOW UP: Overview of the Microsoft ASP.NET 3.5 Extensions Preview

Thanks to everyone who attended!  Sorry about the demo hiccups / going over.  As I mentioned in the beginning, I had a hard time trying to get everything I wanted to cover into 90 minutes.  As you can see, there’s quite a bit in the ASP.NET 3.5 Extensions.  Normally, I make all of my code demos available for download.  However, I used a newer build for my demos that’s not publicly available.  Once we release the new bits, I will make my code available.  For now, you can download my ASP.NET 3.5 Extensions deck here.

UPDATE: I just created a list of links on my Windows Live Space called ASP.NET 3.5 Extensions.  This list has links to all the relevant landing pages & forums for the various technologies covered today.  Newer versions of MVC, Dynamic Data, and the Silverlight Controls have been released since the December 2007 release of the ASP.NET 3.5 Extension Preview.  Make sure you read the release notes of each newer package to understand how to get the newer bits working on top of the December 2007 preview.  The ADO.NET Entity Framework and ADO.NET Data Services in the December 2007 release of the ASP.NET 3.5 Extension Preview are the latest releases as of today (04/30/2008).  Stay tuned for a newer release that will reflect the updates you saw today.

WEBCAST: Overview of the Microsoft ASP.NET 3.5 Extensions Preview

The ASP.NET 3.5 Extensions Preview is a new release that provides new functionality being added to ASP.NET 3.5 and ADO.NET in 2008. This release delivers a set of new features that target:

  • Enabling High Productivity Data Scenarios – including MVC, Entity Framework, ADO.NET Data Services and Dynamic Data
  • Supporting Test Driven Development – including a powerful and extensible MVC framework
  • Creating the best server for Rich Clients – including Ajax history support and Silverlight controls for ASP.NET

We will take a lap around all the great capabilities packed into this upcoming release including ASP.NET MVC, ASP.NET Dynamic Data, ASP.NET AJAX, ADO.NET Entity Framework, ADO.NET Data Services, and Silverlight Controls for ASP.NET.

When

Wednesday, April 30, 2008

2:00P-3:30P EST (11:00A-12:30P PST)

Register at this link:

http://msevents.microsoft.com/CUI/EventDetail.aspx?EventID=1032373610&Culture=en-US

VE JavaScript Intellisense Helper bug & workaround

A bug has been discovered when using the Virtual Earth JavaScript Intellisense Helper where JavaScript Intellisense fails to surface in a very common scenario.  The scenario is when you have declared a page level map variable.  You will get Intellisense in the JavaScript function where you instantiate the map variable.  However, you will not in other functions:

image 

In the example above, you would get Intellisense for map in GetMap(), but not in Find().  The problem is that Visual Studio 2008 JavaScript Intellisense engine does not know that GetMap() gets called before Find().  Therefore, there is no way to know that the map variable used inside the Find() function is an instantiation of the VEMap class.  We are investigating the best guidance on how to handle this scenario in Visual Studio 2008. 

On the surface, the workaround seems simple.  You just need to make sure the map variable is a page level instantiation like so:

image 

Of course, this poses a problem at runtime because VEMap doesn’t have access to the ‘myMap’ div yet.  That’s the whole reason people put their map init code in window.onload, body.onload, or pageLoad() for ASP.NET AJAX based solutions.  So what to do?  For now, here is what I am doing and what I have checked-in to source control for our upcoming release that will be in sync with the Virtual Earth Map Control 6.1:

image

The good news is that you really don’t have to comment/uncomment while you are developing.  The code above will "work" as is.  I say "work" because you will get an annoying script error for the "var map = new VEMap();" line of code, but the rest of your page will function as expected.  You just want to make sure you fix things for production:).  Although this is a little bit annoying, I think it is small price to pay for getting JavaScript Intellisense for the Virtual Earth Map Control.

Virtual Earth: Drawing on the map and storing the result in SQL Server 2008

During my Virtual Earth Workshop at the GIS-T (www.gis-t.org) conference, I demo’d how to execute a spatial query in a VE scenario by using JavaScript, WCF, and SQL Server 2008.  The query returned GeoRSS to the browser so the VE map control could use it to draw polygons on the map.  I ingested the spatial data into SQL from ESRI shape files provided by the US Census Bureau here using a free tool available here.  I’m planning on cleaning up the code, making the sample available, and recording a channel 9 screencast explaining the sample.   As a result of the demo, I received the following email from one of the attendees:

"I would like to know if you have a demo of how I could store the coordinates created by generating points or polylines from on the map into a database. You can save them as part of collections but I would like to know how they can be stored into a database."

I do not have such a sample.  However, Johannes Kebeck, has a sweet series of posts around Virtual Earth & SQL Server 2008:

Virtual Earth & SQL Server 2008 – Part 1: Introduction (1/2)

Virtual Earth & SQL Server 2008 – Part 1: Introduction (2/2)

Virtual Earth & SQL Server 2008 – Part 2: Spatial Data Management in SQL Server 2008 (1/3)

Virtual Earth & SQL Server 2008 – Part 2: Spatial Data Management in SQL Server 2008 (2/3)

Virtual Earth & SQL Server 2008 – Part 2: Spatial Data Management in SQL Server 2008 (3/3)

Virtual Earth & SQL Server 2008 – Part 3: Getting Started with Virtual Earth

Virtual Earth & SQL Server 2008 – Part 4: Integrating SQL Server 2008 and Virtual Earth (1/6)

Virtual Earth & SQL Server 2008 – Part 4: Integrating SQL Server 2008 and Virtual Earth (2/6)

Virtual Earth & SQL Server 2008 – Part 4: Integrating SQL Server 2008 and Virtual Earth (3/6)

Virtual Earth & SQL Server 2008 – Part 4: Integrating SQL Server 2008 and Virtual Earth (4/6)

Virtual Earth & SQL Server 2008 – Part 4: Integrating SQL Server 2008 and Virtual Earth (5/6)

Virtual Earth & SQL Server 2008 – Part 4: Integrating SQL Server 2008 and Virtual Earth (6/6)

Virtual Earth & SQL Server 2008 – Part 5: Conclusion

Part 4 (6/6) is titled Inserting Data into SQL Server 2008 and answers the question.  However, Johannes takes a slightly different approach than the pattern I showed in my demo.  I love the fact that he took a fairly platform agnostic approach in his examples because it means that anyone can use the approach regardless of their client & server libraries.  However, I’m a .NET evangelist.  It’s my job to highlight our great developer platform.  We have some great libraries and APIs in the Microsoft AJAX Library / ASP.NET AJAX & the Windows Communication Foundation that could help make building out this scenario much easier.  I plan on taking the same scenario and building it out using them.  I’ll be working on it, along with my original example, in the next week or so.  When I am done, I will make the source code available and have 2 screencasts walking showing how to build them step by step.

RELEASED: Virtual Earth JavaScript Intellisense Helper

We’ve officially released!  If you’ve been paying attention to the project, you might have noticed that there was a release on March 3, 2008.  I know a few of you have been paying attention because there were 58 downloads before we released the latest version:).  We held off on announcing the release because there was a last minute fix and we wanted to use MIX as a way to kick off the release.  If you aren’t familiar with the project, see my first post here.  The purpose of this project is to make the Virtual Earth developer experience better by fully enabling JavaScript Intellisense for the Virtual Earth Map Control inside of Visual Studio 2008.

I want to take a moment to thank the community for the HUGE outpouring of support for this project.  I announced the project on a Tuesday morning.  By then next day, we had 11 people volunteer to help develop the remaining pieces.  By Friday, we had our first release complete.  That is 4 days start to finish.  In reality, it was only 3 days since I spent most of the first day refactoring and setting up the project so multiple devs could work in parallel.  I am still in awe of how fast this release came together.  I never imagined we’d get a working solution in the hands of Virtual Earth developers so fast.  The credit goes to the community!  I coded VEMap & VEAltitudeMode.  Almost everything else was done by community devs.  Of the 11 devs on the project, there were really 4 folks who coded the majority of the classes & enumerations. 

Since we were able to able to get this project done so fast, it turns out we were able to use MIX as a way to create more awareness for the project.  Chris Pendleton used it in his Developing Applications with Microsoft Virtual Earth session.  You can watch his session, and all the other MIX sessions 24 hours after they happen at the conference at http://sessions.visitmix.com/

You can get the latest release straight from the codeplex project at https://www.codeplex.com/Release/ProjectReleases.aspx?ProjectName=VEJS&ReleaseId=11338.  Please download it, use it, and tell us how we can make it better through the codeplex project at http://www.codeplex.com/VEJS.  We already have a set of works items we are thinking about for the next release.  Let us know what we’re missing.

Virtual Earth JavaScript Intellisense Helper codeplex project update for those who want to contribute

Unfortunately, there was a configuration snafu with the email address I gave out for you to request access to the project as a contributor.  If you you sent an email from a non Microsoft email address prior to this post, then you received a "Delivery Status Notification (Failure)" response.  I have fixed the problem, but it may take some time to replicate to all of our servers.  Please try again, if you still get a failure response, wait a day.  I assure you the email address is valid:).

I have completed refactoring source code project structure to enable better distribution of work across multiple contributors.  I’ve also created work items ready to be assigned to contributors.  So don’t be shy about contributing:).  The more contributors we have, the faster this turns into a useable solution for everyone! 

This will be the last time I blog from here about ongoing project issues.  All further project specific communications will be done via the codeplex project discussions tab.  I will, of course, make announcements about release on this blog:).

I will publish basic getting started instructions for contributors in the next day.  I will put the instructions on the discussions tab.

JavaScript Intellisense for the Virtual Earth Map Control

UPDATE: Fixed the embedded video.

image

Have you ever wished you could get JavaScript Intellisense for the Virtual Earth Map Control in Visual Studio 2008?  I have, so I came up with a solution and started a codeplex project!  I just recorded a short 10 minute channel 9 screencast explaining the solution.  The screencast is here.  I have also embedded the video in this post for those of you who prefer that.  Once the video has started, you can double click it to go fullscreen.

The project is not finished.  I need people to volunteer to contribute so we can release full intellisense for the Virtual Earth Map Control 6.0.  Instructions for people who want to contribute are in the screencast.  The more people willing to contribute, the faster we make this available for everyone!

The codeplex project is http://codeplex.com/vejs.

https://channel9.msdn.com/EmbedVideo.aspx?PostID=386000&Silverlight=true