Show Layers defined in querystring

1604
6
Jump to solution
05-18-2018 05:21 AM
DavidMartin
Occasional Contributor II

If I want to open a Web App (built with WebAppBuilder) using a "launch in context" call from another app, then it seems I can use a given set of URL Parameters to achieve this: Use URL parameters—Portal for ArcGIS | ArcGIS Enterprise .

However, if I want to parameterise the layers to make visible, the above URL doesn't identify a means by which I can achieve this. (This is unlike parameterised calls to the Portal's Web Map Viewer application, which does include layer visibility among its parameters: URL parameters to modify maps—Portal for ArcGIS | ArcGIS Enterprise).

Given that I want to use a Web App built with WebAppBuilder, any ideas as to how, if I were to include a layer list in my url querystring, I could interpret this and only show the requested layers? Given that the normal means of extension is by means of a Widget, I'm imagining that I might be able to use a Widget that is configured to open at startup? I'm not sure how I would then access the querystring, however? Or someone might have a better approach to the problem?

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

David,

  Using a widget would be the route to go.

Getting the url parameters in a widgets code is fairly simple. Here is a function I use in some of my widgets:

//define
'dojo/io-query',
...
ioquery,
...

      getUrlParams: function () {
        var s = window.location.search,
          p;
        if (s === '') {
          return {};
        }
        p = ioquery.queryToObject(s.substr(1));
        return p;
      },

...

var myObject = this.getUrlParams();

Then the part of toggling a layer:

define([
...
'jimu/LayerStructure',
...
],
function(
...
LayerStructure,
...

//get the layer structure
this.layerStructure  = LayerStructure.getInstance();

// this loops through all the layers an turns then off
this.layerStructure.traversal(lang.hitch(this, function(layerNode) {
  layerNode.hide();
}));

// this sets a specific layer to false
this.layerStructure.getNodeById('Parcel Data_0').hide();

View solution in original post

6 Replies
RobertScheitlin__GISP
MVP Emeritus

David,

  Using a widget would be the route to go.

Getting the url parameters in a widgets code is fairly simple. Here is a function I use in some of my widgets:

//define
'dojo/io-query',
...
ioquery,
...

      getUrlParams: function () {
        var s = window.location.search,
          p;
        if (s === '') {
          return {};
        }
        p = ioquery.queryToObject(s.substr(1));
        return p;
      },

...

var myObject = this.getUrlParams();

Then the part of toggling a layer:

define([
...
'jimu/LayerStructure',
...
],
function(
...
LayerStructure,
...

//get the layer structure
this.layerStructure  = LayerStructure.getInstance();

// this loops through all the layers an turns then off
this.layerStructure.traversal(lang.hitch(this, function(layerNode) {
  layerNode.hide();
}));

// this sets a specific layer to false
this.layerStructure.getNodeById('Parcel Data_0').hide();
DavidMartin
Occasional Contributor II

Great! Thanks Robert.

Would the widget's startup method still be the place to put such code? (I see from this site that the method may be deprecated: Widget | API Reference | ArcGIS API for JavaScript 4.7 

And if my url parameters (that specify the layers to show) first require mapping to layer IDs (because the calling system has different names for them), would you have any thoughts as to whether it would be better to maintain such a mapping (3rd party layer name : Web Map Layer ID) in a config file or a feature service? In either case, does the ArcGIS API offer a quick way of handling such custom config data?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

David,

   OK I am a little confused now. You have a link to the JS API 4.7 above so are you wanting to develop a 3D widget in WAB or something?

0 Kudos
DavidMartin
Occasional Contributor II

That's probably my confusion, rather than yours! I'm just after a normal WAB widget that will enable me to show/hide layers on startup in a 2D Web App, as specified by custom URL querystring parameters. I may be looking at the wrong reference area?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

David,

   Correct if you are wanting a 2D widget in WAB then do not referrer to any JS API 4.x documentation. WAB 2D widget use the JS API 3.x. So yes the widgets startup method would be a good place to add your code. As far as linking the calling systems ids to the WAB apps ids you can maintain that in the widgets config.json.

DavidMartin
Occasional Contributor II

Thanks Robert. That clears it up nicely!

0 Kudos