LayerList with token protected layer

6560
13
05-20-2016 07:59 AM
MarcoRosa
New Contributor

Hi to all,

im going to set up Layer List in this way:

var llWidget = new LayerList({
                    map: map,
                    showLegend: true,
                    showOpacitySlider: true,
                    layers: [{
                        layer: mylayer,
                        id: "mylayerID",
                        subLayers: true
                    }]
                }, "layerList");
                llWidget.startup();

Note that mylayer becomes from a request for a token protected lite this:

var mylayer= new ArcGISDynamicMapServiceLayer(url_mylayer + "?token=" + token, {})

Doesn't work .... error is invalid tokens when request to legends it's made. How can i set layer to layer list in thic case ?

Where's the mistake?

Thank's in advanced to all

GP

0 Kudos
13 Replies
RobertScheitlin__GISP
MVP Emeritus

GP,

  Normally the advice from the JS API team for working with secured services is to use a proxy.

Using the proxy | Guide | ArcGIS API for JavaScript

Releases · Esri/resource-proxy · GitHub

0 Kudos
MarcoRosa
New Contributor

Hi Robert, yes im using proxy

Da: Robert Scheitlin, GISP

Inviato: venerdì 20 maggio 2016 17:11

A: Porta Giorgio <gporta@consodata.it>

Oggetto: Re: - LayerList with token protected layer

GeoNet <https://community.esri.com/?et=watches.email.thread>

LayerList with token protected layer

reply from Robert Scheitlin, GISP<https://community.esri.com/people/rscheitlin?et=watches.email.thread> in ArcGIS API for JavaScript - View the full discussion<https://community.esri.com/message/609889?et=watches.email.thread#comment-609889>

0 Kudos
JoelBennett
MVP Regular Contributor

The Legend dijit is known to hiccup on layers having ?token= in their URL under some circumstances.  If you use your browser's developer tools to monitor the network traffic, particularly for the legend request, and notice that "?token=" appears twice in the URL, there is a known workaround. If you have a locally hosted version of the API, you can tweak the esri/dijit/legend.js file to get around this issue.  I discussed this in a separate thread at:

https://community.esri.com/thread/122680#comment-463137

Note that I wrote that up for version 3.12...if you have a different version of the API, the variable names could be different.

MarcoRosa
New Contributor

Thank you Joel, then there is no solution if i use online api ? Im using 3.16 version now

Da: Joel Bennett

Inviato: venerdì 20 maggio 2016 19:03

A: Porta Giorgio <gporta@consodata.it>

Oggetto: Re: - LayerList with token protected layer

GeoNet <https://community.esri.com/?et=watches.email.thread>

LayerList with token protected layer

reply from Joel Bennett<https://community.esri.com/people/bennetjo?et=watches.email.thread> in ArcGIS API for JavaScript - View the full discussion<https://community.esri.com/message/609904?et=watches.email.thread#comment-609904>

0 Kudos
JoelBennett
MVP Regular Contributor

The preferred solution would be to get the API and host it yourself if possible and then make those tweaks...see the bottom of:

Get the ArcGIS API for JavaScript | Guide | ArcGIS API for JavaScript

If that's not an option, a less elegant solution would be to add "esri/dijit/Legend" to your require list.  Then, right before your line:

var llWidget = new LayerList(

you could put

Legend.prototype._legendRequestServer = function(a) {

     //all the same code as the original _legendRequestServer function

     //except with the tweaks mentioned in the other thread

}

and also

Legend.prototype._buildRow_Tools = function(a, b, c, d, e) {

     //all the same code as the original _buildRow_Tools function

     //except with the tweaks mentioned in the other thread

}

You can get the original code for the legend class by downloading https://js.arcgis.com/3.16/esri/dijit/Legend.js

MarcoRosa
New Contributor

Thanks Robert,

i’ll try and i let you know.

Thanks at the moment

Giorgio

Da: Robert Scheitlin, GISP

Inviato: lunedì 23 maggio 2016 15:00

A: Porta Giorgio

Oggetto: Reply marked as helpful on LayerList with token protected layer

GeoNet <https://community.esri.com/?et=watches.email.outcome>

LayerList with token protected layer

Robert Scheitlin, GISP<https://community.esri.com/people/rscheitlin?et=watches.email.outcome> marked Joel Bennett<https://community.esri.com/people/bennetjo?et=watches.email.outcome>'s reply on LayerList with token protected layer<https://community.esri.com/thread/177397?et=watches.email.outcome> as helpful. View the full reply<https://community.esri.com/message/610200?et=watches.email.outcome#comment-610200>

0 Kudos
MarcoRosa
New Contributor

Hi Robert,

done that …. Added require "esri/dijit/Legend", and modified code following istructions. Protected are correctly added to map , no more errors were generated but legend doesnt work correctly.

I can view just first layer without detailed options (layer styles / opacity)

Da: Robert Scheitlin, GISP

Inviato: lunedì 23 maggio 2016 15:00

A: Porta Giorgio <gporta@consodata.it>

Oggetto: Reply marked as helpful on LayerList with token protected layer

GeoNet <https://community.esri.com/?et=watches.email.outcome>

LayerList with token protected layer

Robert Scheitlin, GISP<https://community.esri.com/people/rscheitlin?et=watches.email.outcome> marked Joel Bennett<https://community.esri.com/people/bennetjo?et=watches.email.outcome>'s reply on LayerList with token protected layer<https://community.esri.com/thread/177397?et=watches.email.outcome> as helpful. View the full reply<https://community.esri.com/message/610200?et=watches.email.outcome#comment-610200>

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

GP,

  It was Joel Bennett that recommended the workaround not me.

0 Kudos
MarcoRosa
New Contributor

sorry

Da: Robert Scheitlin, GISP

Inviato: lunedì 23 maggio 2016 17:39

A: Porta Giorgio <gporta@consodata.it>

Oggetto: Re: - LayerList with token protected layer

GeoNet <https://community.esri.com/?et=watches.email.thread>

LayerList with token protected layer

reply from Robert Scheitlin, GISP<https://community.esri.com/people/rscheitlin?et=watches.email.thread> in ArcGIS API for JavaScript - View the full discussion<https://community.esri.com/message/610266?et=watches.email.thread#comment-610266>

0 Kudos