-
Notifications
You must be signed in to change notification settings - Fork 207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cloud Export integration, saving & display #1192
Changes from 54 commits
e8b9cfc
dd3f8db
fd1cda4
60663b8
c4d3a73
ddc1d04
4c6ccbd
94e7ad6
28dbecd
ceb9d9c
30c2916
bd6f347
a327ddc
eb9b660
f6b6d6f
5b89522
1aa5398
5cc449b
9048ae1
44e6092
1a00fe9
89c316b
9b95652
936abd3
07bd82d
5afcada
3a0fbc7
29bf577
e02c20d
99714be
46c55d7
85e41e2
de4d269
be48f15
35e736c
5fac7ca
4bdddfc
8865b44
0de724d
dac2125
3b4a8a1
68db9b6
3055eb3
eff752a
7f18c45
987beba
e1a620d
1a710d8
f83471c
af6abe7
15a1e40
005534a
c4ff692
96300a4
3926966
42102a3
4c4117e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
|
||
//(function() { | ||
MapKnitter.Map = MapKnitter.Class.extend({ | ||
|
||
initialize: function (options) { | ||
this._zoom = options.zoom || 0; | ||
this._latlng = L.latLng(options.latlng); | ||
this.map_id = options.map_id || 0; | ||
this.readOnly = options.readOnly; | ||
this.logged_in = options.logged_in; | ||
this.anonymous = options.anonymous; | ||
|
@@ -45,6 +46,7 @@ MapKnitter.Map = MapKnitter.Class.extend({ | |
var downloadEl = $('.img-download-' + warpable.id), | ||
imgEl = $('#full-img-' + warpable.id); | ||
|
||
// this 'download' section can likely be dropped as Leaflet.DistortableImage now provides for such download itself | ||
downloadEl.click(function () { | ||
downloadEl.html('<i class="fa fa-circle-o-notch fa-spin"></i>'); | ||
|
||
|
@@ -418,6 +420,7 @@ MapKnitter.Map = MapKnitter.Class.extend({ | |
var downloadEl = $('.img-download-' + warpable.id), | ||
imgEl = $('#full-img-' + warpable.id); | ||
|
||
// this 'download' section can likely be dropped as Leaflet.DistortableImage now provides for such download itself | ||
downloadEl.click(function () { | ||
downloadEl.html('<i class="fa fa-circle-o-notch fa-spin"></i>'); | ||
|
||
|
@@ -468,10 +471,7 @@ MapKnitter.Map = MapKnitter.Class.extend({ | |
mode: 'lock', | ||
}).addTo(map); | ||
|
||
var customExports = mapknitter.customExportAction(); | ||
var imgGroup = L.distortableCollection({ | ||
actions: [customExports], | ||
}).addTo(map); | ||
var imgGroup = L.distortableCollection({}).addTo(map); | ||
|
||
imgGroup.addLayer(img); | ||
|
||
|
@@ -617,9 +617,81 @@ MapKnitter.Map = MapKnitter.Class.extend({ | |
setupCollection: function() { | ||
|
||
map._imgGroup = L.distortableCollection({ | ||
editable: !mapknitter.readOnly | ||
editable: !mapknitter.readOnly, | ||
exportOpts: { | ||
// 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 | ||
} | ||
}).addTo(map); | ||
|
||
// customize the function that starts up the export | ||
function fetchStatusUrl(opts) { | ||
console.log('fetch status json', opts); | ||
|
||
var scale = 0; | ||
opts.collection.forEach(function(img) { | ||
scale += img.cm_per_pixel; | ||
}); | ||
// average of scales of each image | ||
scale = parseInt(scale/opts.collection.length); | ||
|
||
$.ajax({ | ||
url: 'https://export.mapknitter.org/export', | ||
crossDomain: true, | ||
type: 'POST', | ||
data: { | ||
collection: JSON.stringify(opts.collection), | ||
scale: prompt("Choose a scale in 'centimeters per pixel' (where a smaller 50cm pixel is higher resolution - comparable to Google Maps - or a larger 200cm pixel is lower resolution):", scale) || opts.scale, | ||
upload: true, | ||
}, | ||
success: handleStatusResponse | ||
}); | ||
// show exports | ||
$('.export-tab').click(); | ||
$('.exports-tab').click(); | ||
window.location.hash = "#cloud-exports"; | ||
} | ||
|
||
// 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(status_url, opts) { | ||
alert("Export has begun: leave this window open to be notified of completion. Due to a known issue, please refresh the page if you'd like to start another."); // https://github.com/publiclab/Leaflet.DistortableImage/issues/522 | ||
// 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: 'https://export.mapknitter.org' + status_url, | ||
map_id: mapknitter.map_id | ||
} | ||
}).done(function (data) { | ||
console.log('saved status.json URL to MapKnitter', data); | ||
}); | ||
|
||
// repeatedly fetch the status.json | ||
var updateInterval = setInterval(function intervalUpdater() { | ||
$.ajax('https://export.mapknitter.org/' + status_url + '?' + Date.now(), { // bust cache with timestamp | ||
type: 'GET', | ||
crossDomain: true, | ||
}).done(function(data) { | ||
// update the progress bar or spinner | ||
// opts.updater(data); | ||
data = JSON.parse(data); | ||
console.log(data, data.status, data.jpg); | ||
if (data && data.status == "complete") { | ||
alert("Export completed at " + data.cm_per_pixel + " cm/px. JPG available at https://mapknitter-exports-warps.storage.googleapis.com/" + data.jpg.split('public/warps')[1] + " -- Please refresh page to view completed exports."); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here I set the alert to show the JPG and direct towards a reload. then cleared the interval. Wooo! |
||
clearInterval(updateInterval); | ||
} | ||
}); | ||
}, 3000); // frequency of updating | ||
|
||
opts.resolve(); // stop the spinner | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But maybe we're not passing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe if I do this, it'll work? @VladimirMikulic are you able to review this: publiclab/Leaflet.DistortableImage#528 Thank you! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, fixed and merged! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jywarren sorry for not being available earlier. I am glad that you've managed to fix it 👍 |
||
} | ||
|
||
var sidebar = document.querySelector('body > div.sidebar'); | ||
|
||
if (!mapknitter.readOnly) { | ||
|
@@ -668,4 +740,4 @@ MapKnitter.Map = MapKnitter.Class.extend({ | |
} | ||
|
||
}); | ||
|
||
//})(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<p><a href="https://publiclab.org/wiki/mapknitter-cloud-exporter">Using the Cloud Exporter »</a></p> | ||
<div class="mapknitter-cloud-exports" id="cloud-exports"> | ||
<% exports.order(created_at: :desc).each_with_index do |export, i| %> | ||
<p class="export mapknitter-cloud-export" style="font-size:11px;"> | ||
<b>Export <%= i %>:</b> | ||
(<a href="<%= export.export_url %>">status</a>) | ||
</p> | ||
<% end %> | ||
</div> | ||
<script> | ||
(function() { | ||
$('.mapknitter-cloud-exports .mapknitter-cloud-export').each(function collectExportUrls() { | ||
var export_el = $(this); | ||
var export_url = export_el.find('a').attr('href'); | ||
$.ajax(export_url).done(function displayExportStatus(response) { | ||
response = JSON.parse(response); | ||
console.log(response, response.status); | ||
|
||
if (response.status) export_el.append(' <i class="status">' + response.status + '</i>'); | ||
if (response.jpg) export_el.append(' <span class="file"><a href="https://mapknitter-exports-warps.storage.googleapis.com/' + response.jpg.split('public/warps/')[1] + '">JPG</span>'); | ||
if (response.geotiff) export_el.append(' <span class="file"><a href="https://mapknitter-exports-warps.storage.googleapis.com/' + response.geotiff.split('public/warps/')[1] + '">GeoTiff</span>'); | ||
|
||
export_el.append('<br />'); | ||
|
||
if (response.height && response.width) export_el.append(' <span class="meta">' + response.height + 'x' + response.width + '</span>'); | ||
if (response.size) export_el.append(' <span class="meta">' + (response.size.split('B')[0]/1000000) + 'MB</span>'); | ||
if (response.zip) export_el.append(' <span class="file"><a href="https://mapknitter-exports-warps.storage.googleapis.com/' + response.zip.split('public/tms/')[1] + '">TMS (zip)</span>'); | ||
if (response.start_time) export_el.append(' <i class="start_time">' + response.start_time + '</i>'); | ||
}); | ||
}) | ||
})() | ||
</script> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,6 +103,12 @@ | |
<%= render partial: 'front_ui/maps', locals: { maps: @maps } %> | ||
</div> | ||
|
||
<div class="all-maps light-blue"> | ||
<br> | ||
<h3 class="text-center"> Exports </h3> | ||
<%= render partial: 'maps/cloud_exports', locals: { exports: @map.exports }%> | ||
</div> | ||
|
||
<script> | ||
var map | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
(function(){ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See how here, I am now passing the
opts
object through each function, so that the functions don't need to have access to internal scope from the Collection; I had hoped that at the end of this function theopts.resolve()
would work.