Select to view content in your preferred language

Problen with the Print Task

13776
44
07-03-2012 04:42 AM
by Anonymous User
Not applicable
Original User: Schnoerkel

Hey there,

i have a problem with the PrintTask. In my applikation i add some Points to the the map as TextSymbol with angle and offset. In the Map all is displayed right. But when i use the PrintTask only little Points are displayed at the Map.

[ATTACH=CONFIG]15706[/ATTACH][ATTACH=CONFIG]15707[/ATTACH]

my code is

add the point:
var xmuss = mapPoint.x - ((mapPoint.x - this.inputPoints[this.inputPoints.length-2].x)/2);
   var ymuss = mapPoint.y - ((mapPoint.y - this.inputPoints[this.inputPoints.length-2].y)/2);   
   var winkelmuss = (Math.atan2((this.inputPoints[this.inputPoints.length-2].y - mapPoint.y), (this.inputPoints[this.inputPoints.length-2].x - mapPoint.x))*180)/Math.PI;
   
   var pt = new esri.geometry.Point(xmuss, ymuss, this._map.spatialReference);
   var textSymbol = new esri.symbol.TextSymbol();
   textSymbol.setColor(new dojo.Color([0,0,0])).setFont(new esri.symbol.Font("12pt").setWeight(esri.symbol.Font.WEIGHT_BOLD));
   var gemessen = '123';     
 
   textSymbol.text = dojo.number.format(gemessen.toFixed(1), {pattern: this.numberPattern}) + zeichen;  
   
   textSymbol.angle = 90;
   
   this.textGraphic=new esri.Graphic();
   this.textGraphic.setSymbol(textSymbol);
   this.textGraphic.setGeometry(pt);
   this._map.graphics.add(this.textGraphic);
   this.measureGraphics.push(this.textGraphic);
 
   


print:

 
//in the init()
// get print templates from the export web map task
        var printInfo = esri.request({
          "url": app.printUrl,
          "content": { "f": "json" }
        });
        printInfo.then(handlePrintInfo, handleError);  






//Print Funktion
   function handlePrintInfo(resp) 
   {
        var layoutTemplate, templateNames, mapOnlyIndex, templates;

        layoutTemplate = dojo.filter(resp.parameters, function(param, idx) {
          return param.name === "Layout_Template";
        });
       
        if ( layoutTemplate.length == 0 ) {
          console.log("print service parameters name for templates must be \"Layout_Template\"");
          return;
        }
        templateNames = layoutTemplate[0].choiceList;

        // remove the MAP_ONLY template then add it to the end of the list of templates
        mapOnlyIndex = dojo.indexOf(templateNames, "MAP_ONLY");
        if ( mapOnlyIndex > -1 ) {
          var mapOnly = templateNames.splice(mapOnlyIndex, mapOnlyIndex + 1)[0];
          templateNames.push(mapOnly);
        }
       
        // create a print template for each choice
        templates = dojo.map(templateNames, function(ch) {
          var plate = new esri.tasks.PrintTemplate();
          plate.layout = plate.label = ch;   
          plate.format = "PDF";
          plate.layoutOptions = {
            "authorText": "Stadt Osnabrück Fachbereich Städtebau",
            "copyrightText": "Copyright Stadt Osnabrück",
            "legendLayers": [],
            "titleText": "Messen",
            "scalebarUnit": "Kilometers"
          };
          return plate;
        }); 
  
  
  // create the print dijit
        app.printer = new esri.dijit.Print({
          "map": app.map,
          "templates": templates,
          url: app.printUrl
        }, dojo.byId("print_button"));
   
        app.printer.startup();
      }
   
   function handleError(err) {
        console.log("Something broke: ", err);
      }







Hopeyou can Help me
44 Replies
by Anonymous User
Not applicable
Original User: apollolm

Unfortunately, I'm not aware of a way to remove the color flag from the JSON without doing some manual manipulation...


I was able to verify that removing the color property from the JSON string directly in the rest endpoint will trigger the text to show up at a readable size for me.

