Customize the PrintTemplate

891
11
09-11-2018 05:59 AM
DavidKucharski
New Contributor II

I have 2 Graphic Layers that I add to my map.

var colorOverlayLyr = new GraphicsLayer({ opacity: 0.5 });
var locationOverlayLyr = new GraphicsLayer({ opacity: 0.5 });

var map = new Map({
basemap: basemapDefault,
layers: [colorOverlayLyr, locationOverlayLyr] 
});

I add graphics to the colorOverlayLyr using the QueryTask, I do this for 5 colors, only the Blue code is included but the other colors are the same. They all are added to the colorOverlayLyr.

params.where = "ID_ IN (" + blue.value + ")";
qTask.execute(params)
.then(getBlueResults)
.catch(promiseRejected);

function getBlueResults(response) {
var peakResults = arrayUtils.map(response.features, function (
feature) {


feature.symbol = {
type: "simple-fill", // autocasts as new PointSymbol3D()
color: {
r: 0,
g: 0,
b: 255,
a: 0.5
},
style: "solid",
opacity: 0.2,
outline: { color: "black", width: 1 }
};

return feature;
});


colorOverlayLyr.addMany(peakResults);

}

I add Graphics to the locationOverlayLyr. The user has the option to add up to 5 different locations on the map. This code is used passing in the different styles. 

var symbolBlack = {
type: "simple-marker", // autocasts as new SimpleMarkerSymbol()
style: values[0],
color: values[1],
size: "8px",
outline: {
color: values[1]
}
};

var point = {
type: "point", 
longitude: values[9],
latitude: values[8]
};

var lineAtt = {
Name: values[2],
Number: values[3],
Display: values[4]
};

var pointGraphic = new Graphic({
geometry: point,
symbol: symbolBlack,
attributes: lineAtt
});
locationOverlayLyr.add(pointGraphic);

The layers come out on the map. I then use the PrintTask to allow a user to print the map. I want to customize the Legend so the user knows exactly what is on the map. I use the LegendLayer to tell what layers to show but I do know know how to customize the description that comes out for the Graphics/Features that are displayed. I can customize the title of the actual layer but the individual graphics I don't know how to. They system shows some default values. How can I change those descriptions.

var printTask = new PrintTask({
url: "https://esridev.nsamedia.com/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Ma..."
});

var colorlegendLayer = new LegendLayer();
colorlegendLayer.layerId = colorOverlayLyr.id;
colorlegendLayer.title = "Color: This is the color";

var locationlegendLayer = new LegendLayer();
locationlegendLayer.layerId = locationOverlayLyr.id;
locationlegendLayer.title = "Location: This is the location";


var template = new PrintTemplate({
format: "pdf",
exportOptions: {
dpi: 300
},
layout: "tabloid-ansi-b-landscape",
layoutOptions: {
titleText: "Test Map",
authorText: "Ben Loewe",
copyrightText: "My Company",
scalebarUnit: "Miles",
legendLayers: [colorlegendLayer, locationlegendLayer]
},
preserveScale: true
});

var params = new PrintParameters({
view: view,
template: template
});

printTask.execute(params).then(printResult, promiseRejected);

0 Kudos
11 Replies
DavidKucharski
New Contributor II

Here is my print code, I am using my own print service on my server. How can I customize the Legend?

document.body.style.cursor = "wait";

var printTask = new PrintTask({
url: "https://esridev.nsamedia.com/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Ma..."
});

var colorlegendLayer = new LegendLayer();
//RJS not fireLayer.layerId. Its fireLayer.id
colorlegendLayer.layerId = colorOverlayLyr.id;
colorlegendLayer.title = "Color: This is the color";

var locationlegendLayer = new LegendLayer();
//RJS not fireLayer.layerId. Its fireLayer.id
locationlegendLayer.layerId = locationOverlayLyr.id;
locationlegendLayer.title = "Location: This is the location";


var template = new PrintTemplate({
format: "pdf",
exportOptions: {
dpi: 300
},
layout: "tabloid-ansi-b-landscape",
layoutOptions: {
titleText: "Test Map",
authorText: "Ben Loewe",
copyrightText: "My Company",
scalebarUnit: "Miles",
legendLayers: [colorlegendLayer, locationlegendLayer]
},
preserveScale: true
});

var params = new PrintParameters({
view: view,
template: template
});

printTask.execute(params).then(printResult, promiseRejected);

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

David,

  Sorry when you said 

Is there any other way to manipulate the PrintTemplate to show customized text?

I thought you were just talking about adding so custom text element to the layout, not trying to control the text inside the legend element.

Creating a custom text element in the layout is absolutely possible with the use of your own print service that has a custom print layout defined. Like here (image attached) in my custom layout I add the Owner Name, PPIN, Parcel Number, Address to the layout based on the selected parcel Polygon:

0 Kudos