metamaps--metamaps/script/phantomjs-save-screenshot.js

58 lines
1.5 KiB
JavaScript
Raw Permalink Normal View History

//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];
2014-10-11 01:24:31 +00:00
var environment = args[2];
var address = environment === 'development' ? 'http://localhost:3000' : 'http://metamaps.herokuapp.com';
var url = address + '/maps/' + mapID;
2014-10-08 04:07:54 +00:00
var width = 940;
var height = 630;
//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?
2014-10-08 04:07:54 +00:00
page.onCallback = function(data){
//pass to ruby
console.log(page.renderBase64('PNG'));
//render to the metamaps_gen002 directory for debug
//page.render('map1.png', 'PNG');
phantom.exit();
};
page.evaluate(function() {
2014-10-08 07:47:45 +00:00
$(document).ready(function () {
//$(document).on(Metamaps.JIT.events.animationDone, function() {
setTimeout(function(){
$('.upperLeftUI, .upperRightUI, .mapControls, .infoAndHelp, .uv-icon, .footer').hide();
Metamaps.JIT.zoomExtents();
window.callPhantom();
}, 5000);
});
});//page.evaluate
2014-10-08 07:47:45 +00:00
} else {
//failed to load
2014-10-08 04:47:17 +00:00
phantom.exit();
}//if
});