Make your maps more visible
One of the things I like best about http://maps.google.com is that I can paste the URL of a GeoRSS feed or KML doc into the search form and get a map view of the data. I can also visualize that very same KML in other online mapping applications or desktop software like Google Earth (and why not GeoRSS too already?). I can email that KML link to someone else and they can also view the same data. KML is a general purpose interface layer for the kind of guerilla geospatial architecture I sketched a couple years ago.
A property of this kind of architecture is visibility. You can "view source" to see the URL of the KML document this style of application is using and then fetch that same document to use in another way. Visibility is good for caching, good for scaling, good for monitoring, good for discovery. Good web apps, in my opinion, are characterized by high visibility.
The Google Maps API group has announced new KML and GeoRSS layers that improves the story for making visible map application with the Maps API. The design decisions are interesting, but I don't really want to get into them or start comparing them to OpenLayers; I just want to point out the API's support for visible architectures. A Google Map application's need for a highly specialized and opaque RPC interface to spatial data just shrank. Use KML or GeoRSS instead.
To get even more visibility you could link to KML from HTML instead of writing the KML URL into your javascript. My take on the Google example is below.
<html> <head> <title>Mapping linked KML</title> <!-- Link to KML instead of writing into a script --> <link type="application/vnd.google-earth.kml+xml" href="http://gmaps-samples.googlecode.com/svn/trunk/ggeoxml/cta.kml" /> <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&key="></script> <!-- Now we have a more generic, reusable script --> <script type="text/javascript" src="map.js"></script> </head> <body style="margin:0px; padding:0px;" onload="initialize()"> <div id="map_canvas" style="width:100%; height:100%"></div> </body> </html>
Where map.js is
function getLinkedKML(doc) { var link = doc.evaluate( '//link[@type="application/vnd.google-earth.kml+xml"]', doc, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; return link.getAttribute("href"); } function initialize() { var myOptions = { mapTypeId: google.maps.MapTypeId.ROADMAP }; var map = new google.maps.Map( document.getElementById("map_canvas"), myOptions); var linkedKML = new google.maps.KmlLayer(getLinkedKML(document)); linkedKML.setMap(map); }
I've uploaded this to http://sgillies.net/files/linked-kml.html. Go ahead and view the source.
Comments
If i have two KML file
Author: jp
Hello,
I want to know if i have two KML file how may i include them( or to watch them).
example:http://myst/document/kml/kml1.kml and http://myst/document/kml/kml2.kml
to a same map.
Thanks
Re: Make your maps more visible
Author: Sean
The HTML doc can have any number of <link> to KML. In the case where neither of them have special semantics, you would get all KML link nodes instead of only the first (using the appropriate xpath expression and parameters) and then make a map layer of each.