So then I went to work to remove the color property from all text symbols programmatically.

dojo.forEach(_markupTool.markupTextLayer.graphics, function (item) {
                    //Remove color property from each graphics' symbol - trying GP Print Task bug workaround
                    if (item && item.symbol && item.symbol.color) {
                        delete item.symbol.color;
                    }
                });


I was hopeful that this would work, but my hopes were dashed when I checked out the map JSON string that was being posted to the server:

*snip* {"id":"graphicsLayer47","featureCollection":{"layers":[{"layerDefinition":{"name":"pointLayer","geometryType":"esriGeometryPoint"},"featureSet":{"geometryType":"esriGeometryPoint","features":[{"geometry":{"x":-13619523.035374189,"y":6030400.527597526,"spatialReference":{"wkid":102100}},"symbol":{"color":[0,0,0,255],"type":"esriTS","angle":0,"xoffset":0,"yoffset":0,"text":"linguist","align":"start","decoration":"none","rotated":false,"kerning":true,"font":{"size":"16pt","style":"normal","variant":"normal","weight":"bold","family":"Arial"}}}]}}]}}],"exportOptions": *snip*


Looks like at some point after I remove the color property but before the map object gets serialized the color property is being added back in as [0,0,0,255]. 

It'd be a pain, but I'm wondering if manually calling the GP Print endpoint would do the trick.  That way we could completely control what was being included in the JSON string as it was passed to the server.

Also - just thinking out loud - I wonder if I pass this turkey thru a proxy first, can I scrub out that portion of the JSON string before it gets passed to the server.  I'm going to try that now.

Ryan
0 Kudos
JohnGravois
Deactivated User
it sounds like it might be helpful in this case to use esri.setRequestPreCallback() to manipulate the webmap JSON immediately before executing the print.
by Anonymous User
Not applicable
Original User: apollolm

Thanks!  That did the trick.

The text doesn't show up exactly where it was in the web map, but it's pretty close.

Here's what I did:

function scrubPrintTask(ioArgs) {
    // inspect ioArgs
    //console.log(ioArgs.url, ioArgs.content);
    if (ioArgs.url.indexOf("ExportWebMap") > -1) {
        if (ioArgs.content.Web_Map_as_JSON) {
            ioArgs.content.Web_Map_as_JSON = ioArgs.content.Web_Map_as_JSON.replace('"symbol":{"color":[0,0,0,255],"type":"esriTS"', '"symbol":{"type":"esriTS"');
        }
    }

    // don't forget to return ioArgs.
    return ioArgs;
}


Thanks!
0 Kudos
AdrianMarsden
Honored Contributor
😄  Brilliant - I had to use this "replaceAll" function as I couldn't get the normal javascript one working.  And, something is still not quite right with the size - I had three text annotations of different sizes and they all came out the same, but they are readable and in almost the location the user addded them, so a good work around until esri solve the bug

Images are screen, without fix, after fix

Cheers

ACM
0 Kudos
by Anonymous User
Not applicable
Original User: TimDuggan

I think I have figured out the root of this problem.  My colleague Tyler Schrag noted above that altering the json referencing "esriTS" will allow the annotations to be passed and visible...however, as Adrian Marsden notes, all custom formatting like size, etc is ignored using this solution.  I started wondering why and eventually landed on the/a major issue.  The json generated by the API outputs 

"symbol":{
     "type":"esriTS",
     "angle":45,
     "xoffset":0,
     "yoffset":0,
     "text":"This is a test.",
     "align":"middle",
     "decoration":"none",
     "rotated":false,
     "kerning":true,
     "font":{
           "size":"16pt",
           "style":"normal",
           "variant":"normal",
           "weight":"bold",
           "family":"Arial"
     }
}


The problem with this is that the object of type esriTS is epxecting font size to be an int, 16 in this case, and not "16pt".  Changing this to an int value without quotes makes the replace outlined in previous posts unnecessary and re-enables formatting to the elements.

