Save screen Shot as Image

2409
1
12-23-2015 04:01 AM
ashrafsalim
New Contributor

this Code

function Print() {

    debugger

    require(["esri/map", "esri/config", "esri/geometry/Extent", "esri/layers/ArcGISTiledMapServiceLayer",

            "esri/tasks/PrintTask", "esri/tasks/PrintTemplate", "esri/tasks/PrintParameters"],

     function (Map,esriConfig, Extent, ArcGISTiledMapServiceLayer, PrintTask, PrintTemplate, PrintParameters) {

        

      

         esriConfig.defaults.io.alwaysUseProxy = false;

         var template = new PrintTemplate();

         template.exportOptions = {

             width: 500,

             height: 400,

             dpi: 96

         };

         template.format = "JPG";

         template.layout = "MAP_ONLY";

         template.preserveScale = false;

         var params = new PrintParameters();

         params.map = layerMap;

         params.template = template;

         var printTask = new PrintTask("http://maps.decaturil.gov/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%2...");

         printTask.execute(params, function (imagePath) {

             window.open(imagePath.url);

             debugger;

            

         }, function (err) {

             console.log(err);

         });

     });

}

this method not run and idea

0 Kudos
1 Reply
RobertScheitlin__GISP
MVP Emeritus

Ashraf,

  First you should not be using another persons print service without permission. maps.decaturil.gov is not a sample sever it belongs to a local government agency.

I have whipped up a sample that uses all public sample services that shows you how to do this. You will have to make sure that your browser is not blocking popups:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
<title>FeatureLayer</title>

<link rel="stylesheet" href="http://js.arcgis.com/3.15/esri/css/esri.css">
<script src="http://js.arcgis.com/3.15/"></script>

<style>
html, body, #map {
  padding: 0;
  margin: 0;
  height: 100%;
  width: 100%;
}
</style>

<script>
require([
    "esri/map",
    "esri/layers/FeatureLayer",
    "esri/tasks/PrintTask",
    "esri/tasks/PrintTemplate",
    "esri/tasks/PrintParameters",
    "esri/config",
    "dojo/on",
    "dojo/_base/lang",
    "dojo/domReady!"
  ],
  function(
    Map,
    FeatureLayer,
    PrintTask,
    PrintTemplate,
    PrintParameters,
    esriConfig,
    on,
    lang
  ) {

    var map = new Map("map", {
      basemap: "hybrid",
      center: [-82.44109, 35.6122],
      zoom: 17
    });

    /****************************************************************
     * Add feature layer - A FeatureLayer at minimum should point
     * to a URL to a feature service or point to a feature collection
     * object.
     ***************************************************************/

    // Carbon storage of trees in Warren Wilson College.
    var featureLayer = new FeatureLayer("https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/Landscape_Trees/FeatureServer/0");

    map.addLayers([featureLayer]);

    esriConfig.defaults.io.alwaysUseProxy = false;
    var template = new PrintTemplate();
    template.exportOptions = {
      width: 500,
      height: 400,
      dpi: 96
    };
    template.format = "JPG";
    template.layout = "MAP_ONLY";
    template.preserveScale = false;
    var params = new PrintParameters();
    params.map = map;
    params.template = template;
    var printTask = new PrintTask("http://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%2...");
    on(map, "layers-add-result", lang.hitch(this, function(){
      printTask.execute(params, function (imagePath) {
        console.info(imagePath.url);
        window.open(imagePath.url, "_blank");
      }, function (err){
        console.log(err);
      });
    }));

  });
</script>
</head>

<body>
  <div id="map"></div>
</body>

</html>