cmv / cmv-app

CMV - The Configurable Map Viewer - A community supported open source mapping framework built with the Esri JavaScript API and the Dojo Toolkit
https://demo.cmv.io/
MIT License
325 stars 278 forks source link

Text color on print #43

Closed archerne closed 7 years ago

archerne commented 10 years ago

I am trying to add different colored text to the map and print it off as a pdf. However all of the text changes to black when it gets printed.

DavidSpriggs commented 10 years ago

In order for this to work the export webmap spec needs to be followed. Have a look at the spec and make sure you are properly defining the text symbol. http://resources.arcgis.com/en/help/main/10.2/index.html#/ExportWebMap_specification/0154000004w8000000/ http://resources.arcgis.com/en/help/rest/apiref/index.html?symbol.html (see the text symbol section)

Also, if the api is not serializing the text symbols properly you can use aspect to modify the json before it is submitted like so:

postCreate: function() {
    this.printTask = new esri.tasks.PrintTask(this.printTaskURL);
    aspect.after(this.printTask, '_createOperationalLayers', this.operationalLayersInspector, false);
},
operationalLayersInspector: function(opLayers) {
    array.forEach(opLayers, function(layer) {
        if (layer.id == "Measurement_graphicslayer") {
            array.forEach(layer.featureCollection.layers, function(fcLayer) {
                array.forEach(fcLayer.featureSet.features, function(feature) {
                    delete feature.attributes;
                    feature.symbol.font.family = "Courier";
                    feature.symbol.font.variant = esri.symbol.Font.VARIANT_NORMAL;
                    feature.symbol.font.size = "32pt";
                });
            });
        }
    });
    return opLayers;
},
archerne commented 10 years ago

It looks correct to me when the JSON gets set. For some reason though the export web map returns it as black. Here is the JSON that is sent, at the bottom you see the esriTS and color blue:

{
      "id": "drawGraphics_poly",
      "minScale": 0,
      "maxScale": 0,
      "featureCollection": {
        "layers": [
          {
            "layerDefinition": {
              "name": "drawGraphics_poly",
              "geometryType": "esriGeometryPoint",
              "drawingInfo": {
                "renderer": {
                  "type": "uniqueValue",
                  "field1": "ren",
                  "field2": null,
                  "field3": null,
                  "fieldDelimiter": ", ",
                  "defaultSymbol": {
                    "color": [
                      0,
                      0,
                      0,
                      64
                    ],
                    "outline": {
                      "color": [
                        0,
                        0,
                        0,
                        255
                      ],
                      "width": 1,
                      "type": "esriSLS",
                      "style": "esriSLSSolid"
                    },
                    "type": "esriSFS",
                    "style": "esriSFSSolid"
                  },
                  "uniqueValueInfos": [
                    {
                      "value": "1",
                      "symbol": {
                        "color": [
                          255,
                          170,
                          0,
                          255
                        ],
                        "outline": {
                          "color": [
                            255,
                            170,
                            0,
                            255
                          ],
                          "width": 1,
                          "type": "esriSLS",
                          "style": "esriSLSSolid"
                        },
                        "type": "esriSFS",
                        "style": "esriSFSForwardDiagonal"
                      },
                      "label": "User drawn polygons",
                      "description": "User drawn polygons"
                    }
                  ]
                }
              },
              "fields": [
                {
                  "name": "OBJECTID",
                  "type": "esriFieldTypeOID",
                  "alias": "OBJECTID",
                  "editable": false,
                  "nullable": false
                },
                {
                  "name": "ren",
                  "type": "esriFieldTypeInteger",
                  "alias": "ren",
                  "editable": true,
                  "nullable": false
                }
              ]
            },
            "featureSet": {
              "geometryType": "esriGeometryPoint",
              "features": [
                {
                  "geometry": {
                    "x": -11028877.012590744,
                    "y": 4953918.636584341,
                    "spatialReference": {
                      "wkid": 102100
                    }
                  },
                  "symbol": {
                    "color": [
                      0,
                      0,
                      205,
                      255
                    ],
                    "type": "esriTS",
                    "angle": 0,
                    "xoffset": 0,
                    "yoffset": 0,
                    "text": "Text12341243123",
                    "align": "middle",
                    "decoration": "none",
                    "rotated": false,
                    "kerning": true,
                    "font": {
                      "size": 20,
                      "style": "normal",
                      "weight": "normal"
                    }
                  }
                }
              ]
            }
          }
        ]
      }
    }
DavidSpriggs commented 10 years ago

So the issue here I think is how the layer is symbolized. When printing you have to think like desktop. Meaning that in desktop, you do not apply symbology to an individual feature but rather set up a renderer on the layer.

Basically the individual features' symbol properties are ignored, only renderers are applied.

In your json above, you have a render with a default value set but no classes defined. This is why they are all symbolized with the default symbol, which is black text.

To fix, set up a render with a class for each color. Then each feature needs an attribute to put it in the proper class. Make sense?

Again, this is due to the fact that we can do things on the web that can not be done in desktop, like apply a symbol to each feature directly. The rendering of the map into a pdf (or other formats) happens in a desktop/server context (ArcObjects) so we have to follow those rules.

archerne commented 10 years ago

I tried changing the default symbol color, and it still printed in black. I changed it to:

"defaultSymbol": {
                    "color": [
                      255,
                      0,
                      0,
                      64
                    ],
                    "outline": {
                      "color": [
                        255,
                        0,
                        0,
                        255
                      ],

I also tried a ClassBreakRenderer and it still stayed black there as well. I have the JSON sting for that too, if that would help.

green3g commented 7 years ago

I'm fairly certain this has been fixed in more recent updates. I'm able to print colored text.