An additional problem I'm running into is that setAngle(45) for a text element rotates counterclockwise on the map (sloping upward to the right), but passes the json value int 45 ("angle":45) which rotates clockwise on the pdf printout (sloping downward to the right).  I'm guessing these are simply bugs in a seldom used portion of the API.  My workaround for now is to get into the json itself via the methods described by users above and do the following replaces:

   
ioArgs.content.Web_Map_as_JSON = ioArgs.content.Web_Map_as_JSON.replace(/\"size\":\"16pt\"/g, '"size":16');
ioArgs.content.Web_Map_as_JSON = ioArgs.content.Web_Map_as_JSON.replace(/\"angle\":/g, '"angle":-');


I have some concerns about the angle replace becoming too greedy and screwing something else up...but I'll cross that bridge (and drill down to that node if needed) when I come to it.

I hope this is helpful!  I've never reported a bug before...can anyone help me with that?
0 Kudos
AdrianMarsden
Honored Contributor
Sorted!!

Using the above post I looked at my code - Tim's suggestion is spot on.

I have a dojo Combo box that allows font selection. So it had options like "12pt" and "16pt" - as a combo box, these were the values returned.

I simply changed these to "12" and "16" etc so at creation time this is what was set. And it all works - with no need to use the "ioArgs.content.Web_Map_as_JSON.replace" lines at all.

So, I think the bug gets re-worded to say that when textmarkers are created with "pt" in them they fail to get printed, but work fine without "pt" in the initial creation

ACM

PS added PDf generated from jsapi application - all text added without "pt" in command and no further adjustments.
0 Kudos
by Anonymous User
Not applicable
Original User: fcbassongis

Ok so here is my take on the issue...

1) The font size setting is indeed a problem - it must be an INTEGER.

2) Layer order: It really doesn't matter in which order you add the feature or label layers, as long as each layer is defined in a seperate '"layerDefinition": {...}' section within the map graphics featureCollection layers.  The layers are then added to the map in the order that you specify them in the JSON passed to the ExportWebMap service.  DO NOT group text symbols (esriTS) with another esriGeometry type within a layerDefinition section - it will cause the feature type specified first to draw and the second type won't draw at all.

3) The ArcGIS JavaScript API (3.5) makes both mistakes!  Inspecting the JSON generated, it is clear that "pt" is included in the font size and text symbols are grouped within other layerDefinition geometry types. Fail.

It works very well after all - Esri just needs to document it properly.
0 Kudos
AdrianMarsden
Honored Contributor
OK - old thread and probably old issue, but one just reported to me.

By using the advice above my text prints fine - the size is correct and it all looks OK.

HOWEVER

If the user adds a graphic point first - just that a point.  Then adds text, when it prints no text is printed

If the user adds text first, the a plain point, just the text is printed.

Any ideas before I start pulling my code apart.

ACM
0 Kudos
AdrianMarsden
Honored Contributor
Of first of two posts - this is the "ioArgs.content.Web_Map_as_JSON" for text added last

