3

I want to print this map. Can anyone please suggest to me how to print and save the displaying pap in ArcGIS using JavaScript?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=7,IE=9" />
    <!--The viewport meta tag is used to improve the presentation and behavior of the samples on iOS devices-->
    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
    <title> World Street Map</title>
    <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.2/js/dojo/dijit/themes/claro/claro.css">
    <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.2/js/esri/css/esri.css" />

    <style>
      html,body,#map,.map.container{
        padding:0;
        margin:0;
        height:100%;
      }
    </style>
    <script type="text/javascript">var djConfig = {parseOnLoad: true};</script>
    <script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=3.2"></script>
    <script type="text/javascript">
      dojo.require("esri.map");

      var map;

      function init() {
        var initExtent = new esri.geometry.Extent({"xmin":-17731,"ymin":6710077,"xmax":-12495,"ymax":6712279,"spatialReference":{"wkid":102100}});
        map = new esri.Map("map",{extent:initExtent});

       //Add the world street map layer to the map. View the ArcGIS Online site for services http://arcgisonline/home/search.html?t=content&f=typekeywords:service    
        var basemap = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer");
        map.addLayer(basemap);
        dynamicMapServiceLayer = newesri.layers.ArcGISDynamicMapServiceLayer("http://maverick.arcgis.com/ArcGIS/rest/services/World_WGS84/MapServer");  

        dojo.connect(map, 'onLoad', function(theMap) {
          //resize the map when the browser resizes
          dojo.connect(window, 'resize', map,map.resize);
        });
     }
     dojo.addOnLoad(init);
    </script>
  </head>

  <body class="claro">
    <div id="map">
    </div>
  </body>
</html>
6
  • 2
    Please enter the code in proper format
    – Sunil
    Dec 6, 2012 at 8:08
  • 1
    I was doing this few weeks ago. Please write which version of arcgis api are you using, and what server-side language are you fluent in. and as @Sunil wrote before - reformat your code.
    – Krystian
    Dec 6, 2012 at 8:38
  • @Mayank and please cut off your IP adress from code. It is very unsecure to do such a things.
    – Krystian
    Dec 6, 2012 at 8:43
  • i am using arcgis 10.1 and language is java script.
    – Mayank
    Dec 6, 2012 at 8:45
  • @Mayank I was asking about server side programing language - if you wanna to do this by your own.
    – Krystian
    Dec 6, 2012 at 8:48

1 Answer 1

7

In ArcGIS 10.1 there is option to print map by Export Web Map Task Service. If you are using API v. 3.x you can just use Print Task from API.

The sample of using dijit with PrintTask can be found here: http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples_start.htm#jssamples/widget_print_webmap.html

or just class description in here: http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi_start.htm

EDIT

if I were you I would do it like this:

1) you have to define URL adress to your print service:

var url ='http://servicesbeta4.esri.com/arcgis/rest/services/Utilities/ExportWebMap/GPServer/Export Web Map Task';
var printTask = new esri.tasks.PrintTask(url);

2) then you have to define callback function for print task execute:

var printResult = function(result){
 console.log(result)
}

3) you have to set new print object with your previously parameters and your existing map object:

var params = new esri.tasks.PrintParameters();
  params.map = map;

4) and finally execute print task

printTask.execute(params, printResult);

FYI it is only general idea of this task. Now you should wrap with your own JS code.

2
  • yes i have already gone through with this ,but there is predefined script like print and printdijit like that, i want a simple print button and then i want to print my map .i have that link before but cudn't get how to customized it ,as i am new in arcgis .so could any one please share one demo example for that.
    – Mayank
    Dec 6, 2012 at 8:56
  • @Mayank OK. I edited the code. Can I ask you to please mark the question as solved and award the points?
    – Krystian
    Dec 6, 2012 at 10:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.