diff --git a/app/assets/javascripts/src/Metamaps.JIT.js b/app/assets/javascripts/src/Metamaps.JIT.js index fe5c34c2..d0d4c70c 100644 --- a/app/assets/javascripts/src/Metamaps.JIT.js +++ b/app/assets/javascripts/src/Metamaps.JIT.js @@ -8,6 +8,7 @@ Metamaps.JIT = { removeSynapse: 'Metamaps:JIT:events:removeSynapse', pan: 'Metamaps:JIT:events:pan', zoom: 'Metamaps:JIT:events:zoom' + animationDone: 'Metamaps:JIT:events:animationDone', }, vizData: [], // contains the visualization-compatible graph /** @@ -229,6 +230,7 @@ Metamaps.JIT = { duration: 800, onComplete: function () { Metamaps.Visualize.mGraph.busy = false; + $(document).trigger(Metamaps.JIT.events.animationDone, [event]); } }, animateFDLayout: { @@ -1679,4 +1681,4 @@ Metamaps.JIT = { }); } } -}; \ No newline at end of file +}; diff --git a/app/workers/grab_map_screenshot_worker.rb b/app/workers/grab_map_screenshot_worker.rb index ed9b2709..730d4a7d 100644 --- a/app/workers/grab_map_screenshot_worker.rb +++ b/app/workers/grab_map_screenshot_worker.rb @@ -3,8 +3,15 @@ class GrabMapScreenshotWorker include Sidekiq::Worker def perform(map_id) + imgBase64 = '' Phantomjs.run('./script/phantomjs-save-screenshot.js', map_id.to_s) { |line| + imgBase64 << line puts line } + + #this doesn't work yet + #map = Map.find(map_id) + #map.add_attachment(imgBase64) + #map.save! end end diff --git a/script/phantomjs-save-screenshot.js b/script/phantomjs-save-screenshot.js index 9fe0f4c7..f79a894e 100755 --- a/script/phantomjs-save-screenshot.js +++ b/script/phantomjs-save-screenshot.js @@ -9,16 +9,8 @@ if (args.length <= 1) { //configurable variables - CHANGE ME var mapID = args[1]; var url = 'http://localhost:3000/maps/' + mapID; -var width = 400; -var height = 400; -var thumbsDirRelative = 'app/assets/images/map_thumbnails'; - -//set up writing to filesystem -var fs = require('fs'); -var thumbsDirectory = fs.workingDirectory + '/' + thumbsDirRelative; -if (!fs.isDirectory(thumbsDirectory)) { - fs.makeDirectory(thumbsDirectory); -}//if +var width = 188; +var height = 126; //set up page and the area we'll render as a PNG var page = require('webpage').create(); @@ -26,29 +18,30 @@ page.viewportSize = { width: width, height: height }; -page.clipRect = { - top: 32, - left: 32, - width: width - 32, - height: height - 32 -}; + page.open(url, function (status) { if (status === 'success') { //since this isn't evaluateAsync, it should also ensure the asynchronous //js stuff is loaded too, hopefully? page.evaluate(function() { - $(document).ready(function(){ - $('.upperLeftUI, .upperRightUI, .mapControls, .infoAndHelp, #barometer_tab, .footer').hide(); - });//document.ready + $(document).on(Metamaps.JIT.events.animationDone, function(){ + $('.upperLeftUI, .upperRightUI, .mapControls, .infoAndHelp, #barometer_tab').hide(); + Metamaps.Famous.logo.hide() + Metamaps.JIT.zoomExtents(); + console.log('got here'); + });//document.on animationDone });//page.evaluate - //render page into map_thumbnails directory - var filename = thumbsDirectory + '/map' + mapID + '.png'; - page.render(filename, 'PNG'); + //pass to ruby + //console.log(page.renderBase64('PNG')); + + //render to the metamaps_gen002 directory for debug + page.render('map1.png', 'PNG'); } else { //failed to load }//if - phantom.exit(); + setTimeout(phantom.exit,5000); + //phantom.exit(); });