{
    "mapOptions": {
        "showAttribution": true,
        "extent": {
            "xmin": 283587.7543757293,
            "ymin": 78359,
            "xmax": 342600.2456242707,
            "ymax": 113602,
            "spatialReference": {
                "wkid": 27700
            }
        },
        "spatialReference": {
            "wkid": 27700
        },
        "scale": 155427.79855309209
    },
    "operationalLayers": [{
        "id": "mainbasemaps",
        "title": "mainbasemaps",
        "opacity": 1,
        "minScale": 0,
        "maxScale": 0,
        "url": "http://eddc-gis2/arcgis/rest/services/BaseMapOSNonTiled/MapServer",
        "visibleLayers": null,
        "layers": []
    }, {
        "id": "altbasemaps",
        "title": "altbasemaps",
        "opacity": 1,
        "minScale": 0,
        "maxScale": 0,
        "url": "http://eddc-gis2/arcgis/rest/services/alt_basemaps/MapServer",
        "visibleLayers": null,
        "layers": []
    }, {
        "id": "aerialmaps",
        "title": "aerialmaps",
        "opacity": 1,
        "minScale": 0,
        "maxScale": 0,
        "url": "http://eddc-gis2/arcgis/rest/services/LIVEinternal/aerials/MapServer",
        "visibleLayers": null,
        "layers": []
    }, {
        "id": "mainmap",
        "title": "mainmap",
        "opacity": 0.9,
        "minScale": 0,
        "maxScale": 0,
        "url": "http://eddc-gis2/arcgis/rest/services/test/emap2/MapServer",
        "visibleLayers": [],
        "layers": []
    }, {
        "id": "graphicsLayer0",
        "minScale": 750,
        "maxScale": 0,
        "featureCollection": {
            "layers": []
        }
    }, {
        "id": "usergraphics",
        "minScale": 0,
        "maxScale": 0,
        "featureCollection": {
            "layers": [{
                "layerDefinition": {
                    "name": "pointLayer",
                    "geometryType": "esriGeometryPoint"
                },
                "featureSet": {
                    "geometryType": "esriGeometryPoint",
                    "features": [{
                        "geometry": {
                            "x": 314019.2829638273,
                            "y": 87077.22170361727,
                            "spatialReference": {
                                "wkid": 27700
                            }
                        },
                        "symbol": {
                            "color": [0, 0, 0, 255],
                            "size": 54,
                            "angle": 0,
                            "xoffset": 0,
                            "yoffset": 0,
                            "type": "esriSMS",
                            "style": "esriSMSCircle",
                            "outline": {
                                "color": [255, 0, 0, 255],
                                "width": 0.75,
                                "type": "esriSLS",
                                "style": "esriSLSSolid"
                            }
                        }
                    }, {
                        "geometry": {
                            "x": 318090.52800466743,
                            "y": 84938.78996499417,
                            "spatialReference": {
                                "wkid": 27700
                            }
                        },
                        "symbol": {
                            "color": [0, 0, 0, 255],
                            "type": "esriTS",
                            "horizontalAlignment": "left",
                            "angle": 0,
                            "xoffset": 0,
                            "yoffset": 0,
                            "text": "text last",
                            "rotated": false,
                            "kerning": true,
                            "font": {
                                "size": 54,
                                "style": "normal",
                                "variant": "normal",
                                "decoration": "none",
                                "weight": "normal",
                                "family": "verdana"
                            }
                        }
                    }]
                }
            }]
        }
    }, {
        "id": "graphicsLayer1",
        "minScale": 0,
        "maxScale": 0,
        "featureCollection": {
            "layers": []
        }
    }, {
        "id": "graphicsLayer2",
        "minScale": 0,
        "maxScale": 0,
        "featureCollection": {
            "layers": []
        }
    }, {
        "id": "map_graphics",
        "minScale": 0,
        "maxScale": 0,
        "featureCollection": {
            "layers": []
        }
    }],
    "exportOptions": {
        "outputSize": [2125.98, 2362.2],
        "dpi": "96"
    },
    "layoutOptions": {
        "titleText": "",
        "authorText": "                    ",
        "copyrightText": "Crown Copyright and database rights 2014 Ordnance Survey 100023746  ",
        "scaleBarOptions": {
            "metricUnit": "Kilometers",
            "metricLabel": "km",
            "nonMetricUnit": "Miles",
            "nonMetricLabel": "mi"
        },
        "legendOptions": {
            "operationalLayers": [{
                "id": "mainmap"
            }]
        }
    }
}

0 Kudos
AdrianMarsden
Honored Contributor
and this one is text first


