Print task doesn't transfer dynamic layer when set the visible layers

4011
3
08-28-2013 03:18 PM
DavidMarquardt
New Contributor III
Hello,

I'm having a problem with a print tool.

My application prints tiled and dynamic layers. 

If I include the dynamic layers without using setVisibleLayers, all elements of the map are shown in the print task image (result 1)

If i filter the dynamic layers, using setVisibleLayers, the tiled images are shown in the print task image, but the dynamic layers are not (result 2).

Situation 2 happens when I use a dynamic service from a server in my company.  When I use a dynamic service from arcgisonline, though, I can use setVisibleLayers and everything works perfectly.


Has anyone else had this issue?  I'm thinking that it's a difference in map server settings, or in internet permissions.   I'm working with 10.11 services.    


Here's a simplified version of the script I'm using:

            <script src="http://js.arcgis.com/3.6/" type="text/javascript"></script>
            <script  type="text/javascript">
   var map; var dynLyr0;var dynLyr3;var visible=[];        
   require([
   "dojo/ready", "dojo/on","dojo/_base/connect", "dojo/dom","dijit/registry","dojo/parser","esri/map","esri/arcgis/utils","esri/dijit/Print","esri/tasks/PrintTemplate","esri/config","esri/graphic","esri/symbols/SimpleMarkerSymbol","esri/geometry/screenUtils","dojo/_base/array","dojo/dom-construct","dojo/query","dojo/_base/Color","dijit/form/Button","dijit/Menu","dijit/form/HorizontalSlider","dijit/TitlePane","dijit/layout/ContentPane","dijit/form/CheckBox",
   ], function(ready, on, connect,
   dom, registry, parser, Map,  arcgisUtils, Print, PrintTemplate, esriConfig, graphic, SimpleMarkerSymbol, screenUtils, arrayUtils, domConstruct, query, Color, Buttn, Menu, HorizontalSlider, TitlePane, ContentPane, CheckBox
   ) {
   ready(function() {

    parser.parse();
    esriConfig.defaults.io.proxyUrl = "/proxy";
    var ext = new esri.geometry.Extent({ "xmin": -17529487, "ymin": 1874364, "xmax": -5084316, "ymax": 7500129, "spatialReference": { "wkid": 102100} });
    map = new esri.Map("map", { extent: ext       
    });
   
    var background = new esri.layers.ArcGISTiledMapServiceLayer("http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer");
    //var dynLyrUrl = "http://internal.domain.com/arcgis/rest/services/fccGridServiceTest/MapServer/";  //My Internal map service DIDN'T WORK
    var dynLyrUrl = "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/";  // THIS ONE WORKS
    dynLyr0 = new esri.layers.ArcGISDynamicMapServiceLayer(dynLyrUrl, {"id": "Original"}); 
    dynLyr0.setVisibleLayers([3]);
    dynLyr0.setOpacity(.85);
    map.addLayers([background, dynLyr0]);
    createPrintDijit();
   
    function createPrintDijit(){
     var printTemplates = new PrintTemplate();
     printTemplates =[{
      label: "Map",
      format: "PDF",
      layout: "MAP_ONLY",
      showAttribution:false,
      exportOptions: {
        width: map.width,
        height: map.height,
        dpi: 96
     }
     }, {
      label: "Landscape",
      format: "png32",
      layout: "A4 Landscape",
      showAttribution:false
     }];
     // print dijit
     printer = new Print({
      map: map,
      templates: printTemplates,
      url: "http://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%2..."
     }, dojo.byId("prnt"));
     console.log(map.getLayer("Original"));
     printer.startup();    
    }
    });
    });

    function changeOpacity(op) {       
    var newOp = (op / 100);
    }

    function updateLayerVisibility0() {
    if(foodLyr0.checked){
    dynLyr0.setVisibility(true);
    }
    else{
    dynLyr0.setVisibility(false);

    }
    }
0 Kudos
3 Replies
DavidMarquardt
New Contributor III
Looks like I have an issue with how I'm setting up my dynamic layer.

I have a project with a group layer to allow for a smooth transition between two scale dependent sublayers (detailed and general).

While I can get the group layer to show up in the map, it won't get get exported to a print image when I do the following:   dynLayer.setVisibleLayers([0]);

Instead, I needed to include all sublayers (dyLayer.setVisibleLayers([0,1,2)]; )  in order to have image print correctly
0 Kudos
JohnGravois
Frequent Contributor
sorry i didn't catch this thread earlier, because i explained the same thing in this thread.

either way, glad you sorted yourself out. 🙂
0 Kudos
deleted-user-QLNqWRKKIorN
New Contributor
There's still an issue with this.  I am using the JavaScript API v3.5 and I have several group layers in my mapping service.  To turn on individual layers I can't include the group layer IDs because when I do the map displays all children of the group, not just the selected ones. Is there another solution?
0 Kudos