Print predefined layers via widget

842
6
Jump to solution
02-14-2018 12:57 AM
SimonWebster
Occasional Contributor

HI all, 

I remember running across a widget that I cannot seem to re-find. Hoping someone might know of which I speak and be able to point me in the right direction. 

I have a scenario where users need to print off a series of ~10 maps depending on what stage their projects are at. The main map contains all the layers that are to appear in these maps, however some layers will be shown for some print results, other times other layers are shown. The widget of which I speak allowed the preset of certain "templates", where it was possible to specify which layers were visible, and which were not.

Ie, user sets the widget to template "3. Do a thing", and only those layers specified in that template were made visible.

From memory this was also a custom printing widget, so of course the result could then invoke an ArcGIS server hosted printing script to apply the page template, etc. 

Any pointers in the right direction are very much appreciated. 

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Simon,

   Use this:

this.layerInfosObj.getLayerInfoById('AdminBoundaryReduced_255_0').setTopLayerVisible(false);

View solution in original post

6 Replies
RobertScheitlin__GISP
MVP Emeritus

Simon,

   I have to say I have not run across that widget. But choosing a template is an OTB ability in the print widget. Now changing the visibility of layer based on the template would not be to hard to add to the OTB print widget for a developer. There are a couple of thread on programatically changing layer visibility in code. 

Make layer visible after LayerList widget has opened 

https://community.esri.com/thread/164027 

0 Kudos
SimonWebster
Occasional Contributor

Thanks Robert,

Essentially I'd be looking to use the template change as a trigger to make visible / hide various layers in the OTB print widget. Makes sense. I'm assuming that this: https://community.esri.com/thread/164027 will be a good lead. 

Thank you.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Simon,

  Yes that is correct. And yes the setTopLayerVisible part of that thread is what you would use in the Print Widgets Print.js file.

0 Kudos
SimonWebster
Occasional Contributor

Robert, 

If I may ask for a little more direction, for lack of progress otherwise:

I'm assuming at the moment that in Print.js the area I wish to focus on is 'onLayoutchange: function(newvalue) {'.

At the moment I'm stuck simply turning a layer on an off. I'm happy to hard code the layers to turn on and off in to the function for now.  
Using the following as an example, I've been unable to decipher the correct way to address the getLayerInfoByID function to turn on and off the layer.

For the purpose of the exercise my test layer is AdminBoundaryReduced_255_0 (this is a sub layer of a parent layer, or rather Layer ID 0 in the appropriate service). 

this.operLayerInfos.getLayerInfoById('AdminBoundaryReduced_255_0').setTopLayerVisible(false);

The function seems specific to addressing that layer from within the layers panel, as per the examples earlier. Would you happen to know how I should be addressing it from the print widget, or just generally?

My console error using the above looks like:

Print.js?wab_dv=2.7:367 Uncaught TypeError: Cannot read property 'getLayerInfoById' of undefined
at Object.onLayoutChange (Print.js?wab_dv=2.7:367)
at Object.<anonymous> (init.js:63)
at Object.c [as onChange] (init.js:119)
at Object.<anonymous> (init.js:390)
at init.js:63
at Object.<anonymous> (init.js:365)
at init.js:63

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Simon,

   Use this:

this.layerInfosObj.getLayerInfoById('AdminBoundaryReduced_255_0').setTopLayerVisible(false);
SimonWebster
Occasional Contributor

Robert, 

This worked first time. Seriously amazing. Thank you. 

0 Kudos