Importing GeoRSS Data
Now that you have seen how to create maps and manually add shapes (pushpins, polylines and polygons) with both the AJAX Map Control and the ASP.NET Map Control, I'll show you how to import data to overlay your map.
GeoRSS is a variation on the popular RSS format that adds tags for point, polyline, and polygon data. For example, Listing 4
contains the same pushpoint, polyline, and polygon information used to create the AJAX Map of the Microsoft campus earlier in the article.
At this point you should recognize some of the tags, including the title and description. Obviously the <georss:point>
correspond to pushpoints, polylines, and polygons. This GeoRSS file is very simple.
Importing GeoRSS Data with the AJAX Map Control
In Listing 5
you can see that all the code required to add those map objects manually has been stripped out and replaced with these three lines.
var mylayer = new VEShapeLayer();
var veLayerSpec = new VEShapeSourceSpecification(
VEDataType.GeoRSS, "MSFT_AjAX.xml", mylayer);
|Figure 10. GeoRSS Data Import: This is the map displayed after importing the GeoRSS data.|
The preceding code creates a new VEShapeLayer to contain the imported data points. Next, it creates a VeShapeSourceSpecification object, which specifies the import format (VEDataType.GeoRSS
), the name of the GeoRSS file (MSFT_AJAX.xml
), and the layer it should be imported into (mylayer
). Finally, it calls the map's ImportShapeLayerData
method to import the data.
contains the GeoRSS data being imported in the preceding example. Running the page from Listing 5
results in the same map being displayed (see Figure 10
) as the earlier example that adds the map objects manually.
Importing GeoRSS Data with the ASP.NET Map Control
The steps to import GeoRSS data using the ASP.NET Map Control are very similar. The code below imports an existing GeoRSS file (MSFT_ASPNET.xml) and displays it.
Partial Public Class GeoRSS_ASPNET
Protected Sub Page_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Me.Load
'Initialize map properties
Map1.Center.Latitude = 47.6439
Map1.Center.Longitude = -122.129
Map1.ZoomLevel = 17
Map1.MapStyle = _
'Create new layer to contain shapes
Dim layer As New ShapeLayer
Dim ShapeSpecs As New ShapeSourceSpecification( _
DataType.GeoRSS, "MSFT_ASPNET.xml", layer)
Map1.ImportShapeLayerData(ShapeSpecs, "", True)
The preceding code first initializes the initial map position, type, and zoom level. Next a shape layer is created and added to the map. The import happens on the next two lines. A ShapeSourceSpecification object is created with the import type specified (GeoRSS), the name of the GeoRSS file to import, and finally the layer to import the data on to.
|Figure 11. Map with HTML Markup: This map results from importing the GeoRSS data with HTML markup included in the data.|
The DataType enum values are GeoRss
, and VECollection
is used primarily to import KML files, while VECollection is used to import collections you may have created on Virtual Earth. I created Virtual Earth collections to get the latitude and longitude coordinates for all the samples in this article.
Lastly, the code calls the map's ImportShapeLayerData
The GeoRSS data imported into the ASP.NET Map Control (see Listing 6
) is similar to the data used with the AJAX Map Control example, but it differs in the polygon section at the end of the file. Just like the HTML markup added to some of the properties when adding map objects manually earlier, you can add HTML markup to the GeoRSS file (as shown here) to provide a richer user experience.
Additional Data Importing Options
The two Virtual Earth map controls can import more than just GeoRSS formatted data. Other supported formats include KML, GPX and VECollection. Keyhole Markup Language (KML), like GeoRSS, is an XML-based format for managing the display of geospatial data in Google Maps and Google Earth. The GPS eXchange format (GPX) is a format for managing GPS data.
Another prime candidate for importing data is SQL Server. While SQL Server 2005 does not have the new geospacial data types that SQL Server 2008 provides, you can easily store latitude and longitude values in your databases. For example, you could create a query to generate a list of retail stores along with their address, website URL, manager name, phone number, latitude and longitude coordinates, and so on to generate a GeoRSS file that you could import into a map. You could add links to your corporate logo, store picture, etc., to create a rich user experience when people click on a specific store location.
I hope this introduction to developing Virtual Earth applications gets you thinking about new ways of delivering data to your users. There is still much to learn. For example, SQL Server 2008 has new geospacial data types that are tailor made to working with Virtual Earth. The Virtual Earth MapCruncher feature allows you to overlay your own map images over the Virtual Earth maps. You can learn more about MapCruncher or download it here
. The Virtual Earth Web Services 1.0, new in version 6.2, provides imagery, search, geocoding, and routing services.
There are additional server-side and client-side events you should learn how to handle. For example, one sample in the Interactive SDK
sidebar, which lists a number of resources to help you continue the learning process. Good luck and happy mapping!