Select to view content in your preferred language

Issues with Legend widget accessing secure layer

637
2
Jump to solution
01-03-2014 01:31 PM
MarcusBush
Emerging Contributor
Hello,

I am working on an app, using version 3.5 of the jsapi, that has a few layers including one service layer that is secure and requires a name and password to access.

I have no problem adding this layer to the map itself using code to add a token at the end of the service url, but the same method isn't working for adding it to the legend widget.

I have tried to change up the order of things,

  • Tried to call the widget in the "onLoad" event

  • Tried to call it in a button click event, to make sure the map had its other layers loaded first

Attempting to add the secure layer to the widget results in getting challenged for the name and password not once, but for every index in the service. before it tries to create the legend.

I've tried adding the legend without the token, and adding it to the LayerInfo array AFTER the tokened version has been added to the map, it doesn't seem to matter, I get no legend for it.

Does anyone have any advice for this?
0 Kudos
1 Solution

Accepted Solutions
BenFousek
Deactivated User
The legend widget doesn't like token appended urls. When you load a layer with a token, it is stored elsewhere in the layer object and can be accessed via layer._getToken(). This is what esri widgets use. If you look at the legend request you'll see a malformed url.

Reset the layer.url object after adding layer:
var url = 'http://server/arcgis/rest/services/beer/MapServer'; var token = 'my_token';  var layer = new ArcGISDynamicMapServiceLayer(url + '?token=" + token, { id: 'some_layer' });  map.addLayer(layer);  layer.url = url;

View solution in original post

0 Kudos
2 Replies
BenFousek
Deactivated User
The legend widget doesn't like token appended urls. When you load a layer with a token, it is stored elsewhere in the layer object and can be accessed via layer._getToken(). This is what esri widgets use. If you look at the legend request you'll see a malformed url.

Reset the layer.url object after adding layer:
var url = 'http://server/arcgis/rest/services/beer/MapServer'; var token = 'my_token';  var layer = new ArcGISDynamicMapServiceLayer(url + '?token=" + token, { id: 'some_layer' });  map.addLayer(layer);  layer.url = url;
0 Kudos
MarcusBush
Emerging Contributor
Ben,

This solution worked great for me, thanks!
0 Kudos