Bugs using ioArgs.content.Web_Map_as_JSON and PrintTask ... any ideas?

859
0
09-13-2013 04:29 PM
TimDuggan
New Contributor
Hello All,

I have a pretty complex app that allows users to toggle all sorts of various layers and then export a high quality pdf of the resulting map including marked up text and shapes.  I posted earlier about a bug with the marked up text a user can add, which shows up perfectly on the web map, exporting as tiny text due to what I think is a bug in Web_Map_as_JSON which was showing the font size in the json as "size":"16pt" when the size attribute is an int.  I solved that using a replace
            ioArgs.content.Web_Map_as_JSON = ioArgs.content.Web_Map_as_JSON.replace(/\"size\":\"16pt\"/g, '"size":16');
 
Similarly, I had an issue with the angle attribute when a shape or text was rotated being exported as the opposite direction that was appearing on the map, thus rotating the wrong way in the pdf version.  I solved that using:
            ioArgs.content.Web_Map_as_JSON = ioArgs.content.Web_Map_as_JSON.replace(/\"angle\":/g, '"angle":-'); // this is backwards...we need + to be -
            ioArgs.content.Web_Map_as_JSON = ioArgs.content.Web_Map_as_JSON.replace(/\"angle\":--/g, '"angle":'); //  and minus (now --) to be plus

These solutions work great, and I hope they are helpful to others.  However, I am now stuck on a differnt (but related?) issue I can't seem to resolve. 

I have a dynamic map service that is declared like so:
_myLayer = new esri.layers.ArcGISDynamicMapServiceLayer("https://www.myDomain.com/arcgis/rest/services/myDir/mySubDir/MapServer", { id: "myLayer", visible: true, opacity: .6 });
_myLayer..setVisibleLayers([0]);
_myLayer.setLayerDefinitions(["MyVariable='NotARealValue'"]);
map.addLayer(_myLayer);


I then have a select menu that dynamically changes the filtering value for MyVariable like so:
dojo.connect(dijit.byId("mySelectMenu"), "onChange", dojo.hitch(this, function () {
        if (dijit.byId("mySelectMenu").item) {
            //Setup a filter on the dynamic map service
            var layerDefinitions = [];
            if (dijit.byId("mySelectMenu").item.name.toUpperCase() == "ALL") {
                layerDefinitions[0] = "1=1"; ///show all
            } else {
                layerDefinitions[0] = "MyVariable = '" + dijit.byId("mySelectMenu").item.name + "'";
            }
            _myLayer.setLayerDefinitions(layerDefinitions);
            _myLayer.show();
        } else {
            consoleLog('if dijit.byId("mySelectMenu").item is not true I see this');
        }
    }));

On the webmap, this works perfectly...when a selection is made, it shows those polys and only those polys (it's a cloropleth overlay with transparency).  However, when I go to print with ALL other layers turned off for the sake of simplifying things, the following JSON is produced and the layer in question doesn't show up at all in the pdf:
{
   "mapOptions":{
      "showAttribution":true,
      "extent":{
         "xmin":-13727299.245256329,
         "ymin":5985761.303078965,
         "xmax":-13482700.754743671,
         "ymax":6104238.696921035,
         "spatialReference":{
            "wkid":102100
         }
      },
      "spatialReference":{
         "wkid":102100
      },
      "scale":577790.5542890005
   },
   "operationalLayers":[
      {
         "id":"myLayer",
         "title":"myLayer",
         "opacity":0.6,
         "minScale":0,
         "maxScale":0,
         "url":"https://www.myDomain.com/arcgis/rest/services/myDir/mySubDir/MapServer",
         "visibleLayers":[0],
         "layers":[
            {
               "id":0,
               "layerDefinition":{
                  "definitionExpression":"MyVariable = 'Valid Value'",
                  "layerTimeOptions":null
               }
            }
         ]
      },
      {
         "id":"streetMap",
         "title":"streetMap",
         "opacity":1,
         "minScale":591657527.591555,
         "maxScale":9027.977411,
         "url":"https://www.caimaps.info/arcgis/rest/services/CAI_Basemap/MapServer"
      },
      {
         "id":"bufferLayer",
         "minScale":0,
         "maxScale":0,
         "featureCollection":{
            "layers":[

            ]
         }
      },
      {
         "id":"drawLayer",
         "minScale":0,
         "maxScale":0,
         "featureCollection":{
            "layers":[

            ]
         }
      },
      {
         "id":"zipLayer",
         "minScale":0,
         "maxScale":0,
         "featureCollection":{
            "layers":[

            ]
         }
      },
      {
         "id":"locatorMatchesLayer",
         "minScale":0,
         "maxScale":0,
         "featureCollection":{
            "layers":[

            ]
         }
      },
      {
         "id":"graphicsLayer0",
         "minScale":0,
         "maxScale":0,
         "featureCollection":{
            "layers":[

            ]
         }
      },
      {
         "id":"graphicsLayer1",
         "minScale":0,
         "maxScale":0,
         "featureCollection":{
            "layers":[

            ]
         }
      }
   ],
   "exportOptions":{
      "outputSize":[
         null,
         null
      ],
      "dpi":200
   },
   "layoutOptions":{
      "titleText":"testing",
      "authorText":"my author name",
      "copyrightText":"copy text here",
      "scaleBarOptions":{
         "metricUnit":"Kilometers",
         "metricLabel":"km",
         "nonMetricUnit":"Miles",
         "nonMetricLabel":"mi"
      },
      "legendOptions":{
         "operationalLayers":[
            {
               "id":"myLayer",
               "subLayerIds":[
                  0
               ]
            },
            {
               "id":"bufferLayer"
            },
            {
               "id":"drawLayer"
            },
            {
               "id":"zipLayer"
            },
            {
               "id":"locatorMatchesLayer"
            },
            {
               "id":"graphicsLayer0"
            },
            {
               "id":"graphicsLayer1"
            }
         ]
      }
   }
}
This fails even if I go straight to the REST print service url and plug the JSON in manually.  Has anyone ever run into this situation?  I don't have the same problem with a queried feature layer because the resulting JSON actually includes the matched features.  I'm guessing this is a bug in a little used corner of the API...but I would LOVE to be proved wrong.  Any help will be greatly appreciated.

Thanks in advance,
Tim

PS - sorry I couldn't share a link to the app...it contains confidential data provided by a client.
0 Kudos
0 Replies