var config = { token: SOME_TOKEN, layers: [ { type: 'dynamic', url: 'http://MY_URL/ArcGIS/rest/services/Slope/MapServer', token: true, name: 'Slope', id: 'slope', visible: false, opacity: 0.5, imageFormat: 'png32', dpi: 96, legend: true, parcelLabelControl: false, subLayerControl: false, info: true, infoHtml: 'This layer displays slopes.' }, { type: 'feature', url: 'http://MY_URL/ArcGIS/rest/services/Fire_Hydrants/MapServer/0', token: true, name: 'Fire Hydrants', id: 'firehydrants', visible: false, opacity: 1, imageFormat: 'png32', dpi: 96, legend: true, itTitle: 'Fire Hydrant', itContentType: 'function', itContentText: '', itContentFunction: 'config.featureFunctions.hydrants.infoTemplate' } ] }
http://MY_URL/ArcGIS/rest/services/Slope/MapServer/legend?token=SOME_TOKEN&f=json&callback=dojo.io.script.jsonp_dojoIoScript23._jsonpCallback
http://MY_URL/ArcGIS/rest/services/Slope/MapServer/legend?token=SOME_TOKEN?token=SOME_TOKEN&f=json&callback=dojo.io.script.jsonp_dojoIoScript23._jsonpCallback
Solved! Go to Solution.
app.map.addLayer(layer); layer.url = l.url; if (l.legend == true) { app.mapParams.legendLayers.push({ layer: layer, title: l.name }) }
var url; if (l.token == true) { url = l.url + '?token=' + config.token } else { url = l.url } var layer = new esri.layers.ArcGISDynamicMapServiceLayer(url, { id: l.id, visible: l.visible, opacity: l.opacity }); layer.setImageFormat(l.imageFormat); layer.setDPI(l.dpi); if (l.legend == true) { app.mapParams.legendLayers.push({ layer: layer, title: l.name }) } app.map.addLayer(layer);
Here's the pertinent parts of function that adds a dynamic layer. Same concept for feature layers.var url; if (l.token == true) { url = l.url + '?token=' + config.token } else { url = l.url } var layer = new esri.layers.ArcGISDynamicMapServiceLayer(url, { id: l.id, visible: l.visible, opacity: l.opacity }); layer.setImageFormat(l.imageFormat); layer.setDPI(l.dpi); if (l.legend == true) { app.mapParams.legendLayers.push({ layer: layer, title: l.name }) } app.map.addLayer(layer);
As you can see I'm manually appending the token. When the page loads the first javascript file is php that returns "var token = THE_TOKEN;" based on the referrer or I include the token in my config object as above. It's a little archaic, but that's how I've done it since the beginning. I can see where this going; probably time to get acquainted with IdentityManagerBase.
if (l.token == true) {
function oc(a){ var o = {}; for(var i=0;i<a.length;i++) { o[a]=''; } return o; }
_legendRequestServer: function(_27) { var url = _27.url; var pos = url.indexOf("?"); if (pos > -1) { url = url.substring(0, pos) + "/legend" + url.substring(pos); } else { url += "/legend"; } var _28 = _4.hitch(this, "_processLegendResponse"); var _29 = {}; _29.f = "json"; if (_27._params.dynamicLayers) { _29.dynamicLayers = _27._params.dynamicLayers; if (_29.dynamicLayers === "[{}]") { _29.dynamicLayers = "[]"; } } var _2a = esri.request({ url: url, content: _29, callbackParamName: "callback", load: function(_2b, _2c) { _28(_27, _2b, _2c); }, error: esriConfig.defaults.io.errorHandler }); return _2a; }
_legendRequestServer: function(_24) { var url = _24.url; var pos = url.indexOf("?"); if (pos > -1) { url = url.substring(0, pos) + "/legend" + url.substring(pos); } else { url += "/legend"; } var _25 = _24._getToken(); if (_25) { url += "?token=" + _25; } var _26 = _2.hitch(this, "_processLegendResponse"); var _27 = {}; _27.f = "json"; if (_24._params.dynamicLayers) { _27.dynamicLayers = _24._params.dynamicLayers; if (_27.dynamicLayers === "[{}]") { _27.dynamicLayers = "[]"; } } var _28 = esri.request({ url: url, content: _27, callbackParamName: "callback", load: function(_29, _2a) { _26(_24, _29, _2a); }, error: esriConfig.defaults.io.errorHandler }); return _28; }
app.map.addLayer(layer); layer.url = l.url; if (l.legend == true) { app.mapParams.legendLayers.push({ layer: layer, title: l.name }) }
Ben, your solution works partially.
I remove the token from the layer url after I've added the layers to the map.
this.map.addLayers(layers);
array.forEach(layers, function (l) {
l.url = l.url.split('?token')[0];
}, this);
The layer gets added to the map and loads image request succesfully. The legend also works fine, but identifying on a layers fails. The identify request doesn't contain a token anymore after I removed the token from the layer.url. It seems that an identify request doesn't add the token as a legend request does.
Do you have a solution for this as well?
Regards,
Joep Ronde