One of the new features of the Virtual Earth v6 Map Control API is the ability to import KML layers on the map. Previous versions of the API allowed you to import GeoRSS using client-side XML parsing. However, one of the restrictions was that the GeoRSS file had to be on the same domain as the application or the browser would bring up a security warning unless the feed was from a trusted site in the client browser.
For v6, we have improved this by added a new VEDataType.ImportXML option to the ImportShapeLayerData call on VEMap. This new call uses the same service from Live Search Maps which allows users to import KML, GeoRSS, or GPX into user collections. In the Virtual Earth API, it will import the XML into a shape layer in your application. It also allows you to load these data files from different domains without causing a browser security warning.
Here are the steps for importing a KML, GeoRSS, or GPX file into your Virtual Earth application:
- Create a shape layer
var shapeLayer = new VEShapeLayer();
2. Create a shape source specification with type VEDataType.ImportXML, the url to the XML file, and a reference to the shape layer:
var shapeSpec = new VEShapeSourceSpecification(VEDataType.ImportXML,”http://dsc.discovery.com/utilities/googleearth/nationalparks/nationalparks.kml”, shapeLayer);
3. Import the data into shape layer by calling ImportShapeLayerData on the map with the specification:
Here’s a link to a simple example which imports a KML file from the Discovery Channel that shows different national parks around the United States:
Note: you can also import XML files directly into Live Search Maps by opening a collection and then clicking on Import and entering the url. You can also, use the following url syntax directly:
http://maps.live.com/?mapurl=[insert url here]