+function uploadTrack() {
+ // See http://wiki.openstreetmap.org/wiki/Api06#Uploading_traces
+ var trackBlob = new Blob([convertTrack("gpx")], { "type" : "application/gpx+xml" });
+ var formData = new FormData();
+ formData.append("file", trackBlob);
+ formData.append("description", "Track recorded via Lantea Maps");
+ //formData.append("tags", "");
+ formData.append("visibility", "private");
+ var XHR = new XMLHttpRequest();
+ XHR.onreadystatechange = function() {
+ if (XHR.readyState == 4 && XHR.status == 200) {
+ // so far so good
+ reportUploadStatus(true);
+ } else if (XHR.readyState == 4 && XHR.status != 200) {
+ // fetched the wrong page or network error...
+ reportUploadStatus(false);
+ }
+ };
+ XHR.open("POST", gOSMAPIURL + "api/0.6/gpx/create", true);
+ // Cross-Origin XHR doesn't allow username/password (HTTP Auth), so need to look into OAuth.
+ // But for now, we'll ask the user for entering credentials with this.
+ XHR.withCredentials = true;
+ try {
+ XHR.send(formData);
+ }
+ catch (e) {
+ reportUploadStatus(false, e);
+ }
+}
+
+function reportUploadStatus(aSuccess, aMessage) {
+ alert(aMessage ? aMessage : (aSuccess ? "success" : "failure"));
+}
+