Expecho's .Net corner
All about software development

How to use the virtual earth winforms user control part 1: Introduction

June 25, 2008 22:01 by Peter Bons

For those who don't know it yet, I have developed a user control for using Microsoft Virtual Earth in your winforms application. In this serie of posts I will provide a guide about how to use the control. The control itself is written in C# and both the control and a sample application are downloadable from the codeplex site. The solution is created in Visual Studio 2005. The control supports a number of things you can do:

  • Get the driving directions to a specific location
  • Add and delete customized pushpins to the map
  • Add and delete shapelayers to the map. Pushpins can be added to layers so when a layer is made invisible, all the pushpins in that layer will be hidden
  • Capture mouse events raised by mouse actions on the map. For example you can get the exact location where a user has clicked on the map so you can add a pushpin there.
  • Control the look and feel of the map. Like enabling satellite view or hiding the map controls
  • Save an image of the exact output of the map
  • Support version 6.1 of the API

The user control hosts a webbrowser control that uses an included .html file with lots of javascript code to interact with the virtual earth webservice. The methods you call on the control are forwarded to the javascript code that then executes certain command on the webservice. For example, to clear all pushpins on the map the call VEMap.Clear() must be issued to the webservice. C# does not know the VEMap class. Instead the user control provides the method VE_DeleteAllShapes() which executes a javascript method called "deleteAllShapes" by invoking this command by using the webbrowser control: vEarthBrowser.Document.InvokeScript("deleteAllShapes"). The javascript function "deleteAllShapes" will execute the right command "VEMap.Clear()" of the webservice. 

The user control includes 4 classes:

ucVEarth is the main class and represent the user control
SearchLocation is a class that represents a location or pushpin on the map.
RouteDirections is the class that represents the driving directions to a specific location. Driving directions consist of one or more RouteLeg objects that represent a part of the route between two waypoints.
RouteLeg is the class the represents the part of a route between two waypoints.

In the next post I will show how to add puspins to the map by using latitude/longitude coordinates and by address (Where) or name (What)


Currently rated 5.0 by 11 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Related posts

Comments

January 29. 2009 20:35

Mark

Would love to give this a go but for what ever reason its not letting me DL it.

Will try again se what happens

Mark

April 9. 2009 18:03

UK Franchises

Hey, just checking out the blogengine.net platform... Seems pretty nice. What is the backend like?

Cheers

Matthew

UK Franchises

April 10. 2009 02:06

Peter Bons

The backend is quite simpel and basic, yet powerful enough for me Smile

Peter Bons

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

July 4. 2009 18:23