{
    "mapOptions": {
        "showAttribution": true,
        "extent": {
            "xmin": 283587.7543757293,
            "ymin": 78359,
            "xmax": 342600.2456242707,
            "ymax": 113602,
            "spatialReference": {
                "wkid": 27700
            }
        },
        "spatialReference": {
            "wkid": 27700
        },
        "scale": 155427.79855309209
    },
    "operationalLayers": [{
        "id": "mainbasemaps",
        "title": "mainbasemaps",
        "opacity": 1,
        "minScale": 0,
        "maxScale": 0,
        "url": "http://eddc-gis2/arcgis/rest/services/BaseMapOSNonTiled/MapServer",
        "visibleLayers": null,
        "layers": []
    }, {
        "id": "altbasemaps",
        "title": "altbasemaps",
        "opacity": 1,
        "minScale": 0,
        "maxScale": 0,
        "url": "http://eddc-gis2/arcgis/rest/services/alt_basemaps/MapServer",
        "visibleLayers": null,
        "layers": []
    }, {
        "id": "aerialmaps",
        "title": "aerialmaps",
        "opacity": 1,
        "minScale": 0,
        "maxScale": 0,
        "url": "http://eddc-gis2/arcgis/rest/services/LIVEinternal/aerials/MapServer",
        "visibleLayers": null,
        "layers": []
    }, {
        "id": "mainmap",
        "title": "mainmap",
        "opacity": 0.9,
        "minScale": 0,
        "maxScale": 0,
        "url": "http://eddc-gis2/arcgis/rest/services/test/emap2/MapServer",
        "visibleLayers": [],
        "layers": []
    }, {
        "id": "graphicsLayer0",
        "minScale": 750,
        "maxScale": 0,
        "featureCollection": {
            "layers": []
        }
    }, {
        "id": "usergraphics",
        "minScale": 0,
        "maxScale": 0,
        "featureCollection": {
            "layers": [{
                "layerDefinition": {
                    "name": "pointLayer",
                    "geometryType": "esriGeometryPoint"
                },
                "featureSet": {
                    "geometryType": "esriGeometryPoint",
                    "features": [{
                        "geometry": {
                            "x": 312785.5723453909,
                            "y": 85884.63477246207,
                            "spatialReference": {
                                "wkid": 27700
                            }
                        },
                        "symbol": {
                            "color": [0, 0, 0, 255],
                            "type": "esriTS",
                            "horizontalAlignment": "left",
                            "angle": 0,
                            "xoffset": 0,
                            "yoffset": 0,
                            "text": "text first",
                            "rotated": false,
                            "kerning": true,
                            "font": {
                                "size": 54,
                                "style": "normal",
                                "variant": "normal",
                                "decoration": "none",
                                "weight": "normal",
                                "family": "verdana"
                            }
                        }
                    }, {
                        "geometry": {
                            "x": 311140.62485414237,
                            "y": 84239.68728121354,
                            "spatialReference": {
                                "wkid": 27700
                            }
                        },
                        "symbol": {
                            "color": [0, 0, 0, 255],
                            "size": 54,
                            "angle": 0,
                            "xoffset": 0,
                            "yoffset": 0,
                            "type": "esriSMS",
                            "style": "esriSMSCircle",
                            "outline": {
                                "color": [255, 0, 0, 255],
                                "width": 0.75,
                                "type": "esriSLS",
                                "style": "esriSLSSolid"
                            }
                        }
                    }]
                }
            }]
        }
    }, {
        "id": "graphicsLayer1",
        "minScale": 0,
        "maxScale": 0,
        "featureCollection": {
            "layers": []
        }
    }, {
        "id": "graphicsLayer2",
        "minScale": 0,
        "maxScale": 0,
        "featureCollection": {
            "layers": []
        }
    }, {
        "id": "map_graphics",
        "minScale": 0,
        "maxScale": 0,
        "featureCollection": {
            "layers": []
        }
    }],
    "exportOptions": {
        "outputSize": [2125.98, 2362.2],
        "dpi": "96"
    },
    "layoutOptions": {
        "titleText": "",
        "authorText": "                    ",
        "copyrightText": "Crown Copyright and database rights 2014 Ordnance Survey 100023746  ",
        "scaleBarOptions": {
            "metricUnit": "Kilometers",
            "metricLabel": "km",
            "nonMetricUnit": "Miles",
            "nonMetricLabel": "mi"
        },
        "legendOptions": {
            "operationalLayers": [{
                "id": "mainmap"
            }]
        }
    }
}




0 Kudos