Allow download of KML file created from JavaScript and Google Earth API -


want create web-application running entirely in browser without backend server component creates kml on-the-fly using google earth api clicking "download" button activates normal content download feature of web browser either prompting save file .kml extension or automatically launching google earth way of kml mime type.

i can construct "data:" url activate download of kml file created within javascript using google earth api works in chrome. works partially in firefox saved ".part" file extension user must explicitly rename file open in google earth. ignored ie. ie 9, example, doesn't support javascript generated file downloads. i'm looking cross-browser solution chrome + firefox + ie @ minimum.

<script type="text/javascript"> var ge; var placemark;  google.load("earth", "1");  function init() {   google.earth.createinstance('map3d', initcallback, failurecallback);     }  ... code create kmlobject  function download() {   // serialize kml text export   var placemarktext = placemark.getkml();   if (placemarktext) {     var uricontent = "data:application/vnd.google-earth.kml+xml;charset=utf-8," +         encodeuricomponent(placemarktext);      window.open(uricontent, 'kml download');   } }  </script> </head>  <body onload="init()" style="font-family: arial, sans-serif; font-size: 13px; border: 0;">  <input type="button" name="button2" value="download kml" onclick="javascript:download()">  <div id="map3d" style="width: 600px; height: 380px;"></div> </body> </html> 

i've seen hack http://code.google.com/p/download-data-uri/ works on chrome not practical solution.

one possible way use downloadify. ...

"a javascript , flash library enables creation , download of text files without server interaction."

you can see working example here. unfortunately don't believe there anyway natively across legacy browsers.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -