Skip to content

Commit

Permalink
integration with new LDI v0.10.0, uploading status.json URL
Browse files Browse the repository at this point in the history
  • Loading branch information
jywarren committed Jan 10, 2020
1 parent 29a26d4 commit 9a26a4d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
38 changes: 37 additions & 1 deletion app/assets/javascripts/mapknitter/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,9 +470,45 @@ MapKnitter.Map = MapKnitter.Class.extend({

var customExports = mapknitter.customExportAction();
var imgGroup = L.distortableCollection({
actions: [customExports],
// exportUrl: 'http://34.74.118.242/api/v2/export/', // to swap to JS exporter
// exportStartUrl: 'http://34.74.118.242/api/v2/export/', // to swap to JS exporter
// fetchStatusUrl: fetchStatusUrl,
handleStatusResponse: handleStatusResponse
}).addTo(map);

// receives the URL of status.json, and starts running the updater to repeatedly fetch from status.json;
// this may be overridden to integrate with any UI
function handleStatusResponse(data, opts) {
console.log(data);
// this is for the JS exporter:
// var statusUrl = data.split('please visit, ')[1];

// save the location of the status URL
$.ajax({
url: "/export",
type: 'POST',
data: { status_url: data.status_url }
}).done(function (data) {
console.log('saved status.json URL to MapKnitter' + data);
});

// repeatedly fetch the status.json
var updateInterval = setInterval(function intervalUpdater() {
$.ajax(statusUrl + '?' + Date.now(), {// bust cache with timestamp
type: 'GET',
crossDomain: true,
}).done(function(data) {
// update the progress bar or spinner

opts.updater(data);
});
}, 3000); // frequency of updating

// but in this example, we're not; we just get the URL of the finished image;
// we should stop the spinner
opts.resolve();
}

imgGroup.addLayer(img);

/**
Expand Down
2 changes: 1 addition & 1 deletion app/views/maps/_cloud_exports.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
console.log(response);
response = JSON.parse(response);
if (response.status) export_el.append('<span class="status">' + response.status + '</span>');
if (response.jpg) export_el.append('<span class="file">' + response.jpg + '</span>');
if (response.jpg) export_el.append('<span class="file"><a href="https://mapknitter-exports-warps.storage.googleapis.com/' + response.jpg + '">JPG</span>');
});
})
})()
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"leaflet": "Leaflet/Leaflet#^1.0.0",
"leaflet-dist": "vperron/leaflet-dist#0.7.x",
"leaflet-draw": "Leaflet/Leaflet.draw#0.2.4",
"leaflet-distortableimage": "0.8.7",
"leaflet-distortableimage": "^0.10.0",
"leaflet-easybutton": "^2.4.0",
"leaflet-environmental-layers": "^1.3.6",
"leaflet-fullhash": "^1.0.0",
Expand Down

0 comments on commit 9a26a4d

Please sign in to comment.