WAB Print Widget - How to Strip it down?

970
9
07-13-2020 12:30 PM
Arne_Gelfert
Occasional Contributor III

So in a way this is part 2 to a recent post about manipulating what ends up in the PDF generated with the Print Widget. I have two (2) questions:

1//   How do I hide the Advanced Options in the widget? I've plowed through the code and noticed numerous commented references to things like:

// this.config.showAdvancedOption = this.showAdvancedOptionChk.getValue();‍‍

But I haven't had a chance to figure out what combination of uncommenting what might hide the options. I'm trying to build something where I don't need the user to get lost in options. They should only have to select a papersize and the app takes care of the rest.

2//   Similarly, I would like to limit printing to 2 paper sizes for which I've prepared optimal layouts. I don't need and don't want to see the "MAP_ONLY". How do I hide/remove it?

These may be rudimentary tasks for custom widgeteers. I feel like I'm still only scratching the surface on the widget universe. 

0 Kudos
9 Replies
RobertScheitlin__GISP
MVP Emeritus
0 Kudos
Arne_Gelfert
Occasional Contributor III

So the following seems to have some effect:

// was
var PrintDijit = declare([_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], {
    ...
    //showAdvancedOption: true,
    ...

// changed it to 
var PrintDijit = declare([_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], {
    ...
    showAdvancedOption: false,
    ...‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
Arne_Gelfert
Occasional Contributor III

Thanks, Robert, didn't see this before hit 'Send'... I'll take a look at the link.

0 Kudos
Arne_Gelfert
Occasional Contributor III

Great! My above fix took care of part 1. I adapted your solution in the referenced post as follows:

var layoutItems = array.map(Layout_Template[0].choiceList, function(item) {
          if(item !== "MAP_ONLY")
          return {
            label: item,
            value: item
          };
        });

 That helped with second portion.

0 Kudos
Arne_Gelfert
Occasional Contributor III

Robert Scheitlin, GISP‌, Any suggestions as to how I might force a certain scale for printing when a specific layout is selected?  

I was able to tweak the show/no-show of layout elements based on which layout is selected in there event handler...

onLayoutChange: function(newValue) {
...
}

But I don't know what governs the scale of what in my case is PDF output.

0 Kudos
Arne_Gelfert
Occasional Contributor III

Okay, this here forces the scale to a particular numeric value...

 printDefInspector: function(printDef) {
       
      // don't really need  the following since I removed the
      // Advanced Options
      // if (this.preserve.preserveScale === 'force') {
      //   printDef.mapOptions.scale = this.preserve.forcedScale;
      // }
      printDef.mapOptions.scale = 12000;
      
      return printDef;
    },‍‍‍‍‍‍‍‍‍‍‍

Now, I just need to set it based on the selected layout. Slowly inching closer...

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Arne,

Lines 42-44.

    print: function() {
      if (this.printSettingsFormDijit.isValid()) {
        var form = this.printSettingsFormDijit.get('value');
        lang.mixin(form, this.layoutMetadataDijit.get('value'));
        lang.mixin(form, this.forceAttributesFormDijit.get('value'));
        lang.mixin(form, this.labelsFormDijit.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 = [], hasDate = false, locale = dojoConfig.locale || 'en';
        for (var p in elementsObj) {
          var cte = {};
          if (p === 'Date') {
            hasDate = true;
          }
          cte[p] = elementsObj[p];
          cteArray.push(cte);
        }
        if(!hasDate) {
          cteArray.push({ Date: new Date().toLocaleString(locale) });
        }

        var templateInfo = this._currentTemplateInfo;
        var hasAuthorText = lang.getObject('layoutOptions.hasAuthorText', false, templateInfo);
        var hasCopyrightText = lang.getObject('layoutOptions.hasCopyrightText',
          false, templateInfo);
        var hasTitleText = lang.getObject('layoutOptions.hasTitleText', false, templateInfo);

        var template = new PrintTemplate();
        template.format = form.format;
        template.layout = form.layout;
        template.preserveScale = (form.preserveScale === 'true' || form.preserveScale === 'force');
        if (form.preserveScale === 'force') {
          template.outScale = this.preserve.forcedScale > 0 ? this.preserve.forcedScale : this.map.getScale();
        }

        if(form.layout === 'A3 Portrait'){
          template.outScale =  12000;
        }
...
0 Kudos
Arne_Gelfert
Occasional Contributor III

Hey I'll take a look and compare... sorry keep getting my wires crossed with you here... didn't see your response until I'd posted mine. Thanks for always coming through!!

0 Kudos
Arne_Gelfert
Occasional Contributor III

This worked....

printDefInspector: function(printDef) {
     
      printDef.mapOptions.scale = this.scaleForPrinting;
      return printDef;
    },


onLayoutChange: function(newValue) {
      if (newValue == 'Layout 1')
      {this.scaleForPrinting = 10000;}
      else if (newValue == 'Layout 2')
      {this.scaleForPrinting = 2000;}
...