Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
<!DOCTYPE html>
<html>
<head>
<title>Create a Map</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
<link rel="stylesheet" href="http://js.arcgis.com/3.7/js/dojo/dijit/themes/claro/claro.css">
<link rel="stylesheet" href="http://js.arcgis.com/3.7/js/esri/css/esri.css">
<style>
#mapDiv{
height: 480px;
width: 640px;
}
</style>
<script src="http://js.arcgis.com/3.7/"></script>
<script>
require(["esri/map", "esri/dijit/Print", "esri/tasks/PrintTemplate"],
function(Map, Print, PrintTemplate) {
var map = new Map("mapDiv", {
center: [14.049, 55.485],
zoom: 3,
basemap: "streets",
logo: false
});
// configure the print task
// see here for more info:
// https://developers.arcgis.com/en/javascript/jsapi/printtemplate.html
var t = new PrintTemplate();
t.layout = "Letter ANSI A Portrait";
t.label = "Portrait (Image)";
t.format = "jpg";
t.layoutOptions = {
legendLayers: [],
scaleBarUnit: "Meters",
titleText: "Demo Title",
authorText: "author text",
copyrightText: "copyright text",
};
t.exportOptions = {
width: 640,
height: 480,
dpi: 96
};
// including only one element into the template array
// will render out only a button, it will otherwise be
// a dropdown selectbox.
var templates = [];
templates.push(t);
// Print-widget from the Dojo Toolkit
// see here for more info:
// https://developers.arcgis.com/en/javascript/jsapi/print.html
printer = new Print({
map: map,
templates: templates,
url: "http://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%20Task"
}, dojo.byId("printButton"));
// listeners - added in ArcGis version 3.6
printer.on('print-complete', function(evt){
console.info(evt);
console.log('The url to the print image is : ' + evt.result.url);
});
printer.on('print-start', function(){
console.log('The print operation has started');
});
printer.on('error', function(error){
console.log('The print operation has failed: ' + error);
});
// render the widget gui
printer.startup();
});
</script>
</head>
<body>
<div id="printButton"></div>
<div id="claro">
<div id="mapDiv"></div>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment