// Usage is "phantomjs-survey_snapshot.js <output_file> <width> <height> <wait_time>"

var system = require('system'),
    args = system.args;

if (args.length === 1) {
    console.error('You must at least specify an argument with the URL to open.');
    exit();
}

var page = require('webpage').create(),
    url = args[1],
    destination = 'snapshot.png',
    width = 1024,
    height = 768,
    wait = 1000,
    headerHeight = 85;

if (args.length >= 3) {
    destination = args[2];
    if (args.length >= 4) {
        width = parseInt(args[3]);
        if (args.length >= 5) {
            height = parseInt(args[4]);
            if (args.length >= 6) {
                wait = parseInt(args[5]);
            }
        }
    }
}

// We add extra pixels for the header
height += headerHeight;

// viewportSize being the actual size of the headless browser
page.viewportSize = {
    width: width,
    height: height
};
// the clipRect is the portion of the page you are taking a screenshot of
// We remove the navbar from view
page.clipRect = {
    top: headerHeight,
    left: 0,
    width: width,
    height: height - headerHeight
};
page.onCallback = function(data){
    window.setTimeout(function () {
        page.render(destination);
        phantom.exit();
    }, wait);
};
page.open(url, function(status) {
    if(status === "success") {
        page.evaluate(function() {
            // Remove the cookie warning
            $('<style>.cc_banner-wrapper { display: none !important; }</style>').appendTo('head');
            // Remove the login message
            $('<style>.alert { display: none !important; }</style>').appendTo('head');
            // Remove the controls
            $('<style>.leaflet-control-container { display: none !important; }</style>').appendTo('head');

            $.when(emapic.allLayersLoadedPromise, emapic.baseLayerLoadedPromise).done(function() {
                // Disable clustering
                emapic.modules.clustering.deactivate();
                window.callPhantom();
            });
        });
    }
});

@@ -407,31 +407,8 @@
 1000
-,%0A    headerHeight = 85
 ;%0A%0Ai
@@ -707,71 +707,8 @@
 %0A%7D%0A%0A
-// We add extra pixels for the header%0Aheight += headerHeight;%0A%0A
 // v
@@ -831,225 +831,8 @@
 %0A%7D;%0A
-// the clipRect is the portion of the page you are taking a screenshot of%0A// We remove the navbar from view%0Apage.clipRect = %7B%0A    top: headerHeight,%0A    left: 0,%0A    width: width,%0A    height: height - headerHeight%0A%7D;%0A
 page
@@ -1064,32 +1064,307 @@
 te(function() %7B%0A
+            // Remove the header%0A            $('%3Cstyle%3E#header %7B display: none !important; %7D%3C/style%3E').appendTo('head');%0A            // Extend the map to the whole page%0A            $('%3Cstyle%3Ebody %3E div.container-fluid %7B height: 100%25 !important; %7D%3C/style%3E').appendTo('head');%0A
             // R

Fix phantomjs survey thumbnail extractor