From 68e1a8042a99926fbb18c7e4c3e16d61987258ed Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Tue, 7 Oct 2014 20:25:45 -0400 Subject: [PATCH] Added animationDone event to Metamaps.JIT.js, tried to hook into it from phantomjs, failed still have debugging stuff in this commit. it's currently rendering the image so I can check output It doesn't seem to be responding to the event, and it's stopped hiding the UI elements around the edge --- app/assets/javascripts/src/Metamaps.JIT.js | 4 ++- app/workers/grab_map_screenshot_worker.rb | 7 ++++ script/phantomjs-save-screenshot.js | 39 +++++++++------------- 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/app/assets/javascripts/src/Metamaps.JIT.js b/app/assets/javascripts/src/Metamaps.JIT.js index 3c5b79c9..3075f0cb 100644 --- a/app/assets/javascripts/src/Metamaps.JIT.js +++ b/app/assets/javascripts/src/Metamaps.JIT.js @@ -3,6 +3,7 @@ Metamaps.JIT = { mouseMove: 'Metamaps:JIT:events:mouseMove', pan: 'Metamaps:JIT:events:pan', zoom: 'Metamaps:JIT:events:zoom' + animationDone: 'Metamaps:JIT:events:animationDone', }, vizData: [], // contains the visualization-compatible graph /** @@ -211,6 +212,7 @@ Metamaps.JIT = { duration: 800, onComplete: function () { Metamaps.Visualize.mGraph.busy = false; + $(document).trigger(Metamaps.JIT.events.animationDone, [event]); } }, animateFDLayout: { @@ -1675,4 +1677,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(); });