Skip to content

Commit

Permalink
save as anonymous gist, #209
Browse files Browse the repository at this point in the history
  • Loading branch information
mapsam committed Nov 8, 2015
1 parent 48d79fb commit 25db070
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/js/menus.left.dropchop.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var dropchop = (function(dc) {
name: 'Save',
icon: '<i class="fa fa-floppy-o"></i>',
actions: [
'save-gist',
'save-geojson',
'save-shapefile'
]
Expand Down
41 changes: 40 additions & 1 deletion src/js/ops.file.dropchop.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ var dropchop = (function(dc) {
dc.util.xhr('http://overpass-api.de/api/interpreter?[out:json];node['+parameters[0]+']('+bbox+');out;', dc.ops.file['load-overpass'].callback);
},
callback: function(xhr, xhrEvent) {
dropchop.util.loader(false);
dc.util.loader(false);
if (xhr.status === 200) {
var data = JSON.parse(xhr.responseText);
var geojson = osmtogeojson(data, {
Expand Down Expand Up @@ -243,6 +243,45 @@ var dropchop = (function(dc) {
//
// Export Data
//
'save-gist': {
minFeatures: 1,
description: 'Save project',
icon: '<i class="fa fa-file-o"></i>',
createsLayer: false,
execute: function() {

var gist = {
"description": "dropchop project",
"public": true,
"files": {}
};

// get each layer and add to gist POST object
for (var lyr in dc.layers.list) {
var layer = dc.layers.list[lyr],
string = JSON.stringify(layer.raw),
fileName = dc.util.removeWhiteSpace(layer.name + '.geojson');
gist.files[fileName] = {};
gist.files[fileName].content = string;
}

$.ajax({
type: 'POST',
url: 'https://api.github.com/gists',
data: JSON.stringify(gist),
dataType: 'json',
success: dc.ops.file['save-gist'].callback,
error: function(err) {
dc.notify('error', 'There was an error saving your project.');
}
});
},
callback: function(data) {
dc.notify('saved', 'Project saved as a Github Gist successfully!<br>You can <a target="_blank" href="'+data.html_url+'">view <strong>'+data.id+'</strong> here</a>.', 'close');
window.history.pushState(null, null, '?gist='+data.id);
}
},

'save-geojson': {
minFeatures: 1,
description: 'Save as GeoJSON',
Expand Down
12 changes: 12 additions & 0 deletions src/scss/_notification.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
font-size: 0.85em;
margin: 5px 5px 0 0;
color: white;
a {
color: white;
text-decoration: underline;
}

&.success {
background: $green;
}
Expand All @@ -16,6 +21,13 @@
&.info {
background: $blue;
}
&.saved {
background: #e1f8e3;
color: #333;
a {
color: #333;
}
}

.notification-close {
background: transparent;
Expand Down

0 comments on commit 25db070

Please sign in to comment.