Virtual Earth API: Adding KML or GeoRSS Layers to the Map

Keith Kinnan's Weblog
01-04-2008, 09:27 AM
<P>One of the new features of the Virtual Earth v6 Map Control API is the ability to import KML layers on the map.&nbsp; Previous versions of the API allowed you to import GeoRSS using client-side XML parsing.&nbsp; 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&nbsp;warning unless the feed was from a trusted site in the client browser.&nbsp; </P>
<P>For v6, we have improved this by added a new <STRONG>VEDataType.ImportXML</STRONG> option to the <STRONG>ImportShapeLayerData</STRONG>&nbsp;call on VEMap.&nbsp; This new call uses the same service from <A href="http://maps.live.com/" mce_href="http://maps.live.com">Live Search Maps</A> 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.&nbsp; It also allows you to load these data files from different domains without causing a browser security warning.</P>
<P>Here are the steps for&nbsp;importing a KML, GeoRSS, or GPX&nbsp;file into your Virtual Earth application:</P>
<OL>
<LI>Create a shape layer</LI></OL>
<BLOCKQUOTE>
<P>var shapeLayer = new VEShapeLayer();</P></BLOCKQUOTE>
<P>&nbsp;&nbsp; 2. Create a shape source specification with type VEDataType.ImportXML, the url to the XML file, and a reference to the shape layer:</P>
<BLOCKQUOTE>
<P>var shapeSpec = new VEShapeSourceSpecification(VEDataType.ImportXML,"<A href='http://dsc.discovery.com/utilities/googleearth/nationalparks/nationalparks.kml"' mce_href='http://dsc.discovery.com/utilities/googleearth/nationalparks/nationalparks.kml"'>http://dsc.discovery.com/utilities/googleearth/nationalparks/nationalparks.kml"</A>, shapeLayer);</P></BLOCKQUOTE>
<P>&nbsp;&nbsp;&nbsp;3. Import the data into shape layer by calling ImportShapeLayerData on the map with the specification:</P>
<BLOCKQUOTE>
<P>map.ImportShapeLayerData(shapeSpec);</P></BLOCKQUOTE>
<P>Here's a link to a simple example which imports a KML file from the <A href="http://dsc.discovery.com/" mce_href="http://dsc.discovery.com">Discovery Channel</A>&nbsp;that shows different national parks around the United States:</P>
<BLOCKQUOTE>
<P><A href="http://krkinnan.members.winisp.net/samples/v6/importxml/ve6importxml01.html" mce_href="http://krkinnan.members.winisp.net/samples/v6/importxml/ve6importxml01.html">Virtual Earth API - Import XML Sample</A></P>
<P><A href="http://krkinnan.members.winisp.net/samples/v6/importxml/ve6importxml01.html"><IMG style="WIDTH: 400px; HEIGHT: 300px" height=300 src="http://krkinnan.members.winisp.net/samples/v6/importxml/ve6importxml01.jpg" width=400 border=0 mce_src="http://krkinnan.members.winisp.net/samples/v6/importxml/ve6importxml01.jpg"> </A></P></BLOCKQUOTE>
<P>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.&nbsp; You can also, use the following url syntax directly:</P>
<BLOCKQUOTE>
<P>http://maps.live.com/?mapurl=[insert url here]</P></BLOCKQUOTE>
<P>For example:</P>
<BLOCKQUOTE>
<P><FONT color=#000000><A href="http://maps.live.com/?mapurl=http://dsc.discovery.com/utilities/googleearth/nationalparks/nationalparks.kml" mce_href="http://maps.live.com/?mapurl=http://dsc.discovery.com/utilities/googleearth/nationalparks/nationalparks.kml">http://maps.live.com/?mapurl=http://dsc.discovery.com/utilities/googleearth/nationalparks/nationalparks.kml</A> </FONT></P>
<P><A href="http://maps.live.com/?mapurl=http://dsc.discovery.com/utilities/googleearth/nationalparks/nationalparks.kml"><IMG style="WIDTH: 433px; HEIGHT: 324px" height=324 src="http://krkinnan.members.winisp.net/samples/v6/importxml/livesearchmapsimportxml01.jpg" width=433 border=0 mce_src="http://krkinnan.members.winisp.net/samples/v6/importxml/livesearchmapsimportxml01.jpg"> </A></P></BLOCKQUOTE><img src="http://blogs.msdn.com/aggbug.aspx?PostID=6436417" width="1" height="1">

More... (http://blogs.msdn.com/keithkin/archive/2007/11/20/virtual-earth-api-adding-kml-or-georss-layers-to-the-map.aspx)

 
Web mp2kmag.com
mapforums.com