metamaps--metamaps/script/phantomjs-save-screenshot.js
Devin Howard 68e1a8042a 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
2014-10-07 20:25:45 -04:00

48 lines
1.3 KiB
JavaScript
Executable file

//parse arguments passed from command line (or more likely, from rails)
var system = require('system');
var args = system.args;
if (args.length <= 1) {
phantom.exit();
throw new Error("no arguments supplied on command line");
}//if
//configurable variables - CHANGE ME
var mapID = args[1];
var url = 'http://localhost:3000/maps/' + mapID;
var width = 188;
var height = 126;
//set up page and the area we'll render as a PNG
var page = require('webpage').create();
page.viewportSize = {
width: width,
height: height
};
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).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
//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
setTimeout(phantom.exit,5000);
//phantom.exit();
});