How-to guide on adding selected parcel information to the Print Service for a WAB application. Thanks Robert
Solved! Go to Solution.
James,
The first part of this is following the tutorial for creating a custom print service:
then follow this blog post (even know it says printing popups):
Printing Popups from Web Application | ArcGIS Blog
I personally have made changes to the Print Widgets Print.js to look for a specific layer in the map and if that layer is present then add certain attributes to the layouts customTextElements.
So in the Print.js print function:
print: function() {
if (this.printSettingsFormDijit.isValid()) {
var form = this.printSettingsFormDijit.get('value');
lang.mixin(form, this.layoutMetadataDijit.get('value'));
this.preserve = this.preserveFormDijit.get('value');
lang.mixin(form, this.preserve);
this.layoutForm = this.layoutFormDijit.get('value');
var mapQualityForm = this.mapQualityFormDijit.get('value');
var mapOnlyForm = this.mapOnlyFormDijit.get('value');
lang.mixin(mapOnlyForm, mapQualityForm);
var elementsObj = this.customTextElementsDijit.get('value');
var cteArray = [];
for (var p in elementsObj) {
var cte = {};
cte[p] = elementsObj[p];
cteArray.push(cte);
}
var template = new PrintTemplate();
template.format = form.format;
template.layout = form.layout;
template.preserveScale = (form.preserveScale === 'true' || form.preserveScale === 'force');
template.label = form.title;
template.exportOptions = mapOnlyForm;
//Hide map attribution
template.showAttribution = false;
//end my change
template.layoutOptions = {
authorText: form.author,
copyrightText: form.copyright,
legendLayers: (this.layoutForm.legend.length > 0 && this.layoutForm.legend[0]) ?
null : [],
titleText: form.title,
customTextElements: cteArray
};
//See if there is a parcel search layer added to the map
var plyr;
array.some(this.map.graphicsLayerIds, lang.hitch(this, function (layerId) {
var lyr = this.map.getLayer(layerId);
if(lyr.name === "Search Results: Parcels"){
plyr = lyr;
return true;
}
}));
if(plyr){
var xppins = "", obj, cTextElements = [];
array.map(plyr.graphics, lang.hitch(this, function(gra, index){
if (plyr.graphics.length === 1){
obj = {OwnerName: "Owner Name: " + gra.attributes.NAME};
cTextElements.push(obj);
obj = {PPIN: "PPIN: " + gra.attributes.PPIN};
cTextElements.push(obj);
obj = {ParcelNum: "Parcel Number: " + gra.attributes.PARCEL_NUMBER};
cTextElements.push(obj);
obj = {StreetAdd: "Street Address: " + gra.attributes.STREET_ADDRESS};
cTextElements.push(obj);
}else if (plyr.graphics.length > 1){
if (xppins === ""){
xppins = gra.attributes.PPIN;
} else {
if([7,16,25,34,43,52,61,70,79,88,97].indexOf(index) > -1){
xppins = xppins + ",\r\n" + gra.attributes.PPIN;
}else{
xppins = xppins + ", " + gra.attributes.PPIN;
}
}
obj = {OwnerName: "Selected PPINs: " + xppins};
cTextElements.push(obj);
}
template.layoutOptions.customTextElements = cTextElements;
}));
}
//end my change
this.printparams.template = template;
this.printparams.extraParameters = { // come from source code of jsapi
printFlag: true
};
var fileHandel = this.printTask.execute(this.printparams);
var result = new printResultDijit({
count: this.count.toString(),
icon: (form.format === "PDF") ? this.pdfIcon : this.imageIcon,
docName: form.title,
title: form.format + ', ' + form.layout,
fileHandle: fileHandel,
nls: this.nls
}).placeAt(this.printResultsNode, 'last');
result.startup();
domStyle.set(this.clearActionBarNode, 'display', 'block');
this.count++;
} else {
this.printSettingsFormDijit.validate();
}
},
I've tried to use that Blog about 40 times now, but I don't seem to understand the link between the customtextelements and parcel layer information and getting them into the map document, all I get is errors, or blank pages.
James,
Not sure if I can explain it any better then the blog post. Once you have your custom text element added to your custom layout for your custom print service, then the print service will just add any text provided in the customTextElements array object that it can find a matching element name for in the print template. So as you can see in my code provided previously "OwnerName" is a custom text element in my print layout and the code:
obj = {OwnerName: "Owner Name: " + gra.attributes.NAME};
Adds the custom text element object to the layoutTemplates customTextElements array.
Can you share the full Print.js your using.
Thank you! I was finally able to solve the issue, it turns out the data wasn't being pushed into the operational layer.
Don't forget to mark this question as answered by clicking on the "Correct Answer" link on the reply that answered your question.
Robert this would be a really cool feature to your Enhanced Search Widget.
Hi Robert,
So, I have followed the tutorial Tanu Posted for printing the popups(Printing Popups from Web Application, #2).
The print service works- map is printed, feature is selected.. but no attributes on the second page.
It appears the problem is seemingly very simple...
The attributes of the popups I want to print are from a rest service layer, which is within the map of the app.
The attributes of the popup only come from one layer.
The attributes have names and aliases, and are named differently in the popups as well.
What name do I put in the "Element Name" text box in the properties box in arcmap when setting up my layout mxd?
The field names listed in the rest service? (PARCELID) The alias names?(Parcel Ident...)
or the names listed in the popup configuration? (i.e. Owner, Sale Price...)
Or something completely different? (like FIELDS)
Then, how should the syntax be changed in the script?
Thank you so much